I'm using aws eks and want to have a small shell func to check if kubectl can communicate with the cluster and if not display a nicer error msg.
this is my script:
_validate_kube_connectivity()
{
echo -n "kubernetes connectivity using kubectl..."
kubectl get ns default
if [[ ! "$?" -eq 0 ]]; then
notok "failed (pls activate via AWS creds)"
exit
fi
ok "yes"
}
however when there are no AWS credentials it is not going to "IF" statement and this is what I see in console:
kubernetes connectivity using kubectl...Unable to locate credentials. You can configure credentials by running "aws configure".
Unable to locate credentials. You can configure credentials by running "aws configure".
Unable to locate credentials. You can configure credentials by running "aws configure".
Unable to locate credentials. You can configure credentials by running "aws configure".
Unable to locate credentials. You can configure credentials by running "aws configure".
Unable to connect to the server: getting credentials: exec: executable aws failed with exit code 255
so how do I solve such cases in bash?