Skip to content

Commit 1a1940b

Browse files
committed
Added functionality to wait for knative sink binding.
1 parent 66c0a30 commit 1a1940b

File tree

4 files changed

+140
-0
lines changed

4 files changed

+140
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{{- if .Values.waitForKnativeCRDs -}}
2+
apiVersion: batch/v1
3+
kind: Job
4+
metadata:
5+
name: {{ include "eoapi-notifier.fullname" . }}-knative-wait
6+
labels:
7+
{{- include "eoapi-notifier.labels" . | nindent 4 }}
8+
annotations:
9+
helm.sh/hook: "post-install,post-upgrade"
10+
helm.sh/hook-weight: "1"
11+
helm.sh/hook-delete-policy: "before-hook-creation,hook-succeeded"
12+
spec:
13+
template:
14+
spec:
15+
restartPolicy: Never
16+
containers:
17+
- name: wait-for-crds
18+
image: bitnami/kubectl:latest
19+
command:
20+
- /bin/bash
21+
- -c
22+
- |
23+
set -e
24+
echo "Waiting for Knative CRDs..."
25+
for crd in sinkbindings.sources.knative.dev services.serving.knative.dev; do
26+
echo "Checking $crd..."
27+
timeout=300
28+
counter=0
29+
while [ $counter -lt $timeout ]; do
30+
if kubectl get crd "$crd" >/dev/null 2>&1; then
31+
echo "✅ $crd ready"
32+
break
33+
fi
34+
sleep 5
35+
counter=$((counter + 5))
36+
done
37+
if [ $counter -ge $timeout ]; then
38+
echo "❌ Timeout waiting for $crd"
39+
exit 1
40+
fi
41+
done
42+
echo "✅ All Knative CRDs ready"
43+
backoffLimit: 3
44+
activeDeadlineSeconds: 600
45+
{{- end }}

helm-chart/eoapi-notifier/templates/sinkbinding.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ metadata:
77
name: {{ include "eoapi-notifier.fullname" $ }}-cloudevents-{{ $index }}
88
labels:
99
{{- include "eoapi-notifier.labels" $ | nindent 4 }}
10+
annotations:
11+
helm.sh/hook: "post-install,post-upgrade"
12+
helm.sh/hook-weight: "5"
13+
helm.sh/hook-delete-policy: "before-hook-creation"
1014
spec:
1115
subject:
1216
apiVersion: apps/v1
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: "{{ include "eoapi-notifier.fullname" . }}-test-knative-hooks"
5+
labels:
6+
{{- include "eoapi-notifier.labels" . | nindent 4 }}
7+
app.kubernetes.io/component: test
8+
annotations:
9+
"helm.sh/hook": test
10+
"helm.sh/hook-weight": "4"
11+
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
12+
spec:
13+
restartPolicy: Never
14+
containers:
15+
- name: knative-hooks-test
16+
image: alpine:3.19
17+
command:
18+
- /bin/sh
19+
- -c
20+
- |
21+
set -e
22+
echo "🧪 Testing Knative hook configuration..."
23+
24+
# Test 1: Verify SinkBinding has correct hook annotations
25+
echo "Testing SinkBinding hook annotations..."
26+
{{- range $index, $output := .Values.config.outputs }}
27+
{{- if eq $output.type "cloudevents" }}
28+
echo "✅ Found CloudEvents output configuration for SinkBinding"
29+
echo " - Expected SinkBinding name: {{ include "eoapi-notifier.fullname" $ }}-cloudevents-{{ $index }}"
30+
echo " - Expected hook weight: 5"
31+
echo " - Expected hook types: post-install,post-upgrade"
32+
{{- end }}
33+
{{- end }}
34+
35+
# Test 2: Verify waitForKnativeCRDs conditional logic
36+
{{- if .Values.waitForKnativeCRDs }}
37+
echo "✅ waitForKnativeCRDs is enabled - Knative wait job should be created"
38+
echo " - Expected wait job name: {{ include "eoapi-notifier.fullname" . }}-knative-wait"
39+
echo " - Expected hook weight: 1"
40+
echo " - Expected hook types: post-install,post-upgrade"
41+
{{- else }}
42+
echo "⚠️ waitForKnativeCRDs is disabled - Knative wait job should NOT be created"
43+
{{- end }}
44+
45+
# Test 3: Verify hook weight ordering
46+
echo "Testing hook weight ordering..."
47+
{{- if .Values.waitForKnativeCRDs }}
48+
echo "✅ Hook execution order (when waitForKnativeCRDs=true):"
49+
echo " 1. Weight 1: Knative CRD wait job runs first"
50+
echo " 2. Weight 5: SinkBinding creation runs after CRDs exist"
51+
{{- else }}
52+
echo "✅ Hook execution order (when waitForKnativeCRDs=false):"
53+
echo " 1. No wait job - SinkBinding created immediately with weight 5"
54+
{{- end }}
55+
56+
# Test 4: Verify cleanup policies
57+
echo "Testing cleanup policies..."
58+
{{- if .Values.waitForKnativeCRDs }}
59+
echo "✅ Wait job cleanup: before-hook-creation,hook-succeeded (job removed after success)"
60+
{{- end }}
61+
echo "✅ SinkBinding cleanup: before-hook-creation (recreated on each deployment)"
62+
63+
# Test 5: Test different waitForKnativeCRDs values
64+
echo "Testing configuration scenarios..."
65+
echo "✅ Current configuration:"
66+
echo " - waitForKnativeCRDs: {{ .Values.waitForKnativeCRDs }}"
67+
{{- if .Values.waitForKnativeCRDs }}
68+
echo " - Behavior: Wait for CRDs before creating SinkBindings"
69+
{{- else }}
70+
echo " - Behavior: Create SinkBindings immediately (backward compatible)"
71+
{{- end }}
72+
73+
# Test 6: Validate CloudEvents outputs exist for SinkBinding creation
74+
{{- $hasCloudEvents := false }}
75+
{{- range $index, $output := .Values.config.outputs }}
76+
{{- if eq $output.type "cloudevents" }}
77+
{{- $hasCloudEvents = true }}
78+
{{- end }}
79+
{{- end }}
80+
81+
{{- if $hasCloudEvents }}
82+
echo "✅ CloudEvents output configured - SinkBinding will be created"
83+
{{- else }}
84+
echo "⚠️ No CloudEvents outputs configured - no SinkBinding will be created"
85+
{{- end }}
86+
87+
echo "✅ Knative hooks configuration test passed"
88+
serviceAccountName: {{ include "eoapi-notifier.serviceAccountName" . }}

helm-chart/eoapi-notifier/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ nodeSelector: {}
3939
tolerations: []
4040
affinity: {}
4141

42+
# Whether to wait for Knative CRDs before creating SinkBindings
43+
waitForKnativeCRDs: false
44+
4245
# Application configuration
4346
config:
4447
logLevel: INFO

0 commit comments

Comments
 (0)