mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-07 12:11:43 +00:00
Merge pull request #33250 from ymqytw/edit_before_create
Automatic merge from submit-queue support editing before creating resource Support `kubectl create -f config.yaml --edit` Support editing before creating resource from files, urls and stdin. The behavior is similar to `kubectl edit` It won't create anything when edit make no change. partial: #18064 Based on: #33686 and #33973 ```release-note Support editing before creating resource from files, urls and stdin, e.g. `kubectl create -f config.yaml --edit` It won't create anything when edit make no change. ```
This commit is contained in:
@@ -720,6 +720,25 @@ runTests() {
|
||||
# Pre-condition: no POD exists
|
||||
create_and_use_new_namespace
|
||||
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
|
||||
## kubectl create --edit can update the image field of a POD. tmp-editor.sh is a fake editor
|
||||
TEMP=$(mktemp /tmp/tmp-editor-XXXXXXXX.sh)
|
||||
echo -e "#!/bin/bash\n$SED -i \"s/gcr.io\/google_containers\/serve_hostname/nginx/g\" \$1" > ${TEMP}
|
||||
chmod +x ${TEMP}
|
||||
# Command
|
||||
EDITOR=${TEMP} kubectl create --edit -f test/fixtures/doc-yaml/admin/limitrange/valid-pod.yaml "${kube_flags[@]}"
|
||||
# Post-condition: valid-pod POD is created and has image gcr.io/google_containers/serve_hostname
|
||||
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" 'valid-pod:'
|
||||
kube::test::get_object_assert pods "{{range.items}}{{$image_field}}:{{end}}" 'nginx:'
|
||||
# Clean up
|
||||
rm ${TEMP}
|
||||
kubectl delete pods/valid-pod "${kube_flags[@]}"
|
||||
|
||||
## kubectl create --edit won't create anything if user makes no changes
|
||||
[ "$(EDITOR=cat kubectl create --edit -f test/fixtures/doc-yaml/admin/limitrange/valid-pod.yaml -o json 2>&1 | grep 'Edit cancelled')" ]
|
||||
|
||||
## Create valid-pod POD
|
||||
# Pre-condition: no POD exists
|
||||
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
|
||||
# Command
|
||||
kubectl create -f test/fixtures/doc-yaml/admin/limitrange/valid-pod.yaml "${kube_flags[@]}"
|
||||
# Post-condition: valid-pod POD is created
|
||||
|
Reference in New Issue
Block a user