Compare commits
3
Commits
863cbb93dc
...
687339bb9e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
687339bb9e | ||
|
|
c28553a1b8 | ||
|
|
0f93cbea70 |
@@ -118,9 +118,56 @@ jobs:
|
|||||||
# cluster-admin-equivalent, so it should not be readable by
|
# cluster-admin-equivalent, so it should not be readable by
|
||||||
# anything else on the runner.
|
# anything else on the runner.
|
||||||
install -m 600 /dev/null $HOME/.kube/config
|
install -m 600 /dev/null $HOME/.kube/config
|
||||||
echo "${{ secrets.KUBEC_CONFIG_BUILDX }}" > $HOME/.kube/config
|
echo "${{ secrets.KUBEC_CONFIG_BUILDX_NEW_2 }}" > $HOME/.kube/config
|
||||||
chmod 600 $HOME/.kube/config
|
chmod 600 $HOME/.kube/config
|
||||||
|
|
||||||
|
- name: Verify the cluster is reachable
|
||||||
|
run: |
|
||||||
|
# Fail fast, and with a useful message, if the kubeconfig cannot
|
||||||
|
# talk to the API server.
|
||||||
|
#
|
||||||
|
# The certificate-authority-data inside the kubeconfig is the k3s
|
||||||
|
# server CA. If the cluster's CA has been rotated since the secret
|
||||||
|
# was created, kubectl fails with:
|
||||||
|
# tls: failed to verify certificate: x509: certificate signed by
|
||||||
|
# unknown authority
|
||||||
|
# which is a confusing way to learn that a secret is stale.
|
||||||
|
if kubectl version --request-timeout=15s >/dev/null 2>&1; then
|
||||||
|
echo "cluster reachable"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "the kubeconfig could not verify the API server - refreshing the CA"
|
||||||
|
|
||||||
|
# The API server publishes its own CA at /cacerts. Fetch it over an
|
||||||
|
# insecure connection - we cannot verify it yet, that is the problem
|
||||||
|
# being solved - and pin it explicitly. This makes the deploy
|
||||||
|
# self-healing after a CA rotation, instead of needing the secret
|
||||||
|
# to be regenerated by hand.
|
||||||
|
SERVER=$(kubectl config view --raw -o jsonpath='{.clusters[0].cluster.server}')
|
||||||
|
echo "server: $SERVER"
|
||||||
|
curl -sk "$SERVER/cacerts" -o $HOME/.kube/ca.crt
|
||||||
|
|
||||||
|
if [ ! -s $HOME/.kube/ca.crt ]; then
|
||||||
|
echo "ERROR: could not fetch the cluster CA from $SERVER/cacerts"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
kubectl config set-cluster default \
|
||||||
|
--embed-certs=true \
|
||||||
|
--certificate-authority=$HOME/.kube/ca.crt >/dev/null
|
||||||
|
rm -f $HOME/.kube/ca.crt
|
||||||
|
|
||||||
|
if kubectl version --request-timeout=15s >/dev/null 2>&1; then
|
||||||
|
echo "cluster reachable after refreshing the CA"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "ERROR: cannot reach the cluster API server even with a refreshed CA."
|
||||||
|
echo " The kubeconfig in the KUBEC_CONFIG_BUILDX_NEW_2 secret may be"
|
||||||
|
echo " stale or invalid, and needs regenerating."
|
||||||
|
exit 1
|
||||||
|
|
||||||
- name: Install kubectl
|
- name: Install kubectl
|
||||||
run: |
|
run: |
|
||||||
# Skip the whole apt dance if the runner already has a kubectl.
|
# Skip the whole apt dance if the runner already has a kubectl.
|
||||||
|
|||||||
Reference in New Issue
Block a user