Skip to content

Commit 010cba6

Browse files
author
Francisco Barros
committed
Refactoring some code...
1 parent ab6be13 commit 010cba6

File tree

2 files changed

+69
-10
lines changed

2 files changed

+69
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
---
3+
apiVersion: apiextensions.k8s.io/v1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
controller-gen.kubebuilder.io/version: v0.4.1
8+
creationTimestamp: null
9+
name: drupalprojectconfigs.drupal.webservices.cern.ch
10+
spec:
11+
group: drupal.webservices.cern.ch
12+
names:
13+
kind: DrupalProjectConfig
14+
listKind: DrupalProjectConfigList
15+
plural: drupalprojectconfigs
16+
singular: drupalprojectconfig
17+
scope: Namespaced
18+
versions:
19+
- name: v1alpha1
20+
schema:
21+
openAPIV3Schema:
22+
description: DrupalProjectConfig is the Schema for the drupalprojectconfigs
23+
API
24+
properties:
25+
apiVersion:
26+
description: 'APIVersion defines the versioned schema of this representation
27+
of an object. Servers should convert recognized schemas to the latest
28+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
29+
type: string
30+
kind:
31+
description: 'Kind is a string value representing the REST resource this
32+
object represents. Servers may infer this from the endpoint the client
33+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
34+
type: string
35+
metadata:
36+
type: object
37+
spec:
38+
description: DrupalProjectConfigSpec defines the desired state of DrupalProjectConfig
39+
properties:
40+
primarySiteName:
41+
description: PrimarySiteName defines the primary DrupalSite instance
42+
of a project
43+
type: string
44+
type: object
45+
status:
46+
description: DrupalProjectConfigStatus defines the observed state of DrupalProjectConfig
47+
type: object
48+
type: object
49+
served: true
50+
storage: true
51+
subresources:
52+
status: {}
53+
status:
54+
acceptedNames:
55+
kind: ""
56+
plural: ""
57+
conditions: []
58+
storedVersions: []

controllers/drupalsite_controller.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,12 @@ func (r *DrupalSiteReconciler) SetupWithManager(mgr ctrl.Manager) error {
156156
Watches(&source.Kind{Type: &webservicesv1a1.DrupalProjectConfig{}}, handler.EnqueueRequestsFromMapFunc(
157157
// Reconcile every DrupalSite in a given namespace
158158
func(a client.Object) []reconcile.Request {
159-
req := make([]reconcile.Request, 1)
160-
// The DrupalSite has the same name as the DrupalSiteConfigOverride
161-
req[0].Name = a.GetName()
162-
req[0].Namespace = a.GetNamespace()
163-
return req
159+
log := r.Log.WithValues("Source", "Namespace event handler", "Namespace", a.GetName())
160+
_, exists := a.GetLabels()["drupal.cern.ch/user-project"]
161+
if exists {
162+
return fetchDrupalSitesInNamespace(mgr, log, a.GetName())
163+
}
164+
return []reconcile.Request{}
164165
}),
165166
).
166167
WithOptions(controller.Options{
@@ -326,22 +327,22 @@ func (r *DrupalSiteReconciler) Reconcile(ctx context.Context, req ctrl.Request)
326327
}
327328
}
328329
}
329-
// Check if Primary DrupalSite HAS a website, and if it does NOT + This DrupalSIte instance is unique -> Become Primary Website
330-
if needsUpdate, err, dpc := r.checkIfPrimaryDrupalsiteExists(ctx, drupalSite); err != nil {
330+
// Check if DrupalProjectConfig has not a primary website + This DrupalSite instance is unique -> Become Primary Website
331+
if updateNeeded, err, dpc := r.checkIfPrimaryDrupalsiteExists(ctx, drupalSite); err != nil {
331332
log.Error(err, fmt.Sprintf("%v failed to validate if DrupalSite is Primary", err.Unwrap()))
332333
setErrorCondition(drupalSite, err)
333334
return r.updateCRStatusOrFailReconcile(ctx, log, drupalSite)
334-
} else if needsUpdate {
335+
} else if updateNeeded {
335336
log.Info("Updating DrupalProjectConfig", "")
336337
return r.updateDrupalProjectConfigCRorFailReconcile(ctx, log, dpc)
337338
}
338339

339340
// Check if current instance is the Primary Drupalsite
340-
if needsUpdate, err := r.checkIfPrimaryDrupalsite(ctx, drupalSite); err != nil {
341+
if updateNeeded, err := r.checkIfPrimaryDrupalsite(ctx, drupalSite); err != nil {
341342
log.Error(err, fmt.Sprintf("%v failed to validate if DrupalSite is Primary", err.Unwrap()))
342343
setErrorCondition(drupalSite, err)
343344
return r.updateCRStatusOrFailReconcile(ctx, log, drupalSite)
344-
} else if needsUpdate {
345+
} else if updateNeeded {
345346
return r.updateCRStatusOrFailReconcile(ctx, log, drupalSite)
346347
}
347348

0 commit comments

Comments
 (0)