Skip to content

Commit ed65625

Browse files
JustinKuliopenshift-merge-robot
authored andcommitted
Check v1beta1 CRD for policy template label
On older versions of k8s where the v1 version of CRDs is not available, this method was preventing the controller from working. Refs: - https://issues.redhat.com/browse/ACM-5326 Signed-off-by: Justin Kulikauskas <[email protected]>
1 parent b372971 commit ed65625

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

controllers/templatesync/template_sync.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,16 +1397,23 @@ func (r *PolicyReconciler) hasPolicyTemplateLabel(
13971397
}
13981398

13991399
err := r.Get(ctx, crdName, &crd)
1400-
if err != nil {
1401-
// If it wasn't found, then it wasn't in the cache and doesn't have the label
1402-
if k8serrors.IsNotFound(err) {
1403-
return false, nil
1400+
if err == nil {
1401+
return crd.GetLabels()[utils.PolicyTypeLabel] == "template", nil
1402+
} else if meta.IsNoMatchError(err) {
1403+
betaCrd := extensionsv1beta1.CustomResourceDefinition{}
1404+
1405+
err = r.Get(ctx, crdName, &betaCrd)
1406+
if err == nil {
1407+
return betaCrd.GetLabels()[utils.PolicyTypeLabel] == "template", nil
14041408
}
1409+
}
14051410

1406-
return false, err
1411+
// If it wasn't found, then it wasn't in the cache and doesn't have the label
1412+
if k8serrors.IsNotFound(err) {
1413+
return false, nil
14071414
}
14081415

1409-
return crd.GetLabels()[utils.PolicyTypeLabel] == "template", nil
1416+
return false, err
14101417
}
14111418

14121419
// hasClusterwideFinalizer returns a boolean for whether a policy has a clusterwide finalizer,

0 commit comments

Comments
 (0)