Added 'image' tag to BackupConfiguration to allow users to specify what container image to use as a sidecar container

This commit is contained in:
jandre 2021-05-12 20:34:08 +02:00
parent efc6114586
commit ba5fc36712
7 changed files with 13 additions and 22 deletions

View File

@ -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"`

View File

@ -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{

View File

@ -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,

View File

@ -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,

View File

@ -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) {

View File

@ -168,6 +168,7 @@ var (
},
Spec: formolv1alpha1.BackupConfigurationSpec{
Repository: TestRepoName,
Image: "desmo999r/formolcli:latest",
Schedule: "1 * * * *",
Keep: formolv1alpha1.Keep{
Last: 2,

View File

@ -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 {