Skip to content

Commit

Permalink
PR comment changes
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Fitzpatrick <[email protected]>
  • Loading branch information
Boomatang committed Sep 25, 2024
1 parent c4e9a6f commit e8740c5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion api/v1beta1/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
})
},
}
Expand Down
25 changes: 14 additions & 11 deletions controllers/authorino_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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,
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 0 additions & 2 deletions controllers/kuadrant_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions controllers/state_of_the_world.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func (e *EventLogger) Log(ctx context.Context, resourceEvents []controller.Resou
return nil
}

// 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
Expand Down

0 comments on commit e8740c5

Please sign in to comment.