mirror of https://github.com/k3s-io/k3s
Merge pull request #66602 from dixudx/kubectl_apply_force_invalid
Automatic merge from submit-queue (batch tested with PRs 66602, 67178, 67207, 67125, 66332). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. kubectl: recreating resources for immutable fields when force is applied **What this PR does / why we need it**: **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #66390 **Special notes for your reviewer**: /assign soltysh juanvallejo /cc @kubernetes/sig-cli-bugs **Release note**: ```release-note kubectl: recreating resources for immutable fields when force is applied ```pull/8/head
commit
0e62573d60
|
@ -0,0 +1,10 @@
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: a
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: test
|
||||||
|
clusterIP: None
|
||||||
|
ports:
|
||||||
|
- port: 80
|
|
@ -0,0 +1,10 @@
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: a
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: test
|
||||||
|
clusterIP: 10.0.0.12
|
||||||
|
ports:
|
||||||
|
- port: 80
|
|
@ -753,7 +753,7 @@ func (p *patcher) patch(current runtime.Object, modified []byte, source, namespa
|
||||||
}
|
}
|
||||||
patchBytes, patchObject, err = p.patchSimple(current, modified, source, namespace, name, errOut)
|
patchBytes, patchObject, err = p.patchSimple(current, modified, source, namespace, name, errOut)
|
||||||
}
|
}
|
||||||
if err != nil && errors.IsConflict(err) && p.force {
|
if err != nil && (errors.IsConflict(err) || errors.IsInvalid(err)) && p.force {
|
||||||
patchBytes, patchObject, err = p.deleteAndCreate(current, modified, namespace, name)
|
patchBytes, patchObject, err = p.deleteAndCreate(current, modified, namespace, name)
|
||||||
}
|
}
|
||||||
return patchBytes, patchObject, err
|
return patchBytes, patchObject, err
|
||||||
|
|
|
@ -157,6 +157,25 @@ run_kubectl_apply_tests() {
|
||||||
# cleanup
|
# cleanup
|
||||||
kubectl delete svc prune-svc 2>&1 "${kube_flags[@]}"
|
kubectl delete svc prune-svc 2>&1 "${kube_flags[@]}"
|
||||||
|
|
||||||
|
|
||||||
|
## kubectl apply -f some.yml --force
|
||||||
|
# Pre-condition: no service exists
|
||||||
|
kube::test::get_object_assert services "{{range.items}}{{$id_field}}:{{end}}" ''
|
||||||
|
# apply service a
|
||||||
|
kubectl apply -f hack/testdata/service-revision1.yaml "${kube_flags[@]}"
|
||||||
|
# check right service exists
|
||||||
|
kube::test::get_object_assert 'services a' "{{${id_field}}}" 'a'
|
||||||
|
# change immutable field and apply service a
|
||||||
|
output_message=$(! kubectl apply -f hack/testdata/service-revision2.yaml 2>&1 "${kube_flags[@]}")
|
||||||
|
kube::test::if_has_string "${output_message}" 'field is immutable'
|
||||||
|
# apply --force to recreate resources for immutable fields
|
||||||
|
kubectl apply -f hack/testdata/service-revision2.yaml --force "${kube_flags[@]}"
|
||||||
|
# check immutable field exists
|
||||||
|
kube::test::get_object_assert 'services a' "{{.spec.clusterIP}}" '10.0.0.12'
|
||||||
|
# cleanup
|
||||||
|
kubectl delete -f hack/testdata/service-revision2.yaml "${kube_flags[@]}"
|
||||||
|
|
||||||
|
|
||||||
set +o nounset
|
set +o nounset
|
||||||
set +o errexit
|
set +o errexit
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue