From 84b930e3228e855a662ab7e54777fc3929354f29 Mon Sep 17 00:00:00 2001 From: eili1s <183522504+eili1s@users.noreply.github.com> Date: Sun, 1 Nov 2026 19:09:37 +0100 Subject: [PATCH] feat(cd): verify Kubernetes backend connectivity --- .github/workflows/deploy.yml | 51 +++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3c0ee4e..40b3f86 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -143,4 +143,53 @@ jobs: kops get cluster einalien.k8s.local \ --state="$KOPS_STATE_STORE" > /dev/null - echo "kOps state store access verified." \ No newline at end of file + echo "kOps state store access verified." + + # Generate short-lived Kubernetes credentials. + - name: Generate Kubernetes kubeconfig + shell: bash + env: + OS_APPLICATION_CREDENTIAL_ID: ${{ secrets.KOPS_APPLICATION_CREDENTIAL_ID }} + OS_APPLICATION_CREDENTIAL_SECRET: ${{ secrets.KOPS_APPLICATION_CREDENTIAL_SECRET }} + run: | + set -euo pipefail + + KUBECONFIG_FILE="$RUNNER_TEMP/assignment2-kubeconfig" + umask 077 + + kops export kubeconfig einalien.k8s.local \ + --admin=1h \ + --state="$KOPS_STATE_STORE" \ + --kubeconfig="$KUBECONFIG_FILE" + + test -s "$KUBECONFIG_FILE" + chmod 600 "$KUBECONFIG_FILE" + + # Verify that the generated configuration contains a cluster context. + KUBECONFIG="$KUBECONFIG_FILE" kubectl config current-context + + # Make the kubeconfig available to subsequent steps. + echo "KUBECONFIG=$KUBECONFIG_FILE" >> "$GITHUB_ENV" + echo "KUBE_CONFIG_PATH=$KUBECONFIG_FILE" >> "$GITHUB_ENV" + + # Confirm that the runner can communicate with Kubernetes. + - name: Verify Kubernetes state access + shell: bash + run: | + set -euo pipefail + + kubectl --request-timeout=15s get --raw=/readyz + kubectl --request-timeout=15s get namespace iac + + # Check the permissions required by the state backend. + kubectl auth can-i get secrets -n iac --quiet + kubectl auth can-i create leases.coordination.k8s.io -n iac --quiet + + echo "Kubernetes state backend access verified." + + # Remove temporary credentials even when verification fails. + - name: Clean up Kubernetes credentials + if: always() + shell: bash + run: | + rm -f "$RUNNER_TEMP/assignment2-kubeconfig" \ No newline at end of file