mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-06 19:52:42 +00:00
Merge pull request #29236 from juanvallejo/jvallejo_add-configuration-missing-error-type
Automatic merge from submit-queue Update client config invalid option errors to be more specific This patch adds better error handling for cases where a global option (such as --context or --cluster) causes an invalid config to be returned. ```release-note release-note-none ```
This commit is contained in:
@@ -1652,6 +1652,51 @@ __EOF__
|
||||
kubectl delete configmap test-configmap --namespace=test-configmaps
|
||||
kubectl delete namespace test-configmaps
|
||||
|
||||
####################
|
||||
# Client Config #
|
||||
####################
|
||||
|
||||
# Command
|
||||
# Pre-condition: kubeconfig "missing" is not a file or directory
|
||||
output_message=$(! kubectl get pod --context="" --kubeconfig=missing 2>&1)
|
||||
kube::test::if_has_string "${output_message}" "missing: no such file or directory"
|
||||
|
||||
# Pre-condition: kubeconfig "missing" is not a file or directory
|
||||
# Command
|
||||
output_message=$(! kubectl get pod --user="" --kubeconfig=missing 2>&1)
|
||||
# Post-condition: --user contains a valid / empty value, missing config file returns error
|
||||
kube::test::if_has_string "${output_message}" "missing: no such file or directory"
|
||||
# Command
|
||||
output_message=$(! kubectl get pod --cluster="" --kubeconfig=missing 2>&1)
|
||||
# Post-condition: --cluster contains a "valid" value, missing config file returns error
|
||||
kube::test::if_has_string "${output_message}" "missing: no such file or directory"
|
||||
|
||||
# Pre-condition: context "missing-context" does not exist
|
||||
# Command
|
||||
output_message=$(! kubectl get pod --context="missing-context" 2>&1)
|
||||
kube::test::if_has_string "${output_message}" 'context "missing-context" does not exist'
|
||||
# Post-condition: invalid or missing context returns error
|
||||
|
||||
# Pre-condition: cluster "missing-cluster" does not exist
|
||||
# Command
|
||||
output_message=$(! kubectl get pod --cluster="missing-cluster" 2>&1)
|
||||
kube::test::if_has_string "${output_message}" 'cluster "missing-cluster" does not exist'
|
||||
# Post-condition: invalid or missing cluster returns error
|
||||
|
||||
# Pre-condition: user "missing-user" does not exist
|
||||
# Command
|
||||
output_message=$(! kubectl get pod --user="missing-user" 2>&1)
|
||||
kube::test::if_has_string "${output_message}" 'auth info "missing-user" does not exist'
|
||||
# Post-condition: invalid or missing user returns error
|
||||
|
||||
# test invalid config
|
||||
kubectl config view | sed -E "s/apiVersion: .*/apiVersion: v-1/g" > "${TMPDIR:-/tmp}"/newconfig.yaml
|
||||
output_message=$(! "${KUBE_OUTPUT_HOSTBIN}/kubectl" get pods --context="" --user="" --kubeconfig=/tmp/newconfig.yaml 2>&1)
|
||||
kube::test::if_has_string "${output_message}" "Error loading config file"
|
||||
|
||||
output_message=$(! kubectl get pod --kubeconfig=missing-config 2>&1)
|
||||
kube::test::if_has_string "${output_message}" 'no such file or directory'
|
||||
|
||||
####################
|
||||
# Service Accounts #
|
||||
####################
|
||||
|
Reference in New Issue
Block a user