1+ name : Test Capsule Attachment with kind
2+
3+ on :
4+ push :
5+ branches : [ main ]
6+ pull_request :
7+ branches : [ main ]
8+ workflow_dispatch :
9+
10+ jobs :
11+ test-with-kind :
12+ runs-on : ubuntu-latest
13+ timeout-minutes : 15
14+
15+ steps :
16+ - name : Checkout code
17+ uses : actions/checkout@v3
18+
19+ - name : Set up Go
20+ uses : actions/setup-go@v4
21+ with :
22+ go-version : ' ^1.24'
23+ cache : true
24+
25+ - name : Build
26+ run : go build -v ./...
27+
28+ - name : Create kind cluster
29+ uses : helm/kind-action@v1.5.0
30+ with :
31+ cluster_name : capsule-test
32+ wait : 120s
33+
34+ - name : Wait for kind to be ready
35+ run : |
36+ kubectl cluster-info
37+ kubectl wait --for=condition=Ready nodes --all --timeout=90s
38+ kubectl get nodes
39+
40+ - name : Create test resources
41+ run : |
42+ # Create test namespace
43+ kubectl create namespace capsule-test
44+
45+ # Create test ConfigMap capsule
46+ cat <<EOF | kubectl apply -f - -n capsule-test
47+ apiVersion: v1
48+ kind: ConfigMap
49+ metadata:
50+ name: test-config-1.0
51+ labels:
52+ capsule.docker.io/name: test-config
53+ capsule.docker.io/version: "1.0"
54+ data:
55+ config.yml: |
56+ testKey: testValue
57+ environment: test
58+ EOF
59+
60+ # Create test Deployment
61+ cat <<EOF | kubectl apply -f - -n capsule-test
62+ apiVersion: apps/v1
63+ kind: Deployment
64+ metadata:
65+ name: test-app
66+ spec:
67+ replicas: 1
68+ selector:
69+ matchLabels:
70+ app: test-app
71+ template:
72+ metadata:
73+ labels:
74+ app: test-app
75+ spec:
76+ containers:
77+ - name: nginx
78+ image: nginx:alpine
79+ ports:
80+ - containerPort: 80
81+ EOF
82+
83+ # Wait for deployment to be ready
84+ kubectl wait --for=condition=Available deployment/test-app -n capsule-test --timeout=60s
85+
86+ - name : Run capsule attachment tests
87+ run : |
88+ # Run your capsule attachment command with the binary you built
89+ ./basic-docker k8s-capsule create test-config 1.0 ./dummy-path
90+
91+ # Use kubectl exec to test if capsule is accessible in pod
92+ POD_NAME=$(kubectl get pods -n capsule-test -l app=test-app -o jsonpath="{.items[0].metadata.name}")
93+
94+ # Execute AttachCapsuleToDeployment
95+ go test -v -run TestAttachCapsuleToDeployment
96+
97+ # Verify that the deployment was updated with the capsule volume
98+ VOLUMES=$(kubectl get deployment test-app -n capsule-test -o jsonpath='{.spec.template.spec.volumes[*].name}')
99+ echo "Deployment volumes: $VOLUMES"
100+
101+ if [[ $VOLUMES == *"capsule-test-config-1.0"* ]]; then
102+ echo "✅ Capsule volume successfully attached to deployment!"
103+ else
104+ echo "❌ Capsule volume not found in deployment"
105+ exit 1
106+ fi
107+
108+ # Verify that the pod has the volume mount
109+ kubectl rollout restart deployment/test-app -n capsule-test
110+ kubectl rollout status deployment/test-app -n capsule-test --timeout=60s
111+
112+ # Get the new pod name after restart
113+ POD_NAME=$(kubectl get pods -n capsule-test -l app=test-app -o jsonpath="{.items[0].metadata.name}")
114+
115+ # Verify the volume mount exists in the pod
116+ MOUNTS=$(kubectl get pod $POD_NAME -n capsule-test -o jsonpath='{.spec.containers[0].volumeMounts[*].name}')
117+ echo "Pod volume mounts: $MOUNTS"
118+
119+ if [[ $MOUNTS == *"capsule-test-config-1.0"* ]]; then
120+ echo "✅ Capsule volume mount successfully added to pod!"
121+ else
122+ echo "❌ Capsule volume mount not found in pod"
123+ exit 1
124+ fi
125+
126+ # Try to access the capsule data from the pod
127+ kubectl exec $POD_NAME -n capsule-test -- ls -la /capsules/test-config/1.0/
128+
129+ - name : Display logs on failure
130+ if : failure()
131+ run : |
132+ echo "==== kubectl get all ===="
133+ kubectl get all -n capsule-test
134+
135+ echo "==== Deployment YAML ===="
136+ kubectl get deployment test-app -n capsule-test -o yaml
137+
138+ echo "==== Pod logs ===="
139+ POD_NAME=$(kubectl get pods -n capsule-test -l app=test-app -o jsonpath="{.items[0].metadata.name}" 2>/dev/null || echo "no-pod-found")
140+ if [ "$POD_NAME" != "no-pod-found" ]; then
141+ kubectl logs $POD_NAME -n capsule-test
142+ fi
0 commit comments