Skip to content

Commit 07dcdc7

Browse files
author
Francisco Barros
committed
Changing to new CRD approach...
1 parent a78e1e7 commit 07dcdc7

12 files changed

+233
-17
lines changed

PROJECT

+8
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,12 @@ resources:
3333
kind: SupportedDrupalVersions
3434
path: gitlab.cern.ch/drupal/paas/drupalsite-operator/api/v1alpha1
3535
version: v1alpha1
36+
- api:
37+
crdVersion: v1
38+
namespaced: true
39+
domain: cern.ch
40+
group: drupal.webservices
41+
kind: DrupalProjectConfig
42+
path: gitlab.cern.ch/drupal/paas/drupalsite-operator/api/v1alpha1
43+
version: v1alpha1
3644
version: "3"
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Copyright 2021 CERN.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// DrupalProjectConfigSpec defines the desired state of DrupalProjectConfig
24+
type DrupalProjectConfigSpec struct {
25+
// PrimarySiteName defines the primary DrupalSite instance of a project
26+
PrimarySiteName string `json:"primarySiteName,omitempty"`
27+
}
28+
29+
// DrupalProjectConfigStatus defines the observed state of DrupalProjectConfig
30+
type DrupalProjectConfigStatus struct {
31+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
32+
}
33+
34+
//+kubebuilder:object:root=true
35+
//+kubebuilder:subresource:status
36+
37+
// DrupalProjectConfig is the Schema for the drupalprojectconfigs API
38+
type DrupalProjectConfig struct {
39+
metav1.TypeMeta `json:",inline"`
40+
metav1.ObjectMeta `json:"metadata,omitempty"`
41+
42+
Spec DrupalProjectConfigSpec `json:"spec,omitempty"`
43+
Status DrupalProjectConfigStatus `json:"status,omitempty"`
44+
}
45+
46+
//+kubebuilder:object:root=true
47+
48+
// DrupalProjectConfigList contains a list of DrupalProjectConfig
49+
type DrupalProjectConfigList struct {
50+
metav1.TypeMeta `json:",inline"`
51+
metav1.ListMeta `json:"metadata,omitempty"`
52+
Items []DrupalProjectConfig `json:"items"`
53+
}
54+
55+
func init() {
56+
SchemeBuilder.Register(&DrupalProjectConfig{}, &DrupalProjectConfigList{})
57+
}

api/v1alpha1/zz_generated.deepcopy.go

+89
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/kustomization.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ resources:
55
- bases/drupal.webservices.cern.ch_drupalsites.yaml
66
- bases/drupal.webservices.cern.ch_drupalsiteconfigoverrides.yaml
77
- bases/drupal.webservices.cern.ch_supporteddrupalversions.yaml
8+
- bases/drupal.webservices.cern.ch_drupalprojectconfigs.yaml
89
# +kubebuilder:scaffold:crdkustomizeresource
910

1011
patchesStrategicMerge:
@@ -13,13 +14,15 @@ patchesStrategicMerge:
1314
#- patches/webhook_in_drupalsites.yaml
1415
#- patches/webhook_in_drupalsiteconfigoverrides.yaml
1516
#- patches/webhook_in_supporteddrupalversions.yaml
17+
#- patches/webhook_in_drupalprojectconfigs.yaml
1618
# +kubebuilder:scaffold:crdkustomizewebhookpatch
1719

1820
# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
1921
# patches here are for enabling the CA injection for each CRD
2022
#- patches/cainjection_in_drupalsites.yaml
2123
#- patches/cainjection_in_drupalsiteconfigoverrides.yaml
2224
#- patches/cainjection_in_supporteddrupalversions.yaml
25+
#- patches/cainjection_in_drupalprojectconfigs.yaml
2326
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
2427

2528
# the following config is for teaching kustomize how to do kustomization for CRDs.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# The following patch adds a directive for certmanager to inject CA into the CRD
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
7+
name: drupalprojectconfigs.drupal.webservices.cern.ch
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# The following patch enables a conversion webhook for the CRD
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
name: drupalprojectconfigs.drupal.webservices.cern.ch
6+
spec:
7+
conversion:
8+
strategy: Webhook
9+
webhook:
10+
clientConfig:
11+
service:
12+
namespace: system
13+
name: webhook-service
14+
path: /convert
15+
conversionReviewVersions:
16+
- v1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# permissions for end users to edit drupalprojectconfigs.
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
name: drupalprojectconfig-editor-role
6+
rules:
7+
- apiGroups:
8+
- drupal.webservices.cern.ch
9+
resources:
10+
- drupalprojectconfigs
11+
verbs:
12+
- create
13+
- delete
14+
- get
15+
- list
16+
- patch
17+
- update
18+
- watch
19+
- apiGroups:
20+
- drupal.webservices.cern.ch
21+
resources:
22+
- drupalprojectconfigs/status
23+
verbs:
24+
- get
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# permissions for end users to view drupalprojectconfigs.
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
name: drupalprojectconfig-viewer-role
6+
rules:
7+
- apiGroups:
8+
- drupal.webservices.cern.ch
9+
resources:
10+
- drupalprojectconfigs
11+
verbs:
12+
- get
13+
- list
14+
- watch
15+
- apiGroups:
16+
- drupal.webservices.cern.ch
17+
resources:
18+
- drupalprojectconfigs/status
19+
verbs:
20+
- get
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: drupal.webservices.cern.ch/v1alpha1
2+
kind: DrupalProjectConfig
3+
metadata:
4+
name: drupalprojectconfig-sample
5+
spec:
6+
primarySiteName: test-site

config/samples/kustomization.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ resources:
33
- drupal.webservices_v1alpha1_drupalsite.yaml
44
- drupal.webservices_v1alpha1_drupalsiteconfigoverride.yaml
55
- drupal.webservices_v1alpha1_supporteddrupalversions.yaml
6+
- drupal.webservices_v1alpha1_drupalprojectconfig.yaml
67
# +kubebuilder:scaffold:manifestskustomizesamples

controllers/drupalsite_controller.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ func (r *DrupalSiteReconciler) Reconcile(ctx context.Context, req ctrl.Request)
238238
if update, err, site := r.ensureSpecFinalizer(ctx, drupalSite, log); err != nil {
239239
log.Error(err, fmt.Sprintf("%v failed to ensure DrupalSite spec defaults", err.Unwrap()))
240240
setErrorCondition(drupalSite, err)
241-
return r.updateCRSpecAndStatusOrFailReconcile(ctx, log, site)
241+
return r.updateCRStatusOrFailReconcile(ctx, log, site)
242242
} else if update {
243243
log.V(3).Info("Initializing DrupalSite Spec")
244-
return r.updateCRSpecAndStatusOrFailReconcile(ctx, log, site)
244+
return r.updateCRStatusOrFailReconcile(ctx, log, site)
245245
//return r.updateCRorFailReconcile(ctx, log, drupalSite)
246246
}
247247
if err := validateSpec(drupalSite.Spec); err != nil {

controllers/reconciler_utils.go

-15
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,6 @@ func (r *DrupalSiteReconciler) updateCRStatusOrFailReconcile(ctx context.Context
148148
return reconcile.Result{}, nil
149149
}
150150

151-
// updateCRStatusOrFailReconcile tries to update the Custom Resource Status and logs any error
152-
func (r *DrupalSiteReconciler) updateCRSpecAndStatusOrFailReconcile(ctx context.Context, log logr.Logger, drp *webservicesv1a1.DrupalSite) (
153-
reconcile.Result, error) {
154-
if err := r.Client.Patch(ctx, drp, nil); err != nil {
155-
//if err := r.Status().Update(ctx, drp); err != nil {
156-
if k8sapierrors.IsConflict(err) {
157-
log.V(4).Info("Object changed while reconciling. Requeuing.")
158-
return reconcile.Result{Requeue: true}, nil
159-
}
160-
log.Error(err, fmt.Sprintf("%v failed to update the application status", ErrClientK8s))
161-
return reconcile.Result{}, err
162-
}
163-
return reconcile.Result{}, nil
164-
}
165-
166151
// getBuildStatus gets the build status from one of the builds for a given resources
167152
func (r *DrupalSiteReconciler) getBuildStatus(ctx context.Context, resource string, drp *webservicesv1a1.DrupalSite) (buildv1.BuildPhase, error) {
168153
buildList := &buildv1.BuildList{}

0 commit comments

Comments
 (0)