|
32 | 32 | set -e |
33 | 33 | echo "=== Knative Initialization ===" |
34 | 34 |
|
35 | | - # Wait for knative-operator to be ready |
36 | | - echo "Waiting for knative-operator..." |
37 | | - kubectl rollout status deployment/knative-operator -n default --timeout={{ .Values.knative.initTimeout | default "600s" }} |
| 35 | + # Wait for knative-operator with exponential backoff |
| 36 | + echo "Waiting for knative-operator deployment to be available..." |
| 37 | + RELEASE_NAMESPACE="{{ .Release.Namespace }}" |
| 38 | + OPERATOR_NAMESPACE="" |
| 39 | + max_attempts=60 |
| 40 | + attempt=1 |
| 41 | + backoff=5 |
| 42 | +
|
| 43 | + while [ $attempt -le $max_attempts ]; do |
| 44 | + echo "Attempt $attempt/$max_attempts: Looking for knative-operator..." |
| 45 | +
|
| 46 | + # First check the release namespace (most likely location for Helm dependency) |
| 47 | + if kubectl get deployment knative-operator -n "$RELEASE_NAMESPACE" >/dev/null 2>&1; then |
| 48 | + OPERATOR_NAMESPACE="$RELEASE_NAMESPACE" |
| 49 | + echo "✅ Found knative-operator in release namespace: $OPERATOR_NAMESPACE" |
| 50 | + break |
| 51 | + fi |
| 52 | +
|
| 53 | + # Fallback: check all namespaces |
| 54 | + OPERATOR_NAMESPACE=$(kubectl get deployment knative-operator --all-namespaces -o jsonpath='{.items[0].metadata.namespace}' 2>/dev/null || echo "") |
| 55 | + if [ -n "$OPERATOR_NAMESPACE" ]; then |
| 56 | + echo "✅ Found knative-operator in namespace: $OPERATOR_NAMESPACE" |
| 57 | + break |
| 58 | + fi |
| 59 | +
|
| 60 | + echo "⏳ knative-operator not found, waiting ${backoff}s before retry..." |
| 61 | + sleep $backoff |
| 62 | + attempt=$((attempt + 1)) |
| 63 | +
|
| 64 | + # Exponential backoff with max of 30s |
| 65 | + if [ $backoff -lt 30 ]; then |
| 66 | + backoff=$((backoff * 2)) |
| 67 | + fi |
| 68 | + done |
| 69 | +
|
| 70 | + if [ -z "$OPERATOR_NAMESPACE" ]; then |
| 71 | + echo "❌ knative-operator deployment not found after $max_attempts attempts" |
| 72 | + echo "" |
| 73 | + echo "=== Debugging Information ===" |
| 74 | + echo "Current namespace: $RELEASE_NAMESPACE" |
| 75 | + echo "" |
| 76 | + echo "Helm releases in current namespace:" |
| 77 | + helm list -n "$RELEASE_NAMESPACE" || echo "No helm releases found" |
| 78 | + echo "" |
| 79 | + echo "All deployments in current namespace:" |
| 80 | + kubectl get deployments -n "$RELEASE_NAMESPACE" -o wide || echo "No deployments found" |
| 81 | + echo "" |
| 82 | + echo "All deployments across all namespaces (first 20):" |
| 83 | + kubectl get deployments --all-namespaces | head -21 |
| 84 | + echo "" |
| 85 | + echo "Knative-related resources:" |
| 86 | + kubectl get all --all-namespaces | grep -i knative || echo "No knative resources found" |
| 87 | + echo "" |
| 88 | + echo "Recent events in current namespace:" |
| 89 | + kubectl get events -n "$RELEASE_NAMESPACE" --sort-by='.lastTimestamp' | tail -10 || echo "No events found" |
| 90 | + echo "" |
| 91 | + echo "Pod status in current namespace:" |
| 92 | + kubectl get pods -n "$RELEASE_NAMESPACE" -o wide || echo "No pods found" |
| 93 | + exit 1 |
| 94 | + fi |
| 95 | +
|
| 96 | + echo "Waiting for knative-operator deployment to be ready..." |
| 97 | + if ! kubectl rollout status deployment/knative-operator -n "$OPERATOR_NAMESPACE" --timeout=600s; then |
| 98 | + echo "❌ knative-operator failed to become ready within timeout" |
| 99 | + echo "Deployment status:" |
| 100 | + kubectl describe deployment knative-operator -n "$OPERATOR_NAMESPACE" |
| 101 | + echo "Pod status:" |
| 102 | + kubectl get pods -n "$OPERATOR_NAMESPACE" -l name=knative-operator -o wide |
| 103 | + echo "Recent events:" |
| 104 | + kubectl get events -n "$OPERATOR_NAMESPACE" --sort-by='.lastTimestamp' | tail -10 |
| 105 | + exit 1 |
| 106 | + fi |
| 107 | +
|
| 108 | + echo "✅ knative-operator is ready, proceeding with Knative setup..." |
38 | 109 |
|
39 | 110 | # Create namespaces |
40 | 111 | kubectl create namespace knative-serving --dry-run=client -o yaml | kubectl apply -f - |
|
55 | 126 | echo "✅ KnativeServing created successfully" |
56 | 127 | else |
57 | 128 | echo "❌ Failed to create KnativeServing. Checking operator status..." |
58 | | - kubectl get pods -n default -l name=knative-operator |
| 129 | + kubectl get pods -n "$OPERATOR_NAMESPACE" -l name=knative-operator |
| 130 | + kubectl logs -n "$OPERATOR_NAMESPACE" -l name=knative-operator --tail=20 |
59 | 131 | exit 1 |
60 | 132 | fi |
61 | 133 |
|
|
74 | 146 | echo "✅ KnativeEventing created successfully" |
75 | 147 | else |
76 | 148 | echo "❌ Failed to create KnativeEventing. Checking operator status..." |
77 | | - kubectl get pods -n default -l name=knative-operator |
| 149 | + kubectl get pods -n "$OPERATOR_NAMESPACE" -l name=knative-operator |
| 150 | + kubectl logs -n "$OPERATOR_NAMESPACE" -l name=knative-operator --tail=20 |
78 | 151 | exit 1 |
79 | 152 | fi |
80 | 153 |
|
|
87 | 160 | limits: |
88 | 161 | cpu: 50m |
89 | 162 | memory: 64Mi |
90 | | - backoffLimit: 3 |
91 | | - activeDeadlineSeconds: 600 |
| 163 | + backoffLimit: 1 |
| 164 | + activeDeadlineSeconds: 1200 |
92 | 165 | {{- end }} |
0 commit comments