From 1b09212f6db5df00f1957b4d2bdb4f26d232e6a1 Mon Sep 17 00:00:00 2001 From: Jean-Marc Andre Date: Thu, 3 Jun 2021 17:17:34 +0200 Subject: [PATCH] tag what container to backup and to run the steps against --- api/v1alpha1/backupconfiguration_types.go | 2 ++ api/v1alpha1/common.go | 2 ++ controllers/backupconfiguration_controller.go | 10 +++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/api/v1alpha1/backupconfiguration_types.go b/api/v1alpha1/backupconfiguration_types.go index 7b156bf..af85281 100644 --- a/api/v1alpha1/backupconfiguration_types.go +++ b/api/v1alpha1/backupconfiguration_types.go @@ -44,6 +44,8 @@ type Target struct { Kind string `json:"kind"` Name string `json:"name"` // +optional + ContainerName string `json:"containerName"` + // +optional ApiVersion string `json:"apiVersion,omitempty"` // +optional VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"` diff --git a/api/v1alpha1/common.go b/api/v1alpha1/common.go index dc49db0..d3b88d4 100644 --- a/api/v1alpha1/common.go +++ b/api/v1alpha1/common.go @@ -19,6 +19,8 @@ const ( RESTORE_ANNOTATION = "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 + TARGETCONTAINER_TAG string = "FORMOL_TARGET" // Used by both the backupsession and restoresession controllers to identified the target deployment TARGET_NAME string = "TARGET_NAME" // Used by restoresession controller diff --git a/controllers/backupconfiguration_controller.go b/controllers/backupconfiguration_controller.go index a56bb96..8aaedf4 100644 --- a/controllers/backupconfiguration_controller.go +++ b/controllers/backupconfiguration_controller.go @@ -214,11 +214,19 @@ func (r *BackupConfigurationReconciler) Reconcile(ctx context.Context, req recon return err } log.V(1).Info("got deployment", "Deployment", deployment) - for _, container := range deployment.Spec.Template.Spec.Containers { + for i, container := range deployment.Spec.Template.Spec.Containers { if container.Name == formolv1alpha1.SIDECARCONTAINER_NAME { log.V(0).Info("There is already a backup sidecar container. Skipping", "container", container) return nil } + if target.ContainerName != "" && target.ContainerName == container.Name { + // Put a tag so we can find what container we are supposed to backup + // and what process we are supposed to chroot to run the init steps + deployment.Spec.Template.Spec.Containers[i].Env = append(container.Env, corev1.EnvVar{ + Name: formolv1alpha1.TARGETCONTAINER_TAG, + Value: "True", + }) + } } sidecar := corev1.Container{ Name: formolv1alpha1.SIDECARCONTAINER_NAME,