diff --git a/api/v1beta1/topology.go b/api/v1beta1/topology.go index e36860c02..b5de93b58 100644 --- a/api/v1beta1/topology.go +++ b/api/v1beta1/topology.go @@ -46,7 +46,7 @@ func LinkKuadrantToAuthorino(objs controller.Store) machinery.LinkFunc { To: AuthorinoKind, Func: func(child machinery.Object) []machinery.Object { return lo.Filter(kuadrants, func(kuadrant machinery.Object, _ int) bool { - return kuadrant.GetNamespace() == child.GetNamespace() + return kuadrant.GetNamespace() == child.GetNamespace() && child.GetName() == "authorino" }) }, } diff --git a/controllers/authorino_task.go b/controllers/authorino_task.go index 3a92ab60a..ead3ad29f 100644 --- a/controllers/authorino_task.go +++ b/controllers/authorino_task.go @@ -2,15 +2,18 @@ package controllers import ( "context" + "strings" + v1beta2 "github.com/kuadrant/authorino-operator/api/v1beta1" - "github.com/kuadrant/kuadrant-operator/api/v1beta1" "github.com/kuadrant/policy-machinery/controller" "github.com/kuadrant/policy-machinery/machinery" "github.com/samber/lo" "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/apis/meta/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/dynamic" "k8s.io/utils/ptr" + + "github.com/kuadrant/kuadrant-operator/api/v1beta1" ) type AuthorinoCrReconciler struct { @@ -45,15 +48,15 @@ func (r *AuthorinoCrReconciler) Reconcile(ctx context.Context, _ []controller.Re kobj, err := GetOldestKuadrant(kobjs) if err != nil { + if strings.Contains(err.Error(), "empty list passed") { + logger.Info("kuadrant resource not found, ignoring", "status", "skipping") + return + } logger.Error(err, "cannot find Kuadrant resource", "status", "error") - } - - if kobj.GetDeletionTimestamp() != nil { - logger.Info("root kuadrant marked for deletion", "status", "skipping") return } - aobjs := lo.FilterMap(topology.Objects().Objects().Items(), func(item machinery.Object, _ int) (machinery.Object, bool) { + aobjs := lo.FilterMap(topology.Objects().Objects().Children(kobj), func(item machinery.Object, _ int) (machinery.Object, bool) { if item.GroupVersionKind().Kind == v1beta1.AuthorinoKind.Kind { return item, true } @@ -66,14 +69,14 @@ func (r *AuthorinoCrReconciler) Reconcile(ctx context.Context, _ []controller.Re } authorino := &v1beta2.Authorino{ - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Authorino", APIVersion: "operator.authorino.kuadrant.io/v1beta1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "authorino", Namespace: kobj.Namespace, - OwnerReferences: []v1.OwnerReference{ + OwnerReferences: []metav1.OwnerReference{ { APIVersion: kobj.GroupVersionKind().GroupVersion().String(), Kind: kobj.GroupVersionKind().Kind, @@ -105,7 +108,7 @@ func (r *AuthorinoCrReconciler) Reconcile(ctx context.Context, _ []controller.Re logger.Error(err, "failed to destruct authorino", "status", "error") } logger.Info("creating authorino resource", "status", "processing") - _, err = r.Client.Resource(v1beta1.AuthorinoResource).Namespace(authorino.Namespace).Create(ctx, unstructuredAuthorino, v1.CreateOptions{}) + _, err = r.Client.Resource(v1beta1.AuthorinoResource).Namespace(authorino.Namespace).Create(ctx, unstructuredAuthorino, metav1.CreateOptions{}) if err != nil { if errors.IsAlreadyExists(err) { logger.Info("already created authorino resource", "status", "acceptable") diff --git a/controllers/kuadrant_controller.go b/controllers/kuadrant_controller.go index b63929306..c7e130571 100644 --- a/controllers/kuadrant_controller.go +++ b/controllers/kuadrant_controller.go @@ -21,7 +21,6 @@ import ( "encoding/json" "github.com/go-logr/logr" - authorinov1beta1 "github.com/kuadrant/authorino-operator/api/v1beta1" limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1" iopv1alpha1 "istio.io/istio/operator/pkg/apis/istio/v1alpha1" corev1 "k8s.io/api/core/v1" @@ -437,6 +436,5 @@ func (r *KuadrantReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). For(&kuadrantv1beta1.Kuadrant{}). Owns(&limitadorv1alpha1.Limitador{}). - Owns(&authorinov1beta1.Authorino{}). Complete(r) } diff --git a/controllers/state_of_the_world.go b/controllers/state_of_the_world.go index e21c4cd81..3a4b2d007 100644 --- a/controllers/state_of_the_world.go +++ b/controllers/state_of_the_world.go @@ -174,6 +174,7 @@ func (e *EventLogger) Log(ctx context.Context, resourceEvents []controller.Resou } } +// GetOldestKuadrant returns the oldest kuadrant resource from a list of kuadrant resources that is not marked for deletion. func GetOldestKuadrant(kuadrants []*kuadrantv1beta1.Kuadrant) (*kuadrantv1beta1.Kuadrant, error) { if len(kuadrants) == 1 { return kuadrants[0], nil