diff --git a/api/v1alpha1/backupconfiguration_types.go b/api/v1alpha1/backupconfiguration_types.go index 2d3e6bb..7370544 100644 --- a/api/v1alpha1/backupconfiguration_types.go +++ b/api/v1alpha1/backupconfiguration_types.go @@ -69,6 +69,7 @@ type Keep struct { // BackupConfigurationSpec defines the desired state of BackupConfiguration type BackupConfigurationSpec struct { Repository string `json:"repository"` + Image string `json:"image"` // +optional Suspend *bool `json:"suspend,omitempty"` diff --git a/controllers/backupconfiguration_controller.go b/controllers/backupconfiguration_controller.go index 6140854..35fb39e 100644 --- a/controllers/backupconfiguration_controller.go +++ b/controllers/backupconfiguration_controller.go @@ -58,6 +58,7 @@ var _ reconcile.Reconciler = &BackupConfigurationReconciler{} // +kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=clusterrolebindings,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=batch,resources=cronjobs,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=batch,resources=cronjobs/status,verbs=get +// +kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,verbs=get;list;create;update func (r *BackupConfigurationReconciler) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) { var changed bool @@ -151,7 +152,7 @@ func (r *BackupConfigurationReconciler) Reconcile(ctx context.Context, req recon Containers: []corev1.Container{ corev1.Container{ Name: "job-createbackupsession-" + backupConf.Name, - Image: "desmo999r/formolcli:latest", + Image: backupConf.Spec.Image, Args: []string{ "backupsession", "create", @@ -220,7 +221,7 @@ func (r *BackupConfigurationReconciler) Reconcile(ctx context.Context, req recon sidecar := corev1.Container{ Name: formolv1alpha1.SIDECARCONTAINER_NAME, // TODO: Put the image in the BackupConfiguration YAML file - Image: "desmo999r/formolcli:latest", + Image: backupConf.Spec.Image, Args: []string{"backupsession", "server"}, //Image: "busybox", //Command: []string{ diff --git a/controllers/backupconfiguration_controller_test.go b/controllers/backupconfiguration_controller_test.go index bc6da33..319d6d6 100644 --- a/controllers/backupconfiguration_controller_test.go +++ b/controllers/backupconfiguration_controller_test.go @@ -41,6 +41,7 @@ var _ = Describe("Testing BackupConf controller", func() { Spec: formolv1alpha1.BackupConfigurationSpec{ Repository: TestRepoName, Schedule: "1 * * * *", + Image: "desmo999r/formolcli:latest", Targets: []formolv1alpha1.Target{ formolv1alpha1.Target{ Kind: formolv1alpha1.SidecarKind, diff --git a/controllers/backupsession_controller.go b/controllers/backupsession_controller.go index 5fb974f..4700c9d 100644 --- a/controllers/backupsession_controller.go +++ b/controllers/backupsession_controller.go @@ -57,6 +57,7 @@ var _ reconcile.Reconciler = &BackupSessionReconciler{} // +kubebuilder:rbac:groups=formol.desmojim.fr,resources=backupsessions/status,verbs=get;update;patch;create;delete // +kubebuilder:rbac:groups=formol.desmojim.fr,resources=functions,verbs=get;list;watch // +kubebuilder:rbac:groups=batch,resources=jobs,verbs=get;list;create;update;patch;delete;watch +// +kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,verbs=get;list;create;update func (r *BackupSessionReconciler) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) { log := r.Log.WithValues("backupsession", req.NamespacedName) @@ -105,7 +106,7 @@ func (r *BackupSessionReconciler) Reconcile(ctx context.Context, req reconcile.R if target.SessionState == formolv1alpha1.Success { deleteSnapshots = append(deleteSnapshots, corev1.Container{ Name: target.Name, - Image: "desmo999r/formolcli:latest", + Image: backupConf.Spec.Image, Args: []string{"snapshot", "delete", "--snapshot-id", target.SnapshotId}, Env: env, }) @@ -164,7 +165,7 @@ func (r *BackupSessionReconciler) Reconcile(ctx context.Context, req reconcile.R } restic := corev1.Container{ Name: "restic", - Image: "desmo999r/formolcli:latest", + Image: backupConf.Spec.Image, Args: []string{"volume", "backup", "--tag", backupSession.Name, "--path", "/output"}, VolumeMounts: []corev1.VolumeMount{output}, Env: backupSessionEnv, diff --git a/controllers/restoresession_controller.go b/controllers/restoresession_controller.go index 610943b..0f119c7 100644 --- a/controllers/restoresession_controller.go +++ b/controllers/restoresession_controller.go @@ -55,6 +55,7 @@ var _ reconcile.Reconciler = &RestoreSessionReconciler{} // +kubebuilder:rbac:groups=formol.desmojim.fr,resources=restoresessions,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=formol.desmojim.fr,resources=restoresessions/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,verbs=get;list;create;update func (r *RestoreSessionReconciler) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) { log := log.FromContext(ctx).WithValues("restoresession", req.NamespacedName) @@ -127,19 +128,16 @@ func (r *RestoreSessionReconciler) Reconcile(ctx context.Context, req reconcile. Name: "output", MountPath: "/output", } - //for _, targetStatus := range backupSession.Status.Targets { - //if targetStatus.Name == target.Name { - //snapshotId := targetStatus.SnapshotId restic := corev1.Container{ Name: "restic", - Image: "desmo999r/formolcli:latest", + Image: backupConf.Spec.Image, Args: []string{"volume", "restore", "--snapshot-id", snapshotId}, VolumeMounts: []corev1.VolumeMount{output}, Env: restoreSessionEnv, } finalizer := corev1.Container{ Name: "finalizer", - Image: "desmo999r/formolcli:latest", + Image: backupConf.Spec.Image, Args: []string{"target", "finalize"}, VolumeMounts: []corev1.VolumeMount{output}, Env: restoreSessionEnv, @@ -214,8 +212,6 @@ func (r *RestoreSessionReconciler) Reconcile(ctx context.Context, req reconcile. if err := r.Create(ctx, job); err != nil { log.Error(err, "unable to create job", "job", job) return err - //} - //} } return nil } @@ -263,9 +259,6 @@ func (r *RestoreSessionReconciler) Reconcile(ctx context.Context, req reconcile. return nil } } - //for _, targetStatus := range backupSession.Status.Targets { - //if targetStatus.Name == target.Name && targetStatus.Kind == target.Kind { - //snapshotId := targetStatus.SnapshotId restoreSessionEnv := []corev1.EnvVar{ corev1.EnvVar{ Name: formolv1alpha1.TARGET_NAME, @@ -282,7 +275,7 @@ func (r *RestoreSessionReconciler) Reconcile(ctx context.Context, req reconcile. } initContainer := corev1.Container{ Name: RESTORESESSION, - Image: formolutils.FORMOLCLI, + Image: backupConf.Spec.Image, Args: []string{"volume", "restore", "--snapshot-id", snapshotId}, VolumeMounts: target.VolumeMounts, Env: restoreSessionEnv, @@ -305,9 +298,6 @@ func (r *RestoreSessionReconciler) Reconcile(ctx context.Context, req reconcile. } return nil - //} - //} - //return nil } startNextTask := func() (*formolv1alpha1.TargetStatus, error) { diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 0acdce0..0fdc255 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -168,6 +168,7 @@ var ( }, Spec: formolv1alpha1.BackupConfigurationSpec{ Repository: TestRepoName, + Image: "desmo999r/formolcli:latest", Schedule: "1 * * * *", Keep: formolv1alpha1.Keep{ Last: 2, diff --git a/pkg/utils/root.go b/pkg/utils/root.go index 24889b3..565b692 100644 --- a/pkg/utils/root.go +++ b/pkg/utils/root.go @@ -7,10 +7,6 @@ import ( "strings" ) -const ( - FORMOLCLI string = "desmo999r/formolcli:latest" -) - func ContainsString(slice []string, s string) bool { for _, item := range slice { if item == s {