Skip to content

Commit c517b47

Browse files
fix: ensureCRDReady check did not work for v1 CRDs (argoproj#378)
Signed-off-by: Yuan Tang <[email protected]>
1 parent e360551 commit c517b47

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

pkg/sync/sync_context.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
"github.com/go-logr/logr"
1414
v1 "k8s.io/api/core/v1"
15-
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
15+
v1extensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1616
"k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
1717
apierr "k8s.io/apimachinery/pkg/api/errors"
1818
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -831,16 +831,16 @@ func (sc *syncContext) setOperationPhase(phase common.OperationPhase, message st
831831
sc.message = message
832832
}
833833

834-
// ensureCRDReady waits until specified CRD is ready (established condition is true). Method is best effort - it does not fail even if CRD is not ready without timeout.
835-
func (sc *syncContext) ensureCRDReady(name string) {
836-
_ = wait.PollImmediate(time.Duration(100)*time.Millisecond, crdReadinessTimeout, func() (bool, error) {
837-
crd, err := sc.extensionsclientset.ApiextensionsV1beta1().CustomResourceDefinitions().Get(context.TODO(), name, metav1.GetOptions{})
834+
// ensureCRDReady waits until specified CRD is ready (established condition is true).
835+
func (sc *syncContext) ensureCRDReady(name string) error {
836+
return wait.PollImmediate(time.Duration(100)*time.Millisecond, crdReadinessTimeout, func() (bool, error) {
837+
crd, err := sc.extensionsclientset.ApiextensionsV1().CustomResourceDefinitions().Get(context.TODO(), name, metav1.GetOptions{})
838838
if err != nil {
839839
return false, err
840840
}
841841
for _, condition := range crd.Status.Conditions {
842-
if condition.Type == v1beta1.Established {
843-
return condition.Status == v1beta1.ConditionTrue, nil
842+
if condition.Type == v1extensions.Established {
843+
return condition.Status == v1extensions.ConditionTrue, nil
844844
}
845845
}
846846
return false, nil
@@ -881,7 +881,10 @@ func (sc *syncContext) applyObject(t *syncTask, dryRun bool, force bool, validat
881881
return common.ResultCodeSyncFailed, err.Error()
882882
}
883883
if kube.IsCRD(t.targetObj) && !dryRun {
884-
sc.ensureCRDReady(t.targetObj.GetName())
884+
crdName := t.targetObj.GetName()
885+
if err = sc.ensureCRDReady(crdName); err != nil {
886+
sc.log.Error(err, fmt.Sprintf("failed to ensure that CRD %s is ready", crdName))
887+
}
885888
}
886889
return common.ResultCodeSynced, message
887890
}

0 commit comments

Comments
 (0)