mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 10:20:51 +00:00
Add manually invalidate cache documentation into delete
When CRDs are deleted, discovery local cache is not invalidated. This brings about `resource not found` error when new CRD with same name is created with different fields(ie. changing scope from cluster-wide to namespaced). Because this already deleted CRD still stays in serverresources.json and kubectl tries to use it. This local cached files have 10 minutes TTL. After deletion, if user waits 10 minutes, files will be expired and deleted and there will be no errors. However, 10 minutes is a long time and cache needs to be invalidated after deletion occurs. This PR adds a document into delete command by noting that there might be a need to invalidate discovery cache when CRD is deleted. In addition to that this PR adds a test to catch this behavior.
This commit is contained in:
parent
cd117abf19
commit
43d8b3459b
6
hack/testdata/CRD/example-crd-1-cluster-scoped-resource.yaml
vendored
Normal file
6
hack/testdata/CRD/example-crd-1-cluster-scoped-resource.yaml
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
apiVersion: test.com/v1
|
||||
kind: Example
|
||||
metadata:
|
||||
name: test
|
||||
spec:
|
||||
test: test
|
24
hack/testdata/CRD/example-crd-1-cluster-scoped.yaml
vendored
Normal file
24
hack/testdata/CRD/example-crd-1-cluster-scoped.yaml
vendored
Normal file
@ -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
|
7
hack/testdata/CRD/example-crd-1-namespaced-resource.yaml
vendored
Normal file
7
hack/testdata/CRD/example-crd-1-namespaced-resource.yaml
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
apiVersion: test.com/v1
|
||||
kind: Example
|
||||
metadata:
|
||||
name: test
|
||||
namespace: default
|
||||
spec:
|
||||
test: test
|
24
hack/testdata/CRD/example-crd-1-namespaced.yaml
vendored
Normal file
24
hack/testdata/CRD/example-crd-1-namespaced.yaml
vendored
Normal file
@ -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
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 #
|
||||
|
Loading…
Reference in New Issue
Block a user