From 240ac9566f45b16b4dfe5fc1e44d1e1d4793f078 Mon Sep 17 00:00:00 2001
From: Rajula Vineet Reddy <rajula.vineet.reddy@cern.ch>
Date: Fri, 21 Oct 2022 11:28:47 +0200
Subject: [PATCH] Fix bug causing new clone creations

---
 controllers/drupalsite_controller.go       |  2 +-
 controllers/drupalsite_controller_utils.go | 13 ++++++-------
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/controllers/drupalsite_controller.go b/controllers/drupalsite_controller.go
index b97ffea5..77f9dabd 100644
--- a/controllers/drupalsite_controller.go
+++ b/controllers/drupalsite_controller.go
@@ -259,7 +259,7 @@ func (r *DrupalSiteReconciler) Reconcile(ctx context.Context, req ctrl.Request)
 	// Set Current version
 	if drupalSite.Status.ReleaseID.Current != releaseID(drupalSite) {
 		drupalSite.Status.ReleaseID.Current = releaseID(drupalSite)
-		update = true || update
+		update = true
 	}
 
 	// Check if the drupal site is ready to serve requests
diff --git a/controllers/drupalsite_controller_utils.go b/controllers/drupalsite_controller_utils.go
index 94118d4f..87b6185e 100644
--- a/controllers/drupalsite_controller_utils.go
+++ b/controllers/drupalsite_controller_utils.go
@@ -178,16 +178,16 @@ func (r *DrupalSiteReconciler) ensureSpecFinalizer(ctx context.Context, drp *web
 	if !controllerutil.ContainsFinalizer(drp, finalizerStr) {
 		log.V(3).Info("Adding finalizer")
 		controllerutil.AddFinalizer(drp, finalizerStr)
-		update = true || update
+		update = true
 	}
 	if drp.Spec.Configuration.WebDAVPassword == "" {
 		drp.Spec.Configuration.WebDAVPassword = generateRandomPassword()
-		update = true || update
+		update = true
 	}
 	// Set default value for DiskSize to 2000Mi
 	if drp.Spec.Configuration.CloneFrom == "" && drp.Spec.Configuration.DiskSize == "" {
 		drp.Spec.Configuration.DiskSize = "2000Mi"
-		update = true || update
+		update = true
 	}
 	// Validate that CloneFrom is an existing DrupalSite
 	if drp.Spec.Configuration.CloneFrom != "" {
@@ -195,9 +195,9 @@ func (r *DrupalSiteReconciler) ensureSpecFinalizer(ctx context.Context, drp *web
 		err := r.Get(ctx, types.NamespacedName{Name: string(drp.Spec.Configuration.CloneFrom), Namespace: drp.Namespace}, &sourceSite)
 		switch {
 		case k8sapierrors.IsNotFound(err):
-			return update, newApplicationError(fmt.Errorf("CloneFrom DrupalSite doesn't exist"), ErrInvalidSpec)
+			return false, newApplicationError(fmt.Errorf("CloneFrom DrupalSite doesn't exist"), ErrInvalidSpec)
 		case err != nil:
-			return update, newApplicationError(err, ErrClientK8s)
+			return false, newApplicationError(err, ErrClientK8s)
 		}
 		// The destination disk size must be at least as large as the source
 		if drp.Spec.Configuration.DiskSize < sourceSite.Spec.Configuration.DiskSize {
@@ -213,7 +213,6 @@ func (r *DrupalSiteReconciler) ensureSpecFinalizer(ctx context.Context, drp *web
 			drp.Spec.Configuration.ExtraConfigurationRepository.Branch = sourceSite.Spec.Configuration.ExtraConfigurationRepository.Branch
 			drp.Spec.Configuration.ExtraConfigurationRepository.RepositoryUrl = sourceSite.Spec.Configuration.ExtraConfigurationRepository.RepositoryUrl
 		}
-		update = true || update
 	}
 	// Initialize 'spec.version.releaseSpec' if empty
 	if len(drp.Spec.Version.ReleaseSpec) == 0 {
@@ -237,7 +236,7 @@ func (r *DrupalSiteReconciler) ensureSpecFinalizer(ctx context.Context, drp *web
 		for _, v := range supportedDrupalVersions.Status.AvailableVersions {
 			if drp.Spec.Name == v.Name {
 				drp.Spec.Version.ReleaseSpec = v.LatestReleaseSpec
-				update = true || update
+				update = true
 				break
 			}
 		}
-- 
GitLab