diff --git a/PROJECT b/PROJECT index 3b0a2d38e16f9d66dccd8a8cbe36209ed36e9696..5d4f467cdaefed6678a9f64843522b922e876ced 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 db4cc702964b7dc37d6c20f9761840315186497b..0000000000000000000000000000000000000000 --- 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 e0f19205a9c244c306bcb8cc842984bb44d05d25..e6fcdc55c9b5d2cc286d444528978a3b491a38f4 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 751f4e792bd1d7f67c85fc8dc9a908fe864e6381..ecae051dcd0c66cb7ebc50b32f480cc40f8442ef 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/chart/drupalsite-operator/templates/manager-rbac.yaml b/chart/drupalsite-operator/templates/manager-rbac.yaml index 2f1bd6fbe4b1202869cce3d8b7b8db7cd86a3af1..a9ef04df7ee0b087b2f3d83235a835607f7c28b8 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/config/crd/bases/drupal.webservices.cern.ch_drupalprojectconfigs.yaml b/config/crd/bases/drupal.webservices.cern.ch_drupalprojectconfigs.yaml deleted file mode 100644 index 069919d86631d3dd423c2cec9a07954a05ce4c21..0000000000000000000000000000000000000000 --- 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 ef30065e43cda0bbef1e3a1399c36ba83e96b988..6c5343aea8488557be75a73ca308f5b7d65496d1 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 d6282601ff27664313e3bc7bd1d2f0e6724a435f..75a2f1591d5d1756e94be70af78422596ed311ef 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 5dcbcbbf3c40ab19b02774664e28ed8db62fa5e8..0000000000000000000000000000000000000000 --- 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 2481d0d27656275100befb369c3ea6cc4ee35eb4..0000000000000000000000000000000000000000 --- 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 de76d96617f9bf69117ffc25ed487abb0242d7c6..0000000000000000000000000000000000000000 --- 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 7ff29ba8cf9e2e2869cc1d3e06a4f6860b58d85c..0000000000000000000000000000000000000000 --- 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 82d058d652bdd4b64fd6409984ac68e03618cba7..afb1d7e22c1a19476fd143b4fa93ec354f6042de 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 fb9a93e8f2cbfbf6e23301844fd01ec4dc2f5f2b..0000000000000000000000000000000000000000 --- 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 63b92752d8da5b4bbfe460843228588e51460377..77aabad166230a99ea23c55d59f3bdd51b6c073e 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 diff --git a/controllers/drupalsite_controller.go b/controllers/drupalsite_controller.go index 77f9dabd4fc669fa6b9edad01b0a2e0494fa652b..aa3e87d622973fbc4136a514bd8dcc4094d6ef47 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 06a6f1b9b9550382b18b23e9136cef314bf15b8d..8028d3818a52ca15ee49347f060cf7ee4c660937 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 bcd107b4ca198c882622619779fbf5c94ad7d59d..cda16e20232b9db0d0d633fbc1378e1d057d0d65 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 6a563aa636a1ce24df9ad196f8fa1c68bb54fb88..1ea567ed8d0b0c21464fc40f1a3dcb203c5e3400 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")) }