Skip to content

Commit d3649bc

Browse files
Alex Zielenskik8s-publishing-bot
authored andcommitted
fix test flake caused by not waiting for CRD schema update
Kubernetes-commit: 0add741012c31f96763d1222b828f07ef3916a3c
1 parent 9624e52 commit d3649bc

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

test/integration/ratcheting_test.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -220,23 +220,12 @@ func (u updateMyCRDV1Beta1Schema) Do(ctx *ratchetingTestContext) error {
220220
}
221221

222222
uuidString := string(uuid.NewUUID())
223-
// UUID string is just hex separated by dashes, which is safe to
224-
// throw into regex like this
225-
pattern := "^" + uuidString + "$"
226223
sentinelName := "__ratcheting_sentinel_field__"
227224
sch.Properties[sentinelName] = apiextensionsv1.JSONSchemaProps{
228-
Type: "string",
229-
Pattern: pattern,
230-
231-
// Put MaxLength condition inside AllOf since the string_validator
232-
// in kube-openapi short circuits upon seeing MaxLength, and we
233-
// want both pattern and MaxLength errors
234-
AllOf: []apiextensionsv1.JSONSchemaProps{
235-
{
236-
MinLength: ptr((int64(1))), // 1 MinLength to prevent empty value from ever being admitted
237-
MaxLength: ptr((int64(0))), // 0 MaxLength to prevent non-empty value from ever being admitted
238-
},
239-
},
225+
Type: "string",
226+
Enum: []apiextensionsv1.JSON{{
227+
Raw: []byte(`"` + uuidString + `"`),
228+
}},
240229
}
241230

242231
for _, v := range myCRD.Spec.Versions {
@@ -254,7 +243,7 @@ func (u updateMyCRDV1Beta1Schema) Do(ctx *ratchetingTestContext) error {
254243
}
255244

256245
// Keep trying to create an invalid instance of the CRD until we
257-
// get an error containing the ResourceVersion we are looking for
246+
// get an error containing the message we are looking for
258247
//
259248
counter := 0
260249
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 {
263252
gvr: myCRDV1Beta1,
264253
name: "sentinel-resource",
265254
patch: map[string]interface{}{
266-
// Just keep using different values
267-
sentinelName: fmt.Sprintf("invalid %v %v", uuidString, counter),
255+
sentinelName: fmt.Sprintf("invalid-%d", counter),
268256
}}.Do(ctx)
269257

270258
if err == nil {

0 commit comments

Comments
 (0)