@@ -235,13 +235,14 @@ func (r *DrupalSiteReconciler) Reconcile(ctx context.Context, req ctrl.Request)
235
235
236
236
// 1. Init: Check if finalizer is set. If not, set it, validate and update CR status
237
237
238
- if update , err := r .ensureSpecFinalizer (ctx , drupalSite , log ); err != nil {
238
+ if update , err , site := r .ensureSpecFinalizer (ctx , drupalSite , log ); err != nil {
239
239
log .Error (err , fmt .Sprintf ("%v failed to ensure DrupalSite spec defaults" , err .Unwrap ()))
240
240
setErrorCondition (drupalSite , err )
241
- return r .updateCRStatusOrFailReconcile (ctx , log , drupalSite )
241
+ return r .updateCRSpecAndStatusOrFailReconcile (ctx , log , site )
242
242
} else if update {
243
243
log .V (3 ).Info ("Initializing DrupalSite Spec" )
244
- return r .updateCRorFailReconcile (ctx , log , drupalSite )
244
+ return r .updateCRSpecAndStatusOrFailReconcile (ctx , log , site )
245
+ //return r.updateCRorFailReconcile(ctx, log, drupalSite)
245
246
}
246
247
if err := validateSpec (drupalSite .Spec ); err != nil {
247
248
log .Error (err , fmt .Sprintf ("%v failed to validate DrupalSite spec" , err .Unwrap ()))
@@ -512,7 +513,7 @@ func validateSpec(drpSpec webservicesv1a1.DrupalSiteSpec) reconcileError {
512
513
513
514
// ensureSpecFinalizer ensures that the spec is valid, adding extra info if necessary, and that the finalizer is there,
514
515
// then returns if it needs to be updated.
515
- func (r * DrupalSiteReconciler ) ensureSpecFinalizer (ctx context.Context , drp * webservicesv1a1.DrupalSite , log logr.Logger ) (update bool , err reconcileError ) {
516
+ func (r * DrupalSiteReconciler ) ensureSpecFinalizer (ctx context.Context , drp * webservicesv1a1.DrupalSite , log logr.Logger ) (update bool , err reconcileError , site * webservicesv1a1. DrupalSite ) {
516
517
if ! controllerutil .ContainsFinalizer (drp , finalizerStr ) {
517
518
log .V (3 ).Info ("Adding finalizer" )
518
519
controllerutil .AddFinalizer (drp , finalizerStr )
@@ -528,9 +529,9 @@ func (r *DrupalSiteReconciler) ensureSpecFinalizer(ctx context.Context, drp *web
528
529
err := r .Get (ctx , types.NamespacedName {Name : string (drp .Spec .Configuration .CloneFrom ), Namespace : drp .Namespace }, & sourceSite )
529
530
switch {
530
531
case k8sapierrors .IsNotFound (err ):
531
- return false , newApplicationError (fmt .Errorf ("CloneFrom DrupalSite doesn't exist" ), ErrInvalidSpec )
532
+ return false , newApplicationError (fmt .Errorf ("CloneFrom DrupalSite doesn't exist" ), ErrInvalidSpec ), drp
532
533
case err != nil :
533
- return false , newApplicationError (err , ErrClientK8s )
534
+ return false , newApplicationError (err , ErrClientK8s ), drp
534
535
}
535
536
// The destination disk size must be at least as large as the source
536
537
if drp .Spec .Configuration .DiskSize < sourceSite .Spec .Configuration .DiskSize {
@@ -546,13 +547,23 @@ func (r *DrupalSiteReconciler) ensureSpecFinalizer(ctx context.Context, drp *web
546
547
}
547
548
update = true
548
549
}
549
-
550
550
// Initialize 'Spec.Configuration.ScheduledBackups' if empty
551
- if len (drp .Spec .Configuration .ScheduledBackups ) == 0 {
552
- drp .Spec .Configuration .ScheduledBackups = "enabled"
551
+ if drp .Spec .Configuration .IsPrimary {
552
+ drupalsiteList := & webservicesv1a1.DrupalSiteList {}
553
+ r .Client .List (ctx , drupalsiteList , & client.ListOptions {Namespace : drp .Namespace })
554
+ drp .Status .IsPrimary = drp .Spec .IsPrimary
555
+ for _ , site := range drupalsiteList .Items {
556
+ //if site.Spec.IsPrimary && site.Name != drp.Name {
557
+ if site .Spec .IsPrimary {
558
+ update = true
559
+ site .Spec .IsPrimary = false
560
+ return update , nil , & site
561
+ }
562
+ }
563
+ //drp.Status.IsPrimary = drp.Spec.IsPrimary
553
564
update = true
554
565
}
555
- return update , nil
566
+ return update , nil , drp
556
567
}
557
568
558
569
// getRunningdeployment fetches the running drupal deployment
0 commit comments