#4 Make backup before pod deletion
This commit is contained in:
parent
6bc79dfb33
commit
98110fac91
|
|
@ -41,7 +41,7 @@ type Container struct {
|
|||
// JenkinsMaster defines the Jenkins master pod attributes and plugins,
|
||||
// every single change requires Jenkins master pod restart
|
||||
type JenkinsMaster struct {
|
||||
Container //TODO move to containers
|
||||
Container
|
||||
|
||||
// pod properties
|
||||
Annotations map[string]string `json:"masterAnnotations,omitempty"`
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ type JenkinsStatus struct {
|
|||
RestoredBackup uint64 `json:"restoredBackup,omitempty"`
|
||||
LastBackup uint64 `json:"lastBackup,omitempty"`
|
||||
PendingBackup uint64 `json:"pendingBackup,omitempty"`
|
||||
BackupDoneBeforePodDeletion bool `json:"backupDoneBeforePodDeletion,omitempty"`
|
||||
}
|
||||
|
||||
// BuildStatus defines type of Jenkins build job status
|
||||
|
|
@ -178,9 +179,10 @@ type Handler struct {
|
|||
|
||||
// Backup defines configuration of Jenkins backup
|
||||
type Backup struct {
|
||||
ContainerName string `json:"containerName"`
|
||||
Action Handler `json:"action"`
|
||||
Interval uint64 `json:"interval"`
|
||||
ContainerName string `json:"containerName"`
|
||||
Action Handler `json:"action"`
|
||||
Interval uint64 `json:"interval"`
|
||||
MakeBackupBeforePodDeletion bool `json:"makeBackupBeforePodDeletion"`
|
||||
}
|
||||
|
||||
// Restore defines configuration of Jenkins backup restore
|
||||
|
|
|
|||
|
|
@ -404,7 +404,19 @@ func (r *ReconcileJenkinsBaseConfiguration) ensureJenkinsMasterPod(meta metav1.O
|
|||
if currentJenkinsMasterPod != nil && isPodTerminating(*currentJenkinsMasterPod) {
|
||||
backupAndRestore := backuprestore.New(r.k8sClient, *r.clientSet, r.logger, r.jenkins, *r.config)
|
||||
backupAndRestore.StopBackupTrigger()
|
||||
//TODO backup before pod deletion?
|
||||
if r.jenkins.Spec.Backup.MakeBackupBeforePodDeletion {
|
||||
if r.jenkins.Status.LastBackup == r.jenkins.Status.PendingBackup && !r.jenkins.Status.BackupDoneBeforePodDeletion {
|
||||
r.jenkins.Status.PendingBackup = r.jenkins.Status.PendingBackup + 1
|
||||
r.jenkins.Status.BackupDoneBeforePodDeletion = true
|
||||
err = r.k8sClient.Update(context.TODO(), r.jenkins)
|
||||
if err != nil {
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
}
|
||||
if err = backupAndRestore.Backup(); err != nil {
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
}
|
||||
return reconcile.Result{Requeue: true}, nil
|
||||
}
|
||||
if currentJenkinsMasterPod != nil && r.isRecreatePodNeeded(*currentJenkinsMasterPod) {
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ func createJenkinsWithBackupAndRestoreConfigured(t *testing.T, name, namespace s
|
|||
},
|
||||
{
|
||||
Name: containerName,
|
||||
Image: "virtuslab/jenkins-operator-backup-pvc:v0.0.1",
|
||||
Image: "virtuslab/jenkins-operator-backup-pvc:v0.0.2",
|
||||
ImagePullPolicy: corev1.PullIfNotPresent,
|
||||
Env: []corev1.EnvVar{
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue