Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the error to detect when the server only has v1beta1 CRDs #107

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions controllers/templatesync/template_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"open-cluster-management.io/governance-policy-propagator/controllers/common"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand All @@ -51,8 +52,8 @@ const (
)

var (
log = ctrl.Log.WithName(ControllerName)
errGroupDiscoveryFailed *discovery.ErrGroupDiscoveryFailed
log = ctrl.Log.WithName(ControllerName)
errResourceDiscoveryFailed *apiutil.ErrResourceDiscoveryFailed
)

//+kubebuilder:rbac:groups=policy.open-cluster-management.io,resources=*,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -1004,7 +1005,7 @@ func (r *PolicyReconciler) cleanUpExcessTemplates(
namespaced: false,
})
}
} else if errors.As(err, &errGroupDiscoveryFailed) {
} else if errors.As(err, &errResourceDiscoveryFailed) {
// If there's no v1 ConstraintTemplate, try the v1beta1 version
gkConstraintTemplateListv1beta1 := gktemplatesv1beta1.ConstraintTemplateList{}
err := r.List(ctx, &gkConstraintTemplateListv1beta1, &client.ListOptions{})
Expand Down Expand Up @@ -1035,7 +1036,7 @@ func (r *PolicyReconciler) cleanUpExcessTemplates(
})
}
// Log and ignore other errors to allow cleanup to continue since Gatekeeper may not be installed
} else if errors.As(err, &errGroupDiscoveryFailed) {
} else if errors.As(err, &errResourceDiscoveryFailed) {
reqLogger.Info("The ConstraintTemplate CRD is not installed")
r.setCreatedGkConstraint(false)
} else {
Expand Down Expand Up @@ -1068,7 +1069,7 @@ func (r *PolicyReconciler) cleanUpExcessTemplates(
})
}
}
} else if errors.As(err, &errGroupDiscoveryFailed) {
} else if errors.As(err, &errResourceDiscoveryFailed) {
crdsv1beta1 := extensionsv1beta1.CustomResourceDefinitionList{}
err := r.List(ctx, &crdsv1beta1, &crdQuery)
if err != nil {
Expand Down Expand Up @@ -1477,7 +1478,7 @@ func (r *PolicyReconciler) hasPolicyTemplateLabel(
err := r.Get(ctx, crdName, &crd)
if err == nil {
return crd.GetLabels()[utils.PolicyTypeLabel] == "template", nil
} else if errors.As(err, &errGroupDiscoveryFailed) {
} else if errors.As(err, &errResourceDiscoveryFailed) {
betaCrd := extensionsv1beta1.CustomResourceDefinition{}

err = r.Get(ctx, crdName, &betaCrd)
Expand Down