From d3649bc1db0882bd91d7eb63dc6d4648fa188342 Mon Sep 17 00:00:00 2001 From: Alex Zielenski Date: Thu, 21 Mar 2024 12:26:51 +0100 Subject: [PATCH] fix test flake caused by not waiting for CRD schema update Kubernetes-commit: 0add741012c31f96763d1222b828f07ef3916a3c --- test/integration/ratcheting_test.go | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/test/integration/ratcheting_test.go b/test/integration/ratcheting_test.go index 01a108add..621f94954 100644 --- a/test/integration/ratcheting_test.go +++ b/test/integration/ratcheting_test.go @@ -220,23 +220,12 @@ func (u updateMyCRDV1Beta1Schema) Do(ctx *ratchetingTestContext) error { } uuidString := string(uuid.NewUUID()) - // UUID string is just hex separated by dashes, which is safe to - // throw into regex like this - pattern := "^" + uuidString + "$" sentinelName := "__ratcheting_sentinel_field__" sch.Properties[sentinelName] = apiextensionsv1.JSONSchemaProps{ - Type: "string", - Pattern: pattern, - - // Put MaxLength condition inside AllOf since the string_validator - // in kube-openapi short circuits upon seeing MaxLength, and we - // want both pattern and MaxLength errors - AllOf: []apiextensionsv1.JSONSchemaProps{ - { - MinLength: ptr((int64(1))), // 1 MinLength to prevent empty value from ever being admitted - MaxLength: ptr((int64(0))), // 0 MaxLength to prevent non-empty value from ever being admitted - }, - }, + Type: "string", + Enum: []apiextensionsv1.JSON{{ + Raw: []byte(`"` + uuidString + `"`), + }}, } for _, v := range myCRD.Spec.Versions { @@ -254,7 +243,7 @@ func (u updateMyCRDV1Beta1Schema) Do(ctx *ratchetingTestContext) error { } // Keep trying to create an invalid instance of the CRD until we - // get an error containing the ResourceVersion we are looking for + // get an error containing the message we are looking for // counter := 0 return wait.PollUntilContextCancel(context.TODO(), 100*time.Millisecond, true, func(_ context.Context) (done bool, err error) { @@ -263,8 +252,7 @@ func (u updateMyCRDV1Beta1Schema) Do(ctx *ratchetingTestContext) error { gvr: myCRDV1Beta1, name: "sentinel-resource", patch: map[string]interface{}{ - // Just keep using different values - sentinelName: fmt.Sprintf("invalid %v %v", uuidString, counter), + sentinelName: fmt.Sprintf("invalid-%d", counter), }}.Do(ctx) if err == nil {