From 6504fb443426091651c6097c1cfe47ad32f7f661 Mon Sep 17 00:00:00 2001
From: Rajula Vineet Reddy <rajula.vineet.reddy@cern.ch>
Date: Tue, 11 Oct 2022 14:27:12 +0200
Subject: [PATCH] Add backup storage location to velero schedule

---
 chart/drupalsite-operator/templates/manager-deploy.yaml | 1 +
 chart/drupalsite-operator/values.yaml                   | 1 +
 controllers/drupalsite_controller.go                    | 2 ++
 controllers/drupalsite_resources.go                     | 1 +
 controllers/suite_test.go                               | 1 +
 main.go                                                 | 1 +
 6 files changed, 7 insertions(+)

diff --git a/chart/drupalsite-operator/templates/manager-deploy.yaml b/chart/drupalsite-operator/templates/manager-deploy.yaml
index 3cf1db4c..b953eed5 100644
--- a/chart/drupalsite-operator/templates/manager-deploy.yaml
+++ b/chart/drupalsite-operator/templates/manager-deploy.yaml
@@ -33,6 +33,7 @@ spec:
         - --cluster-name={{.Values.drupalsiteOperator.clusterName}}
         - --easystart-backup-name={{.Values.drupalsiteOperator.easystartBackupName}}
         - --supported-drupal-version-name={{.Values.drupalsiteOperator.supportedDrupalVersionName}}
+        - --velero-backup-storage-location={{.Values.drupalsiteOperator.veleroBackupStorageLocation}}
         command:
         - /manager
         image: {{ .Values.image | quote }}
diff --git a/chart/drupalsite-operator/values.yaml b/chart/drupalsite-operator/values.yaml
index ad2414bb..d08e4c74 100644
--- a/chart/drupalsite-operator/values.yaml
+++ b/chart/drupalsite-operator/values.yaml
@@ -30,3 +30,4 @@ drupalsiteOperator:
   enableTopologySpread: false
   clusterName: {}
   easystartBackupName: ""
+  veleroBackupStorageLocation: "default"
diff --git a/controllers/drupalsite_controller.go b/controllers/drupalsite_controller.go
index aa3e87d6..fa0ac7ca 100644
--- a/controllers/drupalsite_controller.go
+++ b/controllers/drupalsite_controller.go
@@ -72,6 +72,8 @@ var (
 	EasystartBackupName string
 	// SupportedDrupalVersion Name
 	SupportedDrupalVersionName string
+	// VeleroBackupStorageLocation refers to the name of the Velero backupStorageLocation to be used
+	VeleroBackupStorageLocation string
 )
 
 // DrupalSiteReconciler reconciles a DrupalSite object
diff --git a/controllers/drupalsite_resources.go b/controllers/drupalsite_resources.go
index 1ea567ed..3fc03f51 100644
--- a/controllers/drupalsite_resources.go
+++ b/controllers/drupalsite_resources.go
@@ -1658,6 +1658,7 @@ func scheduledBackupsForDrupalSite(currentobject *velerov1.Schedule, d *webservi
 		TTL: metav1.Duration{
 			Duration: 14 * 24 * time.Hour,
 		},
+		StorageLocation: VeleroBackupStorageLocation,
 	}
 	// Set UseOwnerReferencesInBackup to False since we do not want the Backups to be deleted when Schedule object is deleted or modified
 	currentobject.Spec.UseOwnerReferencesInBackup = pointer.BoolPtr(false)
diff --git a/controllers/suite_test.go b/controllers/suite_test.go
index bda9695b..090f679f 100644
--- a/controllers/suite_test.go
+++ b/controllers/suite_test.go
@@ -84,6 +84,7 @@ var _ = BeforeSuite(func(done Done) {
 	ClusterName = "test"
 	EasystartBackupName = "easystart-backup"
 	SupportedDrupalVersionName = "supported-drupal-versions"
+	VeleroBackupStorageLocation = "default"
 
 	By("bootstrapping test environment")
 	testEnv = &envtest.Environment{
diff --git a/main.go b/main.go
index 692c3b0c..94892db8 100644
--- a/main.go
+++ b/main.go
@@ -87,6 +87,7 @@ func main() {
 	flag.StringVar(&controllers.EasystartBackupName, "easystart-backup-name", "", "The name of the easy-start backup")
 	// The variable name is set here: https://gitlab.cern.ch/drupal/paas/cern-drupal-distribution/-/blob/master/supporteddrupalversions/chart/templates/supported-drupal-versions.yaml
 	flag.StringVar(&controllers.SupportedDrupalVersionName, "supported-drupal-version-name", "supported-drupal-versions", "The name of the resource used cluster-wide for supported drupal versions")
+	flag.StringVar(&controllers.VeleroBackupStorageLocation, "velero-backup-storage-location", "default", "The name of the backupStorageLocation to be used for Velero Schedules created by the controller")
 	opts := zap.Options{
 		Development: false,
 	}
-- 
GitLab