diff --git a/controllers/drupalsite_controller.go b/controllers/drupalsite_controller.go index b97ffea5a4de5931d5a02fb744292f1353482f48..77f9dabd4fc669fa6b9edad01b0a2e0494fa652b 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 94118d4f536998189162923f0780381983a6498d..bcd107b4ca198c882622619779fbf5c94ad7d59d 100644 --- a/controllers/drupalsite_controller_utils.go +++ b/controllers/drupalsite_controller_utils.go @@ -175,46 +175,51 @@ func (r *DrupalSiteReconciler) cleanupDrupalSite(ctx context.Context, log logr.L // ensureSpecFinalizer ensures that the spec is valid, adding extra info if necessary, and that the finalizer is there, // then returns if it needs to be updated. func (r *DrupalSiteReconciler) ensureSpecFinalizer(ctx context.Context, drp *webservicesv1a1.DrupalSite, log logr.Logger) (update bool, err reconcileError) { + // We want the update variable to be true, only when we make changes to the CR & want it to be updated 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 == "" { + if 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 != "" { sourceSite := webservicesv1a1.DrupalSite{} 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 { drp.Spec.Configuration.DiskSize = sourceSite.Spec.Configuration.DiskSize + update = true } // The extraConfigurationRepo should be set in the clone site if defined in the source // TODO: Remove logic for ExtraConfigurationRepo once we deprecate the field if sourceSite.Spec.Configuration.ExtraConfigurationRepo != "" && drp.Spec.Configuration.ExtraConfigurationRepo == "" { drp.Spec.Configuration.ExtraConfigurationRepo = sourceSite.Spec.Configuration.ExtraConfigurationRepo + update = true } // The extraConfigurationRepository should be set in the clone site if defined in the source if sourceSite.Spec.Configuration.ExtraConfigurationRepository.Branch != "" && sourceSite.Spec.Configuration.ExtraConfigurationRepository.RepositoryUrl != "" && drp.Spec.Configuration.ExtraConfigurationRepository.Branch == "" && drp.Spec.Configuration.ExtraConfigurationRepository.RepositoryUrl != "" { drp.Spec.Configuration.ExtraConfigurationRepository.Branch = sourceSite.Spec.Configuration.ExtraConfigurationRepository.Branch drp.Spec.Configuration.ExtraConfigurationRepository.RepositoryUrl = sourceSite.Spec.Configuration.ExtraConfigurationRepository.RepositoryUrl + update = true } - update = true || update } + // Initialize 'spec.version.releaseSpec' if empty if len(drp.Spec.Version.ReleaseSpec) == 0 { // Fetch the SupportedDrupalVersions instance @@ -231,20 +236,20 @@ func (r *DrupalSiteReconciler) ensureSpecFinalizer(ctx context.Context, drp *web } // Error reading the object - fail the request. log.Error(err, fmt.Sprintf("Failed to get SupportedDrupalVersions '%s'", SupportedDrupalVersionName)) - return update, newApplicationError(err, ErrClientK8s) + return false, newApplicationError(err, ErrClientK8s) } // Iterate over available versions to find if the one requested has a ReleaseSpec for _, v := range supportedDrupalVersions.Status.AvailableVersions { if drp.Spec.Name == v.Name { drp.Spec.Version.ReleaseSpec = v.LatestReleaseSpec - update = true || update + update = true break } } // If no available ReleaseSpec, we log and don't update if drp.Spec.Version.ReleaseSpec == "" { log.V(3).Info(fmt.Sprintf("Failed to get a ReleaseSpec for version %s", drp.Spec.Version.Name)) - return update, nil + return false, nil } } return update, nil