mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-06 19:52:42 +00:00
Merge pull request #26722 from deads2k/local-patch
Automatic merge from submit-queue let patch use --local flag like `kubectl set image` Adds the concept of a `--local` flag to `kubectl patch`. This flag is similar to `kubectl set image -f --local` because it will use the content of the file as the input to the patch operation instead of using the file content to file resource/name tuples. This pull lets you run something like `kubectl create deployment --dry-run -o yaml | kubectl set volume --local -f - -o yaml | kubectl patch --local -f - --patch {} | kubectl create -f -` As proof that it works, you can run against a local file just to mess around with it, but `--local -f -` is the most likely case. ``` $kubectl patch --local -f pkg/api/validation/testdata/v1/validPod.yaml --patch='{"spec": {"restartPolicy":"Never"}}' apiVersion: v1 kind: Pod metadata: creationTimestamp: null labels: name: redis-master name: name spec: containers: - args: - this - is - an - ok - command image: gcr.io/fake_project/fake_image:fake_tag name: master resources: {} restartPolicy: Never status: {} ``` This is useful for setting rarely used, but immutable fields from `kubectl create` or `kubectl convert` without dropping to an interactive editor. Some discussion here: https://github.com/kubernetes/kubernetes/issues/21648#issuecomment-218579977 @smarterclayton @kubernetes/kubectl @eparis @soltysh @stevekuznetsov we've talked about this separately
This commit is contained in:
@@ -635,6 +635,9 @@ runTests() {
|
||||
# Post-condition: valid-pod POD is created
|
||||
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" 'valid-pod:'
|
||||
|
||||
## Patch can modify a local object
|
||||
kubectl patch --local -f pkg/api/validation/testdata/v1/validPod.yaml --patch='{"spec": {"restartPolicy":"Never"}}' -o jsonpath='{.spec.restartPolicy}' | grep -q "Never"
|
||||
|
||||
## Patch pod can change image
|
||||
# Command
|
||||
kubectl patch "${kube_flags[@]}" pod valid-pod --record -p='{"spec":{"containers":[{"name": "kubernetes-serve-hostname", "image": "nginx"}]}}'
|
||||
|
Reference in New Issue
Block a user