Skip to content

Commit 2d9f46f

Browse files
committed
Make CRD conversion e2e tests robust in non-aggregator-routing clusters
1 parent 21a2951 commit 2d9f46f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/e2e/apimachinery/crd_conversion_webhook.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3131
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3232
"k8s.io/apimachinery/pkg/util/intstr"
33+
"k8s.io/apimachinery/pkg/util/wait"
3334
"k8s.io/client-go/dynamic"
3435
clientset "k8s.io/client-go/kubernetes"
3536
"k8s.io/kubernetes/test/e2e/framework"
@@ -167,6 +168,7 @@ var _ = SIGDescribe("CustomResourceConversionWebhook [Privileged:ClusterAdmin]",
167168
return
168169
}
169170
defer testcrd.CleanUp()
171+
waitWebhookConversionReady(f, testcrd.Crd, testcrd.DynamicClients, "v2")
170172
testCustomResourceConversionWebhook(f, testcrd.Crd, testcrd.DynamicClients)
171173
})
172174

@@ -201,6 +203,7 @@ var _ = SIGDescribe("CustomResourceConversionWebhook [Privileged:ClusterAdmin]",
201203
return
202204
}
203205
defer testcrd.CleanUp()
206+
waitWebhookConversionReady(f, testcrd.Crd, testcrd.DynamicClients, "v2")
204207
testCRListConversion(f, testcrd)
205208
})
206209
})
@@ -485,3 +488,29 @@ func testCRListConversion(f *framework.Framework, testCrd *crd.TestCrd) {
485488
verifyV2Object(f, crd, &list.Items[0])
486489
verifyV2Object(f, crd, &list.Items[1])
487490
}
491+
492+
// waitWebhookConversionReady sends stub custom resource creation requests requiring conversion until one succeeds.
493+
func waitWebhookConversionReady(f *framework.Framework, crd *apiextensionsv1.CustomResourceDefinition, customResourceClients map[string]dynamic.ResourceInterface, version string) {
494+
framework.ExpectNoError(wait.PollImmediate(100*time.Millisecond, 30*time.Second, func() (bool, error) {
495+
crInstance := &unstructured.Unstructured{
496+
Object: map[string]interface{}{
497+
"kind": crd.Spec.Names.Kind,
498+
"apiVersion": crd.Spec.Group + "/" + version,
499+
"metadata": map[string]interface{}{
500+
"name": f.UniqueName,
501+
"namespace": f.Namespace.Name,
502+
},
503+
},
504+
}
505+
_, err := customResourceClients[version].Create(crInstance, metav1.CreateOptions{})
506+
if err != nil {
507+
// tolerate clusters that do not set --enable-aggregator-routing and have to wait for kube-proxy
508+
// to program the service network, during which conversion requests return errors
509+
e2elog.Logf("error waiting for conversion to succeed during setup: %v", err)
510+
return false, nil
511+
}
512+
513+
framework.ExpectNoError(customResourceClients[version].Delete(crInstance.GetName(), nil), "cleaning up stub object")
514+
return true, nil
515+
}))
516+
}

0 commit comments

Comments
 (0)