@@ -326,13 +326,13 @@ func (r *DrupalSiteReconciler) Reconcile(ctx context.Context, req ctrl.Request)
326
326
}
327
327
}
328
328
}
329
- // TODO: Check if Primary DrupalSite HAS a website, and if it does NOT + This DrupalSIte instance is unique -> Become Primary Website
329
+ // Check if Primary DrupalSite HAS a website, and if it does NOT + This DrupalSIte instance is unique -> Become Primary Website
330
330
if needsUpdate , err , dpc := r .checkIfPrimaryDrupalsiteExists (ctx , drupalSite ); err != nil {
331
331
log .Error (err , fmt .Sprintf ("%v failed to validate if DrupalSite is Primary" , err .Unwrap ()))
332
332
setErrorCondition (drupalSite , err )
333
333
return r .updateCRStatusOrFailReconcile (ctx , log , drupalSite )
334
334
} else if needsUpdate {
335
- log .Info ("Updating DrupalProjectConfig of project %s" , drupalSite . Namespace , "" )
335
+ log .Info ("Updating DrupalProjectConfig" , "" )
336
336
return r .updateDrupalProjectConfigCRorFailReconcile (ctx , log , dpc )
337
337
}
338
338
@@ -342,7 +342,6 @@ func (r *DrupalSiteReconciler) Reconcile(ctx context.Context, req ctrl.Request)
342
342
setErrorCondition (drupalSite , err )
343
343
return r .updateCRStatusOrFailReconcile (ctx , log , drupalSite )
344
344
} else if needsUpdate {
345
- log .Info ("Updating IsPrimary Site Status of %s" , drupalSite .Name , "" )
346
345
return r .updateCRStatusOrFailReconcile (ctx , log , drupalSite )
347
346
}
348
347
@@ -859,25 +858,28 @@ func (r *DrupalSiteReconciler) checkIfPrimaryDrupalsiteExists(ctx context.Contex
859
858
}
860
859
861
860
//checkIfPrimaryDrupalSite checks if current DrupalSite is primary or not in the project
862
- func (r * DrupalSiteReconciler ) checkIfPrimaryDrupalsite (ctx context.Context , drp * webservicesv1a1.DrupalSite ) (bool , reconcileError ) {
861
+ func (r * DrupalSiteReconciler ) checkIfPrimaryDrupalsite (ctx context.Context , drp * webservicesv1a1.DrupalSite ) (update bool , reconcileErr reconcileError ) {
862
+ update = false
863
863
// Fetch the DrupalProjectConfigList on the Namespace
864
864
drupalProjectConfigList := & webservicesv1a1.DrupalProjectConfigList {}
865
865
if err := r .List (ctx , drupalProjectConfigList , & client.ListOptions {Namespace : drp .Namespace }); err != nil {
866
- return false , newApplicationError (errors .New ("fetching drupalProjectConfigList failed" ), ErrClientK8s )
866
+ reconcileErr = newApplicationError (errors .New ("fetching drupalProjectConfigList failed" ), ErrClientK8s )
867
+ return
867
868
}
868
869
if len (drupalProjectConfigList .Items ) == 0 {
869
870
r .Log .Info ("Warning: Project %s does not contain any DrupalProjectConfig!" , drp .Namespace )
870
- return false , nil
871
+ return
871
872
}
872
873
// We get the first DrupalProjectConfig in the Namespace, only one is expected per cluster!
873
874
drupalProjectConfig := drupalProjectConfigList .Items [0 ]
874
875
if drp .Name == drupalProjectConfig .Spec .PrimarySiteName && ! drp .Status .IsPrimary {
876
+ update = true
875
877
drp .Status .IsPrimary = true
876
- return true , nil
877
- }
878
- if drp . Name != drupalProjectConfig . Spec . PrimarySiteName && drp . Status . IsPrimary {
878
+ return
879
+ } else if drp . Name != drupalProjectConfig . Spec . PrimarySiteName && drp . Status . IsPrimary {
880
+ update = true
879
881
drp .Status .IsPrimary = false
880
- return true , nil
882
+ return
881
883
}
882
- return false , nil
884
+ return
883
885
}
0 commit comments