fix(cd): use dynamic KUBECONFIG path and enhanced context diagnostics
This commit is contained in:
@@ -52,19 +52,25 @@ jobs:
|
||||
|
||||
- name: Deploy to Kubernetes
|
||||
run: |
|
||||
export KUBECONFIG=$HOME/.kube/config
|
||||
mkdir -p $HOME/.kube
|
||||
if echo "${{ secrets.KUBECONFIG }}" | grep -q "apiVersion"; then
|
||||
echo "Detected plain text KUBECONFIG"
|
||||
printf '%s' "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config
|
||||
printf '%s' "${{ secrets.KUBECONFIG }}" > $KUBECONFIG
|
||||
else
|
||||
echo "Detected base64 KUBECONFIG"
|
||||
printf '%s' "${{ secrets.KUBECONFIG }}" | base64 -d > $HOME/.kube/config
|
||||
# Handle potential newlines/wrapping in the secret
|
||||
printf '%s' "${{ secrets.KUBECONFIG }}" | base64 -d > $KUBECONFIG
|
||||
fi
|
||||
chmod 600 $HOME/.kube/config
|
||||
chmod 600 $KUBECONFIG
|
||||
|
||||
# Diagnostics
|
||||
echo "Kubeconfig size: $(wc -c < $HOME/.kube/config) bytes"
|
||||
if ! grep -q "current-context" $HOME/.kube/config; then
|
||||
echo "Kubeconfig path: $KUBECONFIG"
|
||||
echo "Kubeconfig size: $(wc -c < $KUBECONFIG) bytes"
|
||||
echo "Available contexts:"
|
||||
kubectl config get-contexts
|
||||
|
||||
if ! grep -q "current-context" $KUBECONFIG; then
|
||||
echo "Warning: current-context missing, attempting to fix..."
|
||||
FIRST_CONTEXT=$(kubectl config get-contexts -o name | head -n 1)
|
||||
if [ -n "$FIRST_CONTEXT" ]; then
|
||||
@@ -72,7 +78,6 @@ jobs:
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Current context: $(kubectl config current-context)"
|
||||
kubectl config view --minify # Verification of context
|
||||
kubectl apply -k infra/k8s/overlays/dev
|
||||
env:
|
||||
KUBECONFIG: /home/runner/.kube/config
|
||||
|
||||
Reference in New Issue
Block a user