mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-11 06:02:18 +00:00
handle invalid client config option errors
This patch provides a more relevant error message when a client configuration option is passed with an invalid or non-existent value. `$ kubectl get pods --cluster="non-existent"` ``` error: No configuration file found, please login or point to an existing file ``` `$ kubectl get pods --cluster="non-existent"` ``` error: cluster "non-existent" does not exist ```
This commit is contained in:
@@ -1584,6 +1584,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