mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 02:09:56 +00:00
fix test flake caused by not waiting for CRD schema update
This commit is contained in:
parent
a309fadbac
commit
0add741012
@ -220,23 +220,12 @@ func (u updateMyCRDV1Beta1Schema) Do(ctx *ratchetingTestContext) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uuidString := string(uuid.NewUUID())
|
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__"
|
sentinelName := "__ratcheting_sentinel_field__"
|
||||||
sch.Properties[sentinelName] = apiextensionsv1.JSONSchemaProps{
|
sch.Properties[sentinelName] = apiextensionsv1.JSONSchemaProps{
|
||||||
Type: "string",
|
Type: "string",
|
||||||
Pattern: pattern,
|
Enum: []apiextensionsv1.JSON{{
|
||||||
|
Raw: []byte(`"` + uuidString + `"`),
|
||||||
// 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
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range myCRD.Spec.Versions {
|
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
|
// 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
|
counter := 0
|
||||||
return wait.PollUntilContextCancel(context.TODO(), 100*time.Millisecond, true, func(_ context.Context) (done bool, err error) {
|
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,
|
gvr: myCRDV1Beta1,
|
||||||
name: "sentinel-resource",
|
name: "sentinel-resource",
|
||||||
patch: map[string]interface{}{
|
patch: map[string]interface{}{
|
||||||
// Just keep using different values
|
sentinelName: fmt.Sprintf("invalid-%d", counter),
|
||||||
sentinelName: fmt.Sprintf("invalid %v %v", uuidString, counter),
|
|
||||||
}}.Do(ctx)
|
}}.Do(ctx)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user