|
| 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" . }} |
0 commit comments