mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 10:43:56 +00:00
fix integration tests
This commit is contained in:
parent
4c995d8fc8
commit
d141efc3b0
@ -27,6 +27,7 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/apimachinery/pkg/util/yaml"
|
"k8s.io/apimachinery/pkg/util/yaml"
|
||||||
|
|
||||||
@ -780,21 +781,25 @@ spec:
|
|||||||
if v := "spec.versions[0].schema.openAPIV3Schema.properties[a].type: Required value: must not be empty for specified object fields"; !strings.Contains(cond.Message, v) {
|
if v := "spec.versions[0].schema.openAPIV3Schema.properties[a].type: Required value: must not be empty for specified object fields"; !strings.Contains(cond.Message, v) {
|
||||||
t.Fatalf("expected violation %q, but got: %v", v, cond.Message)
|
t.Fatalf("expected violation %q, but got: %v", v, cond.Message)
|
||||||
}
|
}
|
||||||
|
if v := "spec.preserveUnknownFields: Invalid value: true: must be false"; !strings.Contains(cond.Message, v) {
|
||||||
|
t.Fatalf("expected violation %q, but got: %v", v, cond.Message)
|
||||||
|
}
|
||||||
|
|
||||||
// remove schema
|
// remove schema
|
||||||
t.Log("Remove schema")
|
t.Log("Remove schema")
|
||||||
for retry := 0; retry < 5; retry++ {
|
for retry := 0; retry < 5; retry++ {
|
||||||
crd, err = apiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Get(context.TODO(), name, metav1.GetOptions{})
|
// This patch fixes two fields to resolve
|
||||||
if err != nil {
|
// 1. property type validation error
|
||||||
t.Fatalf("unexpected get error: %v", err)
|
// 2. preserveUnknownFields validation error
|
||||||
}
|
patch := []byte("[{\"op\":\"add\",\"path\":\"/spec/validation/openAPIV3Schema/properties/a/type\",\"value\":\"int\"}," +
|
||||||
crd.Spec.Validation = nil
|
"{\"op\":\"replace\",\"path\":\"/spec/preserveUnknownFields\",\"value\":false}]")
|
||||||
if _, err = apiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Update(context.TODO(), crd, metav1.UpdateOptions{}); apierrors.IsConflict(err) {
|
if _, err = apiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Patch(context.TODO(), name, types.JSONPatchType, patch, metav1.PatchOptions{}); apierrors.IsConflict(err) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected update error: %v", err)
|
t.Fatalf("unexpected update error: %v", err)
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected update error: %v", err)
|
t.Fatalf("unexpected update error: %v", err)
|
||||||
@ -821,6 +826,7 @@ spec:
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected get error: %v", err)
|
t.Fatalf("unexpected get error: %v", err)
|
||||||
}
|
}
|
||||||
|
crd.Spec.PreserveUnknownFields = nil
|
||||||
crd.Spec.Validation = &apiextensionsv1beta1.CustomResourceValidation{OpenAPIV3Schema: origSchema}
|
crd.Spec.Validation = &apiextensionsv1beta1.CustomResourceValidation{OpenAPIV3Schema: origSchema}
|
||||||
if _, err = apiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Update(context.TODO(), crd, metav1.UpdateOptions{}); apierrors.IsConflict(err) {
|
if _, err = apiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Update(context.TODO(), crd, metav1.UpdateOptions{}); apierrors.IsConflict(err) {
|
||||||
continue
|
continue
|
||||||
@ -828,6 +834,7 @@ spec:
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected update error: %v", err)
|
t.Fatalf("unexpected update error: %v", err)
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected update error: %v", err)
|
t.Fatalf("unexpected update error: %v", err)
|
||||||
@ -849,6 +856,9 @@ spec:
|
|||||||
if v := "spec.versions[0].schema.openAPIV3Schema.properties[a].type: Required value: must not be empty for specified object fields"; !strings.Contains(cond.Message, v) {
|
if v := "spec.versions[0].schema.openAPIV3Schema.properties[a].type: Required value: must not be empty for specified object fields"; !strings.Contains(cond.Message, v) {
|
||||||
t.Fatalf("expected violation %q, but got: %v", v, cond.Message)
|
t.Fatalf("expected violation %q, but got: %v", v, cond.Message)
|
||||||
}
|
}
|
||||||
|
if v := "spec.preserveUnknownFields: Invalid value: true: must be false"; !strings.Contains(cond.Message, v) {
|
||||||
|
t.Fatalf("expected violation %q, but got: %v", v, cond.Message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNonStructuralSchemaCondition(t *testing.T) {
|
func TestNonStructuralSchemaCondition(t *testing.T) {
|
||||||
@ -862,6 +872,7 @@ func TestNonStructuralSchemaCondition(t *testing.T) {
|
|||||||
apiVersion: apiextensions.k8s.io/v1beta1
|
apiVersion: apiextensions.k8s.io/v1beta1
|
||||||
kind: CustomResourceDefinition
|
kind: CustomResourceDefinition
|
||||||
spec:
|
spec:
|
||||||
|
preserveUnknownFields: PRESERVE_UNKNOWN_FIELDS
|
||||||
version: v1beta1
|
version: v1beta1
|
||||||
names:
|
names:
|
||||||
plural: foos
|
plural: foos
|
||||||
@ -882,6 +893,7 @@ spec:
|
|||||||
|
|
||||||
type Test struct {
|
type Test struct {
|
||||||
desc string
|
desc string
|
||||||
|
preserveUnknownFields string
|
||||||
globalSchema, v1Schema, v1beta1Schema string
|
globalSchema, v1Schema, v1beta1Schema string
|
||||||
expectedCreateErrors []string
|
expectedCreateErrors []string
|
||||||
unexpectedCreateErrors []string
|
unexpectedCreateErrors []string
|
||||||
@ -889,7 +901,19 @@ spec:
|
|||||||
unexpectedViolations []string
|
unexpectedViolations []string
|
||||||
}
|
}
|
||||||
tests := []Test{
|
tests := []Test{
|
||||||
{"empty", "", "", "", nil, nil, nil, nil},
|
{
|
||||||
|
desc: "empty",
|
||||||
|
expectedViolations: []string{
|
||||||
|
"spec.preserveUnknownFields: Invalid value: true: must be false",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "preserve unknown fields is false",
|
||||||
|
preserveUnknownFields: "false",
|
||||||
|
globalSchema: `
|
||||||
|
type: object
|
||||||
|
`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "int-or-string and preserve-unknown-fields true",
|
desc: "int-or-string and preserve-unknown-fields true",
|
||||||
globalSchema: `
|
globalSchema: `
|
||||||
@ -922,7 +946,8 @@ x-kubernetes-embedded-resource: true
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "embedded-resource without preserve-unknown-fields, but properties",
|
desc: "embedded-resource without preserve-unknown-fields, but properties",
|
||||||
|
preserveUnknownFields: "false",
|
||||||
globalSchema: `
|
globalSchema: `
|
||||||
type: object
|
type: object
|
||||||
x-kubernetes-embedded-resource: true
|
x-kubernetes-embedded-resource: true
|
||||||
@ -934,16 +959,15 @@ properties:
|
|||||||
metadata:
|
metadata:
|
||||||
type: object
|
type: object
|
||||||
`,
|
`,
|
||||||
expectedViolations: []string{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "embedded-resource with preserve-unknown-fields",
|
desc: "embedded-resource with preserve-unknown-fields",
|
||||||
|
preserveUnknownFields: "false",
|
||||||
globalSchema: `
|
globalSchema: `
|
||||||
type: object
|
type: object
|
||||||
x-kubernetes-embedded-resource: true
|
x-kubernetes-embedded-resource: true
|
||||||
x-kubernetes-preserve-unknown-fields: true
|
x-kubernetes-preserve-unknown-fields: true
|
||||||
`,
|
`,
|
||||||
expectedViolations: []string{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "embedded-resource with wrong type",
|
desc: "embedded-resource with wrong type",
|
||||||
@ -1330,7 +1354,8 @@ oneOf:
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "structural complete",
|
desc: "structural complete",
|
||||||
|
preserveUnknownFields: "false",
|
||||||
globalSchema: `
|
globalSchema: `
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
@ -1391,7 +1416,6 @@ oneOf:
|
|||||||
- properties:
|
- properties:
|
||||||
g: {}
|
g: {}
|
||||||
`,
|
`,
|
||||||
expectedViolations: nil,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "invalid v1beta1 schema",
|
desc: "invalid v1beta1 schema",
|
||||||
@ -1472,7 +1496,8 @@ properties:
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "metadata with name property",
|
desc: "metadata with name property",
|
||||||
|
preserveUnknownFields: "false",
|
||||||
globalSchema: `
|
globalSchema: `
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
@ -1483,10 +1508,10 @@ properties:
|
|||||||
type: string
|
type: string
|
||||||
pattern: "^[a-z]+$"
|
pattern: "^[a-z]+$"
|
||||||
`,
|
`,
|
||||||
expectedViolations: []string{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "metadata with generateName property",
|
desc: "metadata with generateName property",
|
||||||
|
preserveUnknownFields: "false",
|
||||||
globalSchema: `
|
globalSchema: `
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
@ -1497,10 +1522,10 @@ properties:
|
|||||||
type: string
|
type: string
|
||||||
pattern: "^[a-z]+$"
|
pattern: "^[a-z]+$"
|
||||||
`,
|
`,
|
||||||
expectedViolations: []string{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "metadata with name and generateName property",
|
desc: "metadata with name and generateName property",
|
||||||
|
preserveUnknownFields: "false",
|
||||||
globalSchema: `
|
globalSchema: `
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
@ -1514,7 +1539,6 @@ properties:
|
|||||||
type: string
|
type: string
|
||||||
pattern: "^[a-z]+$"
|
pattern: "^[a-z]+$"
|
||||||
`,
|
`,
|
||||||
expectedViolations: []string{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "metadata under junctors",
|
desc: "metadata under junctors",
|
||||||
@ -1597,6 +1621,7 @@ properties:
|
|||||||
"GLOBAL_SCHEMA", toValidationJSON(tst.globalSchema),
|
"GLOBAL_SCHEMA", toValidationJSON(tst.globalSchema),
|
||||||
"V1BETA1_SCHEMA", toValidationJSON(tst.v1beta1Schema),
|
"V1BETA1_SCHEMA", toValidationJSON(tst.v1beta1Schema),
|
||||||
"V1_SCHEMA", toValidationJSON(tst.v1Schema),
|
"V1_SCHEMA", toValidationJSON(tst.v1Schema),
|
||||||
|
"PRESERVE_UNKNOWN_FIELDS", tst.preserveUnknownFields,
|
||||||
).Replace(tmpl)
|
).Replace(tmpl)
|
||||||
|
|
||||||
// decode CRD manifest
|
// decode CRD manifest
|
||||||
|
Loading…
Reference in New Issue
Block a user