diff --git a/hack/testdata/CRD/example-crd-1-cluster-scoped-resource.yaml b/hack/testdata/CRD/example-crd-1-cluster-scoped-resource.yaml new file mode 100644 index 00000000000..21fa5bfd10a --- /dev/null +++ b/hack/testdata/CRD/example-crd-1-cluster-scoped-resource.yaml @@ -0,0 +1,6 @@ +apiVersion: test.com/v1 +kind: Example +metadata: + name: test +spec: + test: test diff --git a/hack/testdata/CRD/example-crd-1-cluster-scoped.yaml b/hack/testdata/CRD/example-crd-1-cluster-scoped.yaml new file mode 100644 index 00000000000..3774d84878f --- /dev/null +++ b/hack/testdata/CRD/example-crd-1-cluster-scoped.yaml @@ -0,0 +1,24 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: examples.test.com +spec: + group: test.com + scope: Cluster + versions: + - name: v1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + properties: + spec: + type: object + properties: + test: + type: string + names: + plural: examples + singular: example + kind: Example diff --git a/hack/testdata/CRD/example-crd-1-namespaced-resource.yaml b/hack/testdata/CRD/example-crd-1-namespaced-resource.yaml new file mode 100644 index 00000000000..ba1f268b61a --- /dev/null +++ b/hack/testdata/CRD/example-crd-1-namespaced-resource.yaml @@ -0,0 +1,7 @@ +apiVersion: test.com/v1 +kind: Example +metadata: + name: test + namespace: default +spec: + test: test diff --git a/hack/testdata/CRD/example-crd-1-namespaced.yaml b/hack/testdata/CRD/example-crd-1-namespaced.yaml new file mode 100644 index 00000000000..42128ff9151 --- /dev/null +++ b/hack/testdata/CRD/example-crd-1-namespaced.yaml @@ -0,0 +1,24 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: examples.test.com +spec: + group: test.com + scope: Namespaced + versions: + - name: v1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + properties: + spec: + type: object + properties: + test: + type: string + names: + plural: examples + singular: example + kind: Example diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/delete/delete.go b/staging/src/k8s.io/kubectl/pkg/cmd/delete/delete.go index 4f9d806247f..cd3df4280b2 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/delete/delete.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/delete/delete.go @@ -69,7 +69,11 @@ var ( Note that the delete command does NOT do resource version checks, so if someone submits an update to a resource right when you submit a delete, their update will be lost along with the - rest of the resource.`)) + rest of the resource. + + After a CustomResourceDefinition is deleted, invalidation of discovery cache may take up + to 10 minutes. If you don't want to wait, you might want to run "kubectl api-resources" + to refresh the discovery cache.`)) deleteExample = templates.Examples(i18n.T(` # Delete a pod using the type and name specified in pod.json diff --git a/test/cmd/discovery.sh b/test/cmd/discovery.sh index 0a8e0ba8972..fdfd3c8a84d 100755 --- a/test/cmd/discovery.sh +++ b/test/cmd/discovery.sh @@ -96,6 +96,36 @@ run_resource_aliasing_tests() { set +o errexit } +run_crd_deletion_recreation_tests() { + set -o nounset + set -o errexit + + create_and_use_new_namespace + kube::log::status "Testing resource creation, deletion, and re-creation" + + output_message=$(kubectl apply -f hack/testdata/CRD/example-crd-1-cluster-scoped.yaml) + kube::test::if_has_string "${output_message}" 'created' + output_message=$(kubectl apply -f hack/testdata/CRD/example-crd-1-cluster-scoped-resource.yaml) + kube::test::if_has_string "${output_message}" 'created' + output_message=$(kubectl delete -f hack/testdata/CRD/example-crd-1-cluster-scoped.yaml) + kube::test::if_has_string "${output_message}" 'deleted' + # Invalidate local cache because cluster scoped CRD in cache is stale. + # Invalidation of cache may take up to 10 minutes and we are manually + # invalidate cache and expect that scope changed CRD should be created without problem. + kubectl api-resources + output_message=$(kubectl apply -f hack/testdata/CRD/example-crd-1-namespaced.yaml) + kube::test::if_has_string "${output_message}" 'created' + output_message=$(kubectl apply -f hack/testdata/CRD/example-crd-1-namespaced-resource.yaml) + kube::test::if_has_string "${output_message}" 'created' + + # Cleanup + kubectl delete -f hack/testdata/CRD/example-crd-1-namespaced-resource.yaml + kubectl delete -f hack/testdata/CRD/example-crd-1-namespaced.yaml + + set +o nounset + set +o errexit +} + run_kubectl_explain_tests() { set -o nounset set -o errexit diff --git a/test/cmd/legacy-script.sh b/test/cmd/legacy-script.sh index 6ce6d67edf0..860c97e9cd3 100755 --- a/test/cmd/legacy-script.sh +++ b/test/cmd/legacy-script.sh @@ -892,6 +892,13 @@ runTests() { record_command run_kubectl_explain_tests fi + ############################## + # CRD Deletion / Re-creation # + ############################## + + if kube::test::if_supports_resource "${namespaces}" ; then + record_command run_crd_deletion_recreation_tests + fi ########### # Swagger #