From 044d11c15cd0b06c42e623fd632e60aa1e003e79 Mon Sep 17 00:00:00 2001 From: KevFan Date: Fri, 15 Nov 2024 09:55:41 +0000 Subject: [PATCH] refactor: IsAuthorinoOperatorInstalled function Signed-off-by: KevFan --- controllers/state_of_the_world.go | 10 +--------- pkg/authorino/conditions.go | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/controllers/state_of_the_world.go b/controllers/state_of_the_world.go index 8ddc30c85..be04407ea 100644 --- a/controllers/state_of_the_world.go +++ b/controllers/state_of_the_world.go @@ -355,13 +355,7 @@ func (b *BootOptionsBuilder) getLimitadorOperatorOptions() []controller.Controll func (b *BootOptionsBuilder) getAuthorinoOperatorOptions() []controller.ControllerOption { var opts []controller.ControllerOption var err error - b.isAuthorinoOperatorInstalled, err = utils.IsCRDInstalled(b.manager.GetRESTMapper(), kuadrantv1beta1.AuthorinoGroupKind.Group, kuadrantv1beta1.AuthorinoGroupKind.Kind, authorinooperatorv1beta1.GroupVersion.Version) - if err != nil || !b.isAuthorinoOperatorInstalled { - b.logger.Info("authorino operator is not installed, skipping related watches and reconcilers", "err", err) - return opts - } - - b.isAuthorinoOperatorInstalled, err = utils.IsCRDInstalled(b.manager.GetRESTMapper(), authorino.AuthConfigGroupKind.Group, authorino.AuthConfigGroupKind.Kind, authorinov1beta3.GroupVersion.Version) + b.isAuthorinoOperatorInstalled, err = authorino.IsAuthorinoOperatorInstalled(b.manager.GetRESTMapper(), b.logger) if err != nil || !b.isAuthorinoOperatorInstalled { b.logger.Info("authorino operator is not installed, skipping related watches and reconcilers", "err", err) return opts @@ -522,8 +516,6 @@ func finalStepsWorkflow(client *dynamic.DynamicClient, isGatewayAPIInstalled, is return workflow } -var ErrMissingKuadrant = fmt.Errorf("missing kuadrant object in topology") - func GetKuadrantFromTopology(topology *machinery.Topology) *kuadrantv1beta1.Kuadrant { kuadrants := lo.FilterMap(topology.Objects().Roots(), func(root machinery.Object, _ int) (controller.Object, bool) { o, isSortable := root.(controller.Object) diff --git a/pkg/authorino/conditions.go b/pkg/authorino/conditions.go index 49010b476..fd8a2ca5c 100644 --- a/pkg/authorino/conditions.go +++ b/pkg/authorino/conditions.go @@ -1,15 +1,36 @@ package authorino import ( - authorinov1beta1 "github.com/kuadrant/authorino-operator/api/v1beta1" + "github.com/go-logr/logr" + authorinooperatorv1beta1 "github.com/kuadrant/authorino-operator/api/v1beta1" + authorinov1beta3 "github.com/kuadrant/authorino/api/v1beta3" + "k8s.io/apimachinery/pkg/api/meta" + + "github.com/kuadrant/kuadrant-operator/pkg/utils" + + kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1" ) -func FindAuthorinoStatusCondition(conditions []authorinov1beta1.Condition, conditionType string) *authorinov1beta1.Condition { +func FindAuthorinoStatusCondition(conditions []authorinooperatorv1beta1.Condition, conditionType string) *authorinooperatorv1beta1.Condition { for i := range conditions { - if conditions[i].Type == authorinov1beta1.ConditionType(conditionType) { + if conditions[i].Type == authorinooperatorv1beta1.ConditionType(conditionType) { return &conditions[i] } } return nil } + +func IsAuthorinoOperatorInstalled(restMapper meta.RESTMapper, logger logr.Logger) (bool, error) { + if ok, err := utils.IsCRDInstalled(restMapper, kuadrantv1beta1.AuthorinoGroupKind.Group, kuadrantv1beta1.AuthorinoGroupKind.Kind, authorinooperatorv1beta1.GroupVersion.Version); !ok || err != nil { + logger.V(1).Error(err, "Authorino Operator CRD was not installed", "group", kuadrantv1beta1.AuthorinoGroupKind.Group, "kind", kuadrantv1beta1.AuthorinoGroupKind.Kind, "version", authorinooperatorv1beta1.GroupVersion.Version) + return false, err + } + + if ok, err := utils.IsCRDInstalled(restMapper, AuthConfigGroupKind.Group, AuthConfigGroupKind.Kind, authorinov1beta3.GroupVersion.Version); !ok || err != nil { + logger.V(1).Error(err, "Authorino Operator CRD was not installed", "group", AuthConfigGroupKind.Group, "kind", AuthConfigGroupKind.Kind, "version", authorinov1beta3.GroupVersion.Version) + return false, err + } + + return true, nil +}