Skip to content

Commit

Permalink
fix test flake caused by not waiting for CRD schema update
Browse files Browse the repository at this point in the history
Kubernetes-commit: 0add741012c31f96763d1222b828f07ef3916a3c
  • Loading branch information
Alex Zielenski authored and k8s-publishing-bot committed Mar 21, 2024
1 parent 9624e52 commit d3649bc
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions test/integration/ratcheting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down

0 comments on commit d3649bc

Please sign in to comment.