From 68265228c6b14fb4a4d1c69364266e398a89078a Mon Sep 17 00:00:00 2001 From: Dimitra Chatzichrysou <dimitra.chatzichrysou@cern.ch> Date: Wed, 11 May 2022 17:06:26 +0200 Subject: [PATCH 1/2] Remove DrupalProjectConfig CRD --- PROJECT | 8 -- api/v1alpha1/drupalprojectconfig_types.go | 57 ------------ api/v1alpha1/drupalsite_types.go | 6 +- api/v1alpha1/zz_generated.deepcopy.go | 89 ------------------- ...services.cern.ch_drupalprojectconfigs.yaml | 58 ------------ ...rupal.webservices.cern.ch_drupalsites.yaml | 11 +-- config/crd/kustomization.yaml | 3 - .../cainjection_in_drupalprojectconfigs.yaml | 7 -- .../webhook_in_drupalprojectconfigs.yaml | 16 ---- .../rbac/drupalprojectconfig_editor_role.yaml | 24 ----- .../rbac/drupalprojectconfig_viewer_role.yaml | 20 ----- config/rbac/role.yaml | 18 ---- ...services_v1alpha1_drupalprojectconfig.yaml | 6 -- config/samples/kustomization.yaml | 1 - 14 files changed, 4 insertions(+), 320 deletions(-) delete mode 100644 api/v1alpha1/drupalprojectconfig_types.go delete mode 100644 config/crd/bases/drupal.webservices.cern.ch_drupalprojectconfigs.yaml delete mode 100644 config/crd/patches/cainjection_in_drupalprojectconfigs.yaml delete mode 100644 config/crd/patches/webhook_in_drupalprojectconfigs.yaml delete mode 100644 config/rbac/drupalprojectconfig_editor_role.yaml delete mode 100644 config/rbac/drupalprojectconfig_viewer_role.yaml delete mode 100644 config/samples/drupal.webservices_v1alpha1_drupalprojectconfig.yaml diff --git a/PROJECT b/PROJECT index 3b0a2d38..5d4f467c 100644 --- a/PROJECT +++ b/PROJECT @@ -33,12 +33,4 @@ resources: kind: SupportedDrupalVersions path: gitlab.cern.ch/drupal/paas/drupalsite-operator/api/v1alpha1 version: v1alpha1 -- api: - crdVersion: v1 - namespaced: true - domain: cern.ch - group: drupal.webservices - kind: DrupalProjectConfig - path: gitlab.cern.ch/drupal/paas/drupalsite-operator/api/v1alpha1 - version: v1alpha1 version: "3" diff --git a/api/v1alpha1/drupalprojectconfig_types.go b/api/v1alpha1/drupalprojectconfig_types.go deleted file mode 100644 index db4cc702..00000000 --- a/api/v1alpha1/drupalprojectconfig_types.go +++ /dev/null @@ -1,57 +0,0 @@ -/* -Copyright 2021 CERN. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// DrupalProjectConfigSpec defines the desired state of DrupalProjectConfig -type DrupalProjectConfigSpec struct { - // PrimarySiteName defines the primary DrupalSite instance of a project - // +optional - PrimarySiteName string `json:"primarySiteName,omitempty"` -} - -// DrupalProjectConfigStatus defines the observed state of DrupalProjectConfig -type DrupalProjectConfigStatus struct { -} - -//+kubebuilder:object:root=true -//+kubebuilder:subresource:status - -// DrupalProjectConfig is the Schema for the drupalprojectconfigs API -type DrupalProjectConfig struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec DrupalProjectConfigSpec `json:"spec,omitempty"` - Status DrupalProjectConfigStatus `json:"status,omitempty"` -} - -//+kubebuilder:object:root=true - -// DrupalProjectConfigList contains a list of DrupalProjectConfig -type DrupalProjectConfigList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []DrupalProjectConfig `json:"items"` -} - -func init() { - SchemeBuilder.Register(&DrupalProjectConfig{}, &DrupalProjectConfigList{}) -} diff --git a/api/v1alpha1/drupalsite_types.go b/api/v1alpha1/drupalsite_types.go index e0f19205..e6fcdc55 100644 --- a/api/v1alpha1/drupalsite_types.go +++ b/api/v1alpha1/drupalsite_types.go @@ -108,7 +108,7 @@ type Configuration struct { // +optional WebDAVPassword string `json:"webDAVPassword,omitempty"` - // ScheduledBackups [deprecated] when "true" will enable Scheduled Velero backups for the site and when "false" will disable scheduled backups + // ScheduledBackups when "enabled" will enable Scheduled Velero backups for the site and when "disabled" will disable scheduled backups // +kubebuilder:validation:Enum:=enabled;disabled // +kubebuilder:default=enabled // +optional @@ -171,10 +171,6 @@ type DrupalSiteStatus struct { // +optional GitlabWebhookURL string `json:"gitlabWebhookURL,omitempty"` - // IsPrimary states if the Drupalsite is the main instance of the project - // +kubebuilder:default=false - IsPrimary bool `json:"isPrimary,omitempty"` - // DBUpdatesLastCheckTimestamp reports the time when the site was checked for db updates DBUpdatesLastCheckTimestamp string `json:"dBUpdatesLastCheckTimestamp,omitempty"` } diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 751f4e79..ecae051d 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -64,95 +64,6 @@ func (in *Configuration) DeepCopy() *Configuration { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DrupalProjectConfig) DeepCopyInto(out *DrupalProjectConfig) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DrupalProjectConfig. -func (in *DrupalProjectConfig) DeepCopy() *DrupalProjectConfig { - if in == nil { - return nil - } - out := new(DrupalProjectConfig) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *DrupalProjectConfig) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DrupalProjectConfigList) DeepCopyInto(out *DrupalProjectConfigList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]DrupalProjectConfig, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DrupalProjectConfigList. -func (in *DrupalProjectConfigList) DeepCopy() *DrupalProjectConfigList { - if in == nil { - return nil - } - out := new(DrupalProjectConfigList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *DrupalProjectConfigList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DrupalProjectConfigSpec) DeepCopyInto(out *DrupalProjectConfigSpec) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DrupalProjectConfigSpec. -func (in *DrupalProjectConfigSpec) DeepCopy() *DrupalProjectConfigSpec { - if in == nil { - return nil - } - out := new(DrupalProjectConfigSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DrupalProjectConfigStatus) DeepCopyInto(out *DrupalProjectConfigStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DrupalProjectConfigStatus. -func (in *DrupalProjectConfigStatus) DeepCopy() *DrupalProjectConfigStatus { - if in == nil { - return nil - } - out := new(DrupalProjectConfigStatus) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DrupalSite) DeepCopyInto(out *DrupalSite) { *out = *in diff --git a/config/crd/bases/drupal.webservices.cern.ch_drupalprojectconfigs.yaml b/config/crd/bases/drupal.webservices.cern.ch_drupalprojectconfigs.yaml deleted file mode 100644 index 069919d8..00000000 --- a/config/crd/bases/drupal.webservices.cern.ch_drupalprojectconfigs.yaml +++ /dev/null @@ -1,58 +0,0 @@ - ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.4.1 - creationTimestamp: null - name: drupalprojectconfigs.drupal.webservices.cern.ch -spec: - group: drupal.webservices.cern.ch - names: - kind: DrupalProjectConfig - listKind: DrupalProjectConfigList - plural: drupalprojectconfigs - singular: drupalprojectconfig - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - description: DrupalProjectConfig is the Schema for the drupalprojectconfigs - API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: DrupalProjectConfigSpec defines the desired state of DrupalProjectConfig - properties: - primarySiteName: - description: PrimarySiteName defines the primary DrupalSite instance - of a project - type: string - type: object - status: - description: DrupalProjectConfigStatus defines the observed state of DrupalProjectConfig - type: object - type: object - served: true - storage: true - subresources: - status: {} -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/config/crd/bases/drupal.webservices.cern.ch_drupalsites.yaml b/config/crd/bases/drupal.webservices.cern.ch_drupalsites.yaml index ef30065e..6c5343ae 100644 --- a/config/crd/bases/drupal.webservices.cern.ch_drupalsites.yaml +++ b/config/crd/bases/drupal.webservices.cern.ch_drupalsites.yaml @@ -103,9 +103,9 @@ spec: type: string scheduledBackups: default: enabled - description: ScheduledBackups [deprecated] when "true" will enable - Scheduled Velero backups for the site and when "false" will - disable scheduled backups + description: ScheduledBackups when "enabled" will enable Scheduled + Velero backups for the site and when "disabled" will disable + scheduled backups enum: - enabled - disabled @@ -233,11 +233,6 @@ spec: of the site's image after changes on its source Gitlab "extraConfigurationRepo". It should be copied to Gitlab. type: string - isPrimary: - default: false - description: IsPrimary states if the Drupalsite is the main instance - of the project - type: boolean releaseID: description: ReleaseID reports the actual release of CERN Drupal Distribution that is being used in the deployment. diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index d6282601..75a2f159 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -5,7 +5,6 @@ resources: - bases/drupal.webservices.cern.ch_drupalsites.yaml - bases/drupal.webservices.cern.ch_drupalsiteconfigoverrides.yaml - bases/drupal.webservices.cern.ch_supporteddrupalversions.yaml -- bases/drupal.webservices.cern.ch_drupalprojectconfigs.yaml # +kubebuilder:scaffold:crdkustomizeresource patchesStrategicMerge: @@ -14,7 +13,6 @@ patchesStrategicMerge: #- patches/webhook_in_drupalsites.yaml #- patches/webhook_in_drupalsiteconfigoverrides.yaml #- patches/webhook_in_supporteddrupalversions.yaml -#- patches/webhook_in_drupalprojectconfigs.yaml # +kubebuilder:scaffold:crdkustomizewebhookpatch # [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix. @@ -22,7 +20,6 @@ patchesStrategicMerge: #- patches/cainjection_in_drupalsites.yaml #- patches/cainjection_in_drupalsiteconfigoverrides.yaml #- patches/cainjection_in_supporteddrupalversions.yaml -#- patches/cainjection_in_drupalprojectconfigs.yaml # +kubebuilder:scaffold:crdkustomizecainjectionpatch # the following config is for teaching kustomize how to do kustomization for CRDs. diff --git a/config/crd/patches/cainjection_in_drupalprojectconfigs.yaml b/config/crd/patches/cainjection_in_drupalprojectconfigs.yaml deleted file mode 100644 index 5dcbcbbf..00000000 --- a/config/crd/patches/cainjection_in_drupalprojectconfigs.yaml +++ /dev/null @@ -1,7 +0,0 @@ -# The following patch adds a directive for certmanager to inject CA into the CRD -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) - name: drupalprojectconfigs.drupal.webservices.cern.ch diff --git a/config/crd/patches/webhook_in_drupalprojectconfigs.yaml b/config/crd/patches/webhook_in_drupalprojectconfigs.yaml deleted file mode 100644 index 2481d0d2..00000000 --- a/config/crd/patches/webhook_in_drupalprojectconfigs.yaml +++ /dev/null @@ -1,16 +0,0 @@ -# The following patch enables a conversion webhook for the CRD -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - name: drupalprojectconfigs.drupal.webservices.cern.ch -spec: - conversion: - strategy: Webhook - webhook: - clientConfig: - service: - namespace: system - name: webhook-service - path: /convert - conversionReviewVersions: - - v1 diff --git a/config/rbac/drupalprojectconfig_editor_role.yaml b/config/rbac/drupalprojectconfig_editor_role.yaml deleted file mode 100644 index de76d966..00000000 --- a/config/rbac/drupalprojectconfig_editor_role.yaml +++ /dev/null @@ -1,24 +0,0 @@ -# permissions for end users to edit drupalprojectconfigs. -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: drupalprojectconfig-editor-role -rules: -- apiGroups: - - drupal.webservices.cern.ch - resources: - - drupalprojectconfigs - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - drupal.webservices.cern.ch - resources: - - drupalprojectconfigs/status - verbs: - - get diff --git a/config/rbac/drupalprojectconfig_viewer_role.yaml b/config/rbac/drupalprojectconfig_viewer_role.yaml deleted file mode 100644 index 7ff29ba8..00000000 --- a/config/rbac/drupalprojectconfig_viewer_role.yaml +++ /dev/null @@ -1,20 +0,0 @@ -# permissions for end users to view drupalprojectconfigs. -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: drupalprojectconfig-viewer-role -rules: -- apiGroups: - - drupal.webservices.cern.ch - resources: - - drupalprojectconfigs - verbs: - - get - - list - - watch -- apiGroups: - - drupal.webservices.cern.ch - resources: - - drupalprojectconfigs/status - verbs: - - get diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 82d058d6..afb1d7e2 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -75,24 +75,6 @@ rules: - databases verbs: - '*' -- apiGroups: - - drupal.webservices.cern.ch - resources: - - drupalprojectconfigs - verbs: - - get - - list - - patch - - update - - watch -- apiGroups: - - drupal.webservices.cern.ch - resources: - - drupalprojectconfigs/status - verbs: - - get - - patch - - update - apiGroups: - drupal.webservices.cern.ch resources: diff --git a/config/samples/drupal.webservices_v1alpha1_drupalprojectconfig.yaml b/config/samples/drupal.webservices_v1alpha1_drupalprojectconfig.yaml deleted file mode 100644 index fb9a93e8..00000000 --- a/config/samples/drupal.webservices_v1alpha1_drupalprojectconfig.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: drupal.webservices.cern.ch/v1alpha1 -kind: DrupalProjectConfig -metadata: - name: drupalprojectconfig-sample -spec: - primarySiteName: test-site diff --git a/config/samples/kustomization.yaml b/config/samples/kustomization.yaml index 63b92752..77aabad1 100644 --- a/config/samples/kustomization.yaml +++ b/config/samples/kustomization.yaml @@ -3,5 +3,4 @@ resources: - drupal.webservices_v1alpha1_drupalsite.yaml - drupal.webservices_v1alpha1_drupalsiteconfigoverride.yaml - drupal.webservices_v1alpha1_supporteddrupalversions.yaml -- drupal.webservices_v1alpha1_drupalprojectconfig.yaml # +kubebuilder:scaffold:manifestskustomizesamples -- GitLab From ee24d9e0ed8f1f4cf399a7f1ab39a141417b9db5 Mon Sep 17 00:00:00 2001 From: Dimitra Chatzichrysou <dimitra.chatzichrysou@cern.ch> Date: Wed, 11 May 2022 17:14:35 +0200 Subject: [PATCH 2/2] Remove primary site logic from the controller --- .../templates/manager-rbac.yaml | 3 - controllers/drupalsite_controller.go | 53 +----------- controllers/drupalsite_controller_test.go | 15 ---- controllers/drupalsite_controller_utils.go | 82 +------------------ controllers/drupalsite_resources.go | 2 +- 5 files changed, 4 insertions(+), 151 deletions(-) diff --git a/chart/drupalsite-operator/templates/manager-rbac.yaml b/chart/drupalsite-operator/templates/manager-rbac.yaml index 2f1bd6fb..a9ef04df 100644 --- a/chart/drupalsite-operator/templates/manager-rbac.yaml +++ b/chart/drupalsite-operator/templates/manager-rbac.yaml @@ -80,7 +80,6 @@ rules: resources: - drupalsites - supporteddrupalversions - - drupalprojectconfigs verbs: - "*" - apiGroups: @@ -96,7 +95,6 @@ rules: resources: - drupalsites/finalizers - supporteddrupalversions/finalizers - - drupalprojectconfigs/finalizers verbs: - update - apiGroups: @@ -104,7 +102,6 @@ rules: resources: - drupalsites/status - supporteddrupalversions/status - - drupalprojectconfigs/status verbs: - get - patch diff --git a/controllers/drupalsite_controller.go b/controllers/drupalsite_controller.go index 77f9dabd..aa3e87d6 100644 --- a/controllers/drupalsite_controller.go +++ b/controllers/drupalsite_controller.go @@ -83,8 +83,6 @@ type DrupalSiteReconciler struct { // +kubebuilder:rbac:groups=drupal.webservices.cern.ch,resources=drupalsites/status,verbs=get;update;patch // +kubebuilder:rbac:groups=drupal.webservices.cern.ch,resources=drupalsites/finalizers,verbs=update // +kubebuilder:rbac:groups=drupal.webservices.cern.ch,resources=drupalsiteconfigoverrides,verbs=get;list;watch -// +kubebuilder:rbac:groups=drupal.webservices.cern.ch,resources=drupalprojectconfigs,verbs=get;list;watch;update;patch -// +kubebuilder:rbac:groups=drupal.webservices.cern.ch,resources=drupalprojectconfigs/status,verbs=get;update;patch // +kubebuilder:rbac:groups=app,resources=deployments,verbs=* // +kubebuilder:rbac:groups=build.openshift.io,resources=buildconfigs,verbs=* // +kubebuilder:rbac:groups=build.openshift.io,resources=builds,verbs=get;list;watch @@ -150,13 +148,6 @@ func (r *DrupalSiteReconciler) SetupWithManager(mgr ctrl.Manager) error { return req }), ). - Watches(&source.Kind{Type: &webservicesv1a1.DrupalProjectConfig{}}, handler.EnqueueRequestsFromMapFunc( - // Reconcile every DrupalSite in a given namespace - func(a client.Object) []reconcile.Request { - log := r.Log.WithValues("Source", "Namespace event handler", "Namespace", a.GetNamespace()) - return fetchDrupalSitesInNamespace(mgr, log, a.GetNamespace()) - }), - ). WithOptions(controller.Options{ MaxConcurrentReconciles: ParallelThreadCount, }). @@ -184,19 +175,11 @@ func (r *DrupalSiteReconciler) Reconcile(ctx context.Context, req ctrl.Request) log.Error(err, "Failed to get DrupalSite") return ctrl.Result{}, err } - // Fetch the DrupalProjectConfig Resource - drupalProjectConfig, err := r.GetDrupalProjectConfig(ctx, drupalSite) - if err != nil { - log.Error(err, fmt.Sprintf("%v failed to retrieve DrupalProjectConfig", err)) - // Although we log an Error, we will allow the reconcile to continue, as the absence of the resource does not mean DrupalSite cannot be processed - // Populate resource as nil - drupalProjectConfig = nil - } //Handle deletion if drupalSite.GetDeletionTimestamp() != nil { if controllerutil.ContainsFinalizer(drupalSite, finalizerStr) { - return r.cleanupDrupalSite(ctx, log, drupalSite, drupalProjectConfig) + return r.cleanupDrupalSite(ctx, log, drupalSite) } return ctrl.Result{}, nil } @@ -215,20 +198,6 @@ func (r *DrupalSiteReconciler) Reconcile(ctx context.Context, req ctrl.Request) log.Error(transientErr, "Permanent error marked as transient! Permanent errors should not bubble up to the reconcile loop.") return reconcile.Result{}, nil } - // Log and schedule a new reconciliation - handleNonfatalErr := func(nonfatalErr reconcileError, logstrFmt string) { - if nonfatalErr == nil { - return - } - if nonfatalErr.Temporary() { - log.Error(nonfatalErr, fmt.Sprintf(logstrFmt, nonfatalErr.Unwrap())) - } else { - log.Error(nonfatalErr, "Permanent error marked as transient! Permanent errors should not bubble up to the reconcile loop.") - } - // emitting error because the controller can count it in the error metrics, - // which we can monitor to notice transient problems affecting the entire infrastructure - requeueFlag = nonfatalErr - } // 0. Skip reconciliation if admin-pause annotation is present @@ -288,33 +257,15 @@ func (r *DrupalSiteReconciler) Reconcile(ctx context.Context, req ctrl.Request) update = addGitlabWebhookToStatus(ctx, drupalSite) || update } - // Check if current instance is the Primary Drupalsite and update Status - update = r.checkIfPrimaryDrupalsite(ctx, drupalSite, drupalProjectConfig) || update - // Update status with all the conditions that were checked if update { return r.updateCRStatusOrFailReconcile(ctx, log, drupalSite) } - // Check if DrupalProjectConfig has not a primary website + This DrupalSite instance is unique -> Become Primary Website - updateProjectConfig, reconcileErr := r.proclaimPrimarySiteIfExists(ctx, drupalSite, drupalProjectConfig) - switch { - case err != nil: - log.Error(err, fmt.Sprintf("%v failed to declare this DrupalSite as Primary", reconcileErr.Unwrap())) - setErrorCondition(drupalSite, reconcileErr) - return r.updateCRStatusOrFailReconcile(ctx, log, drupalSite) - case updateProjectConfig: - log.Info("Proclaiming this site as primary in DrupalProjectConfig") - r.checkIfPrimaryDrupalsite(ctx, drupalSite, drupalProjectConfig) - if err = r.updateDrupalProjectConfigCR(ctx, log, drupalProjectConfig); err != nil { - handleNonfatalErr(newApplicationError(err, ErrClientK8s), "%v while updating DrupalProjectConfig") - } - } - backupList, err := r.checkNewBackups(ctx, drupalSite, log) switch { case err != nil: - log.Error(err, fmt.Sprintf("%v failed to check for new backups", reconcileErr.Unwrap())) + log.Error(err, fmt.Sprintf("%v failed to check for new backups", err)) return ctrl.Result{}, err // DeepEqual returns false when one of the slice is empty case len(backupList) != len(drupalSite.Status.AvailableBackups) && !reflect.DeepEqual(backupList, drupalSite.Status.AvailableBackups): diff --git a/controllers/drupalsite_controller_test.go b/controllers/drupalsite_controller_test.go index 06a6f1b9..8028d381 100644 --- a/controllers/drupalsite_controller_test.go +++ b/controllers/drupalsite_controller_test.go @@ -1970,21 +1970,6 @@ var _ = Describe("DrupalSite controller", func() { }) }) }) - Describe("TODO Using DrupalProjectConfig", func() { - Context("", func() { - It("", func() { - // Tests that should be done - // Create a new project without any DrupalProjectConfig, operator logs Warning: Project $PROJECT does not contain any DrupalProjectConfig! - // Createda DrupalProjectConfig with one website and saw spec getting automatically filled, $PROJECT only 1 drupalsite\"$DRUPALSITE\", which is considered the primary production site - // Creation of a second website does not affect DrupalProjectConfig - // Creation of DrupalProjectConfig with 2 DrupalSites in place will not automatically fill spec.primarySiteName - // Deletion of 2 instances to 1, and spec.primarySiteName=="", will auto-fill - // If spec.primarySiteName!="", it is never auto-filled, not even with just one instance being created - // By default DrupalSite.status.isPrimary is false - // Editing DrupalProjectConfig will reflect changes on DrupalSite.status.isPrimary - }) - }) - }) Describe("Deleting the drupalsite object", func() { Context("With critical QoS", func() { It("Should be deleted successfully", func() { diff --git a/controllers/drupalsite_controller_utils.go b/controllers/drupalsite_controller_utils.go index bcd107b4..cda16e20 100644 --- a/controllers/drupalsite_controller_utils.go +++ b/controllers/drupalsite_controller_utils.go @@ -19,7 +19,6 @@ import ( "context" "crypto/md5" "encoding/hex" - "errors" "fmt" "github.com/go-logr/logr" @@ -41,19 +40,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" ) -// updateCRorFailReconcile tries to update the Custom Resource and logs any error -func (r *DrupalSiteReconciler) updateDrupalProjectConfigCR(ctx context.Context, log logr.Logger, dpc *webservicesv1a1.DrupalProjectConfig) error { - err := r.Update(ctx, dpc) - if err != nil { - if k8sapierrors.IsConflict(err) { - log.V(4).Info("DrupalProjectConfig changed while reconciling. Requeuing.") - } else { - log.Error(err, fmt.Sprintf("%v failed to update the application", ErrClientK8s)) - } - } - return err -} - // getBuildStatus gets the build status from one of the builds for a given resources func (r *DrupalSiteReconciler) getBuildStatus(ctx context.Context, resource string, drp *webservicesv1a1.DrupalSite) (buildv1.BuildPhase, error) { buildList := &buildv1.BuildList{} @@ -153,18 +139,9 @@ func databaseSecretName(d *webservicesv1a1.DrupalSite) string { } // cleanupDrupalSite checks and removes if a finalizer exists on the resource -// It also removes the site from the DrupalProjectConfig in case it was the primary site. -func (r *DrupalSiteReconciler) cleanupDrupalSite(ctx context.Context, log logr.Logger, drp *webservicesv1a1.DrupalSite, dpc *webservicesv1a1.DrupalProjectConfig) (ctrl.Result, error) { +func (r *DrupalSiteReconciler) cleanupDrupalSite(ctx context.Context, log logr.Logger, drp *webservicesv1a1.DrupalSite) (ctrl.Result, error) { log.V(1).Info("Deleting DrupalSite") - // Remove site from DrupalProjectConfig if it was the primary site - if dpc != nil && dpc.Spec.PrimarySiteName == drp.Name { - dpc.Spec.PrimarySiteName = "" - if err := r.updateDrupalProjectConfigCR(ctx, log, dpc); err != nil { - return ctrl.Result{}, err - } - } - controllerutil.RemoveFinalizer(drp, finalizerStr) if err := r.ensureNoBackupSchedule(ctx, drp, log); err != nil { return ctrl.Result{}, err @@ -255,63 +232,6 @@ func (r *DrupalSiteReconciler) ensureSpecFinalizer(ctx context.Context, drp *web return update, nil } -// GetDrupalProjectConfig gets the DrupalProjectConfig for a Project -func (r *DrupalSiteReconciler) GetDrupalProjectConfig(ctx context.Context, drp *webservicesv1a1.DrupalSite) (*webservicesv1a1.DrupalProjectConfig, reconcileError) { - // Fetch the DrupalProjectConfigList on the Namespace - drupalProjectConfigList := &webservicesv1a1.DrupalProjectConfigList{} - if err := r.List(ctx, drupalProjectConfigList, &client.ListOptions{Namespace: drp.Namespace}); err != nil { - return nil, newApplicationError(errors.New("fetching drupalProjectConfigList failed"), ErrClientK8s) - } - if len(drupalProjectConfigList.Items) == 0 { - r.Log.Info("Warning: Project " + drp.Namespace + " does not contain any DrupalProjectConfig!") - return nil, nil - } - // We get the first DrupalProjectConfig in the Namespace, only one is expected per project! - return &drupalProjectConfigList.Items[0], nil -} - -// proclaimPrimarySiteIfExists will check for Drupalsites in a project, if only one DrupalSite is in place then we consider that primary exists and can be set on the DrupalProjectConfig, otherwise nothing to do as there is no clear Primary site -func (r *DrupalSiteReconciler) proclaimPrimarySiteIfExists(ctx context.Context, drp *webservicesv1a1.DrupalSite, dpc *webservicesv1a1.DrupalProjectConfig) (update bool, reconcileError reconcileError) { - update = false - if dpc == nil { - return - } - // Check how many DrupalSites are in place on the project - drupalSiteList := &webservicesv1a1.DrupalSiteList{} - if err := r.List(ctx, drupalSiteList, &client.ListOptions{Namespace: drp.Namespace}); err != nil { - reconcileError = newApplicationError(errors.New("fetching drupalSiteList failed"), ErrClientK8s) - return - } - if len(drupalSiteList.Items) > 1 { - // Nothing to do in case there's more than one DrupalSite in the project - return - } - - if dpc.Spec.PrimarySiteName == "" { - dpc.Spec.PrimarySiteName = drp.Name - r.Log.Info("Project" + dpc.Namespace + "contains only 1 drupalsite\"" + drp.Name + "\", which is considered the primary production site") - update = true - return - } - return -} - -//checkIfPrimaryDrupalSite updates the status of the current Drupalsite to show if it is the primary site according to the DrupalProjectConfig -func (r *DrupalSiteReconciler) checkIfPrimaryDrupalsite(ctx context.Context, drp *webservicesv1a1.DrupalSite, dpc *webservicesv1a1.DrupalProjectConfig) bool { - if dpc == nil { - return false - } - // We get the first DrupalProjectConfig in the Namespace, only one is expected per cluster! - if drp.Name == dpc.Spec.PrimarySiteName && !drp.Status.IsPrimary { - drp.Status.IsPrimary = true - return true - } else if drp.Name != dpc.Spec.PrimarySiteName && drp.Status.IsPrimary { - drp.Status.IsPrimary = false - return true - } - return false -} - func (r *DrupalSiteReconciler) getDeployConfigmap(ctx context.Context, d *webservicesv1a1.DrupalSite) (deploy appsv1.Deployment, cmPhp corev1.ConfigMap, cmNginxGlobal corev1.ConfigMap, cmSettings corev1.ConfigMap, cmPhpCli corev1.ConfigMap, err error) { err = r.Get(ctx, types.NamespacedName{Name: d.Name, Namespace: d.Namespace}, &deploy) diff --git a/controllers/drupalsite_resources.go b/controllers/drupalsite_resources.go index 6a563aa6..1ea567ed 100644 --- a/controllers/drupalsite_resources.go +++ b/controllers/drupalsite_resources.go @@ -176,7 +176,7 @@ func (r *DrupalSiteReconciler) ensureResources(drp *webservicesv1a1.DrupalSite, // 5. Cluster-scoped: Backup schedule, Tekton RBAC // Create Velero schedule only after site is initialized in order for the first backup to not report 'Failed' or 'PartiallyFailed' status - if drp.ConditionTrue("Initialized") && (drp.Status.IsPrimary || drp.Spec.Configuration.ScheduledBackups == "enabled") { + if drp.ConditionTrue("Initialized") && drp.Spec.Configuration.ScheduledBackups == "enabled" { if transientErr := r.ensureResourceX(ctx, drp, "backup_schedule", log); transientErr != nil { transientErrs = append(transientErrs, transientErr.Wrap("%v: for Velero Schedule")) } -- GitLab