@@ -27,6 +27,7 @@ import (
2727 "github.com/go-logr/logr"
2828 "go.mongodb.org/mongo-driver/mongo"
2929 "go.mongodb.org/mongo-driver/mongo/options"
30+ "golang.org/x/exp/slices"
3031 corev1 "k8s.io/api/core/v1"
3132 apierrors "k8s.io/apimachinery/pkg/api/errors"
3233 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -302,12 +303,12 @@ func (r *GrowthbookInstanceReconciler) Reconcile(ctx context.Context, req ctrl.R
302303}
303304
304305func (r * GrowthbookInstanceReconciler ) reconcile (ctx context.Context , instance v1beta1.GrowthbookInstance , logger logr.Logger ) (v1beta1.GrowthbookInstance , error ) {
305- msg := "reconcile instance progressing"
306+ /* msg := "reconcile instance progressing"
306307 r.Recorder.Event(&instance, "Normal", "info", msg)
307308 instance = v1beta1.GrowthbookInstanceNotReady(instance, v1beta1.ProgressingReason, msg)
308309 if err := r.patchStatus(ctx, &instance); err != nil {
309310 return instance, err
310- }
311+ }*/
311312
312313 var err error
313314 var usr , pw string
@@ -363,11 +364,7 @@ func (r *GrowthbookInstanceReconciler) reconcileOrganizations(ctx context.Contex
363364 }
364365
365366 for _ , org := range orgs .Items {
366- instance .Status .SubResourceCatalog = append (instance .Status .SubResourceCatalog , v1beta1.ResourceReference {
367- Kind : org .Kind ,
368- Name : org .Name ,
369- APIVersion : org .APIVersion ,
370- })
367+ instance = updateResourceCatalog (instance , & org )
371368 }
372369
373370 for _ , org := range orgs .Items {
@@ -423,11 +420,7 @@ func (r *GrowthbookInstanceReconciler) reconcileFeatures(ctx context.Context, in
423420 }
424421
425422 for _ , feature := range features .Items {
426- instance .Status .SubResourceCatalog = append (instance .Status .SubResourceCatalog , v1beta1.ResourceReference {
427- Kind : feature .Kind ,
428- Name : feature .Name ,
429- APIVersion : feature .APIVersion ,
430- })
423+ instance = updateResourceCatalog (instance , & feature )
431424 }
432425
433426 for _ , feature := range features .Items {
@@ -459,11 +452,7 @@ func (r *GrowthbookInstanceReconciler) reconcileUsers(ctx context.Context, insta
459452 }
460453
461454 for _ , user := range users .Items {
462- instance .Status .SubResourceCatalog = append (instance .Status .SubResourceCatalog , v1beta1.ResourceReference {
463- Kind : user .Kind ,
464- Name : user .Name ,
465- APIVersion : user .APIVersion ,
466- })
455+ instance = updateResourceCatalog (instance , & user )
467456 }
468457
469458 for _ , user := range users .Items {
@@ -510,11 +499,7 @@ func (r *GrowthbookInstanceReconciler) reconcileClients(ctx context.Context, ins
510499 }
511500
512501 for _ , client := range clients .Items {
513- instance .Status .SubResourceCatalog = append (instance .Status .SubResourceCatalog , v1beta1.ResourceReference {
514- Kind : client .Kind ,
515- Name : client .Name ,
516- APIVersion : client .APIVersion ,
517- })
502+ instance = updateResourceCatalog (instance , & client )
518503 }
519504
520505 for _ , client := range clients .Items {
@@ -579,6 +564,20 @@ func (r *GrowthbookInstanceReconciler) getClientToken(ctx context.Context, clien
579564 }
580565}
581566
567+ func updateResourceCatalog (instance v1beta1.GrowthbookInstance , resource client.Object ) v1beta1.GrowthbookInstance {
568+ resRef := v1beta1.ResourceReference {
569+ Kind : resource .GetObjectKind ().GroupVersionKind ().Kind ,
570+ Name : resource .GetName (),
571+ APIVersion : fmt .Sprintf ("%s/%s" , resource .GetObjectKind ().GroupVersionKind ().Group , resource .GetObjectKind ().GroupVersionKind ().Version ),
572+ }
573+
574+ if ! slices .Contains (instance .Status .SubResourceCatalog , resRef ) {
575+ instance .Status .SubResourceCatalog = append (instance .Status .SubResourceCatalog , resRef )
576+ }
577+
578+ return instance
579+ }
580+
582581func (r * GrowthbookInstanceReconciler ) getUsernamePassword (ctx context.Context , instance v1beta1.GrowthbookInstance , secretReference * v1beta1.SecretReference ) (string , string , error ) {
583582 if secretReference == nil {
584583 return "" , "" , errors .New ("no secret reference provided" )
0 commit comments