Skip to content

Commit

Permalink
refactor: IsAuthorinoOperatorInstalled function
Browse files Browse the repository at this point in the history
Signed-off-by: KevFan <[email protected]>
  • Loading branch information
KevFan committed Dec 2, 2024
1 parent ded41f1 commit 7442260
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
10 changes: 1 addition & 9 deletions controllers/state_of_the_world.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
27 changes: 24 additions & 3 deletions pkg/authorino/conditions.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 7442260

Please sign in to comment.