From b2d80d66ae6bca9e1bc5d04737998806296f8a93 Mon Sep 17 00:00:00 2001 From: Jean-Marc ANDRE Date: Thu, 23 Mar 2023 22:19:13 +0100 Subject: [PATCH] Restore OnlineKind --- api/v1alpha1/backupsession_types.go | 9 ++++--- api/v1alpha1/common.go | 1 + api/v1alpha1/restoresession_types.go | 2 +- .../backupconfiguration_controller_helpers.go | 5 ++++ controllers/restoresession_controller.go | 2 +- test/03-restoresession.yaml | 27 ++++++++++--------- 6 files changed, 28 insertions(+), 18 deletions(-) diff --git a/api/v1alpha1/backupsession_types.go b/api/v1alpha1/backupsession_types.go index 03f69cd..03d7a1d 100644 --- a/api/v1alpha1/backupsession_types.go +++ b/api/v1alpha1/backupsession_types.go @@ -40,10 +40,11 @@ type TargetStatus struct { TargetName string `json:"targetName"` TargetKind `json:"targetKind"` SessionState `json:"state"` - SnapshotId string `json:"snapshotId"` - StartTime *metav1.Time `json:"startTime"` - Duration *metav1.Duration `json:"duration,omitempty"` - Try int `json:"try"` + // +optional + SnapshotId string `json:"snapshotId,omitempty"` + StartTime *metav1.Time `json:"startTime"` + Duration *metav1.Duration `json:"duration,omitempty"` + Try int `json:"try"` } // BackupSessionSpec defines the desired state of BackupSession diff --git a/api/v1alpha1/common.go b/api/v1alpha1/common.go index 3491639..ea61a01 100644 --- a/api/v1alpha1/common.go +++ b/api/v1alpha1/common.go @@ -1,6 +1,7 @@ package v1alpha1 const ( + RESTORECONTAINER_NAME string = "formol-restore" // the name of the sidecar container SIDECARCONTAINER_NAME string = "formol" // the name of the container we backup when there are more than 1 container in the pod diff --git a/api/v1alpha1/restoresession_types.go b/api/v1alpha1/restoresession_types.go index 289dacb..8011ddb 100644 --- a/api/v1alpha1/restoresession_types.go +++ b/api/v1alpha1/restoresession_types.go @@ -27,7 +27,7 @@ type BackupSessionRef struct { // RestoreSessionSpec defines the desired state of RestoreSession type RestoreSessionSpec struct { - BackupSessionRef `json:"backupSessionRef"` + BackupSessionRef `json:"backupSession"` } // RestoreSessionStatus defines the observed state of RestoreSession diff --git a/controllers/backupconfiguration_controller_helpers.go b/controllers/backupconfiguration_controller_helpers.go index 97dc74a..eeba15e 100644 --- a/controllers/backupconfiguration_controller_helpers.go +++ b/controllers/backupconfiguration_controller_helpers.go @@ -350,6 +350,11 @@ func (r *BackupConfigurationReconciler) createRBACSidecar(sa corev1.ServiceAccou Name: FORMOL_SIDECAR_ROLE, }, Rules: []rbacv1.PolicyRule{ + rbacv1.PolicyRule{ + Verbs: []string{"get", "list", "update"}, + APIGroups: []string{"apps"}, + Resources: []string{"deployments"}, + }, rbacv1.PolicyRule{ Verbs: []string{"get", "list", "watch"}, APIGroups: []string{"formol.desmojim.fr"}, diff --git a/controllers/restoresession_controller.go b/controllers/restoresession_controller.go index ea2759a..edbcf06 100644 --- a/controllers/restoresession_controller.go +++ b/controllers/restoresession_controller.go @@ -58,7 +58,7 @@ func (r *RestoreSessionReconciler) Reconcile(ctx context.Context, req ctrl.Reque if err := r.Get(r.Context, client.ObjectKey{ Namespace: backupSession.Spec.Ref.Namespace, Name: backupSession.Spec.Ref.Name, - }, &restoreSession); err != nil { + }, &backupConf); err != nil { r.Log.Error(err, "unable to get BackupConfiguration") return ctrl.Result{}, err } diff --git a/test/03-restoresession.yaml b/test/03-restoresession.yaml index 9cb2348..c5a9e78 100644 --- a/test/03-restoresession.yaml +++ b/test/03-restoresession.yaml @@ -10,21 +10,24 @@ spec: name: backup-demo namespace: demo status: - keep: monthly - startTime: "2021-05-01T22:15:28Z" + keep: "" + startTime: "2023-03-20T20:47:08Z" state: Success target: - - duration: 17.952754232s - kind: Sidecar - name: nginx-deployment - snapshotId: f411315c - startTime: "2021-05-01T22:15:34Z" + - backupType: Online + duration: 3.189468146s + snapshotId: 4730eaad + startTime: "2023-03-20T20:47:08Z" state: Success + targetKind: Deployment + targetName: apache-deployment try: 1 - - duration: 25.46747271s - kind: Job - name: backup-pg - snapshotId: ca673e5a - startTime: "2021-05-01T22:15:55Z" + - backupType: Job + duration: 7.509060051s + snapshotId: 4ddc5da1 + startTime: "2023-03-20T20:47:08Z" state: Success + targetKind: StatefulSet + targetName: postgres-demo try: 1 +