PERF(config): improve kubeconfig decoding

- Remove all whitespace before decoding
- Try both -d and --decode options
- Fallback to using value as-is (if Gitea already decoded)
- Verify YAML validity before using
- Better error handling and diagnostics
This commit is contained in:
2025-12-28 17:56:32 +09:00
parent 9455c521cf
commit aec80456ef

View File

@@ -41,12 +41,7 @@ jobs:
run: | run: |
if [ -z "$KUBECONFIG_B64" ]; then if [ -z "$KUBECONFIG_B64" ]; then
echo "❌ KUBECONFIG secret not set" echo "❌ KUBECONFIG secret not set"
echo "" echo "Please add KUBECONFIG to Gitea repository secrets"
echo "Please add KUBECONFIG to Gitea repository secrets:"
echo "1. Go to: https://gitea0213.kro.kr/bluemayne/jovies/settings/secrets"
echo "2. Add new secret:"
echo " Name: KUBECONFIG"
echo " Value: <base64 encoded kubeconfig>"
exit 1 exit 1
fi fi
@@ -54,17 +49,33 @@ jobs:
mkdir -p $HOME/.kube mkdir -p $HOME/.kube
# Decode base64 (handle both single-line and multi-line) # Clean up the base64 string (remove all whitespace and newlines)
echo "$KUBECONFIG_B64" | tr -d '\n' | base64 -d > $HOME/.kube/config || { CLEAN_B64=$(echo "$KUBECONFIG_B64" | tr -d '[:space:]')
echo "❌ Failed to decode KUBECONFIG"
echo "Secret length: ${#KUBECONFIG_B64}" echo "After cleanup: ${#CLEAN_B64} chars"
echo "First 50 chars: ${KUBECONFIG_B64:0:50}..."
exit 1 # Try decoding
} if echo "$CLEAN_B64" | base64 -d > $HOME/.kube/config 2>/dev/null; then
echo "✅ Successfully decoded kubeconfig"
elif echo "$CLEAN_B64" | base64 --decode > $HOME/.kube/config 2>/dev/null; then
echo "✅ Successfully decoded kubeconfig (with --decode)"
else
echo "❌ Both base64 decode methods failed"
echo "Trying to save as-is (maybe already decoded)..."
echo "$KUBECONFIG_B64" > $HOME/.kube/config
fi
chmod 600 $HOME/.kube/config chmod 600 $HOME/.kube/config
echo "✅ Kubeconfig configured" # Verify it's valid YAML
if head -1 $HOME/.kube/config | grep -q "apiVersion"; then
echo "✅ Kubeconfig appears valid"
else
echo "⚠️ Kubeconfig may not be valid, first line:"
head -1 $HOME/.kube/config
fi
# Test connection
kubectl cluster-info kubectl cluster-info
kubectl get nodes -o wide kubectl get nodes -o wide