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