Merge pull request #53609 from juanvallejo/jvallejo/set-user-specified-ns-dry-run-create

Automatic merge from submit-queue. 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>.

add user-specified  ns to --dry-run created obj

Fixes https://github.com/kubernetes/kubernetes/issues/51068

**Release note**:
```release-note
NONE
```

Includes a namespace in a created resource's metadata when `--dry-run` is used if:
- a namespace was explicitly set by the user (via `--namespace`)
- No errors occur accessing the object's metadata

cc @fabianofranz @deads2k
This commit is contained in:
Kubernetes Submit Queue
2017-10-19 00:24:42 -07:00
committed by GitHub
2 changed files with 41 additions and 1 deletions

View File

@@ -915,6 +915,32 @@ __EOF__
set +o errexit
}
# runs specific kubectl create tests
run_create_tests() {
set -o nounset
set -o errexit
### Create generic secret with explicit namespace
# Pre-condition: secret 'mysecret' does not exist
output_message=$(! kubectl get secrets mysecret 2>&1 "${kube_flags[@]}")
kube::test::if_has_string "${output_message}" 'secrets "mysecret" not found'
# Command
output_message=$(kubectl create "${kube_flags[@]}" secret generic mysecret --dry-run --from-literal=foo=bar -o jsonpath='{.metadata.namespace}' --namespace=user-specified)
# Post-condition: mysecret still not created since --dry-run was used
# Output from 'create' command should contain the specified --namespace value
failure_message=$(! kubectl get secrets mysecret 2>&1 "${kube_flags[@]}")
kube::test::if_has_string "${failure_message}" 'secrets "mysecret" not found'
kube::test::if_has_string "${output_message}" 'user-specified'
# Command
output_message=$(kubectl create "${kube_flags[@]}" secret generic mysecret --dry-run --from-literal=foo=bar -o jsonpath='{.metadata.namespace}')
# Post-condition: jsonpath for .metadata.namespace should be empty for object since --namespace was not explicitly specified
kube::test::if_empty_string "${output_message}"
set +o nounset
set +o errexit
}
# Runs tests related to kubectl apply.
run_kubectl_apply_tests() {
set -o nounset
@@ -4568,6 +4594,14 @@ runTests() {
record_command run_kubectl_get_tests
fi
######################
# Create #
######################
if kube::test::if_supports_resource "${secrets}" ; then
record_command run_create_tests
fi
##################
# Global timeout #
##################