Skip to content

separate each test, continue on error #3

separate each test, continue on error

separate each test, continue on error #3

Workflow file for this run

name: Test Capsule Attachment with kind
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
test-with-kind:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '^1.24'
cache: true
- name: Build binary app
run: |
# Build with output path specified
go build -v -o basic-docker
# Verify binary exists and is executable
ls -la basic-docker
chmod +x basic-docker
# Move to a directory in PATH (alternative approach)
sudo mv basic-docker /usr/local/bin/
which basic-docker
- name: Create kind cluster
uses: helm/[email protected]
with:
cluster_name: capsule-test
wait: 120s
- name: Wait for kind to be ready
run: |
kubectl cluster-info
kubectl wait --for=condition=Ready nodes --all --timeout=90s
kubectl get nodes
- name: Create test resources
run: |
# Create test namespace
kubectl create namespace capsule-test
# Create test ConfigMap capsule
cat <<EOF | kubectl apply -f - -n capsule-test
apiVersion: v1
kind: ConfigMap
metadata:
name: test-config-1.0
labels:
capsule.docker.io/name: test-config
capsule.docker.io/version: "1.0"
data:
config.yml: |
testKey: testValue
environment: test
EOF
# Create test Deployment
cat <<EOF | kubectl apply -f - -n capsule-test
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-app
spec:
replicas: 1
selector:
matchLabels:
app: test-app
template:
metadata:
labels:
app: test-app
spec:
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
EOF
# Wait for deployment to be ready
kubectl wait --for=condition=Available deployment/test-app -n capsule-test --timeout=60s
- name: Run capsule attachment tests
id: verify-binary
continue-on-error: true
run: |
# Create dummy path for testing
mkdir -p /tmp/capsules
echo "test-config data" > /tmp/capsules/test-config
# Use the binary that should now be in PATH
basic-docker k8s-capsule create test-config 1.0 /tmp/capsules/test-config
- name: Test API methods with Go tests
id: go-tests
continue-on-error: true
run: |
echo "::group::Running Go tests for AttachCapsuleToDeployment"
export KUBECONFIG=$HOME/.kube/config
export TEST_NAMESPACE=capsule-test
go test -v -run TestAttachCapsuleToDeployment
TEST_RESULT=$?
echo "Go test exit code: $TEST_RESULT"
echo "::endgroup::"
if [ $TEST_RESULT -eq 0 ]; then
echo "✅ Go tests passed successfully!"
echo "go_tests_success=true" >> $GITHUB_OUTPUT
else
echo "⚠️ Go tests failed, but continuing with manual tests"
echo "go_tests_success=false" >> $GITHUB_OUTPUT
fi
- name: Verify deployment configuration
id: verify-deployment
continue-on-error: true
run: |
echo "::group::Verifying deployment configuration"
# Check if the volume was added to the deployment
VOLUMES=$(kubectl get deployment test-app -n capsule-test -o jsonpath='{.spec.template.spec.volumes[*].name}')
echo "Deployment volumes: $VOLUMES"
VERIFICATION_RESULT=0
if [[ $VOLUMES == *"capsule-test-config-1.0"* ]]; then
echo "✅ Capsule volume successfully attached to deployment!"
else
echo "❌ Capsule volume not found in deployment"
VERIFICATION_RESULT=1
fi
# Check volume source type (should be ConfigMap)
VOLUME_CM_NAME=$(kubectl get deployment test-app -n capsule-test -o jsonpath='{.spec.template.spec.volumes[?(@.name=="capsule-test-config-1.0")].configMap.name}')
if [[ "$VOLUME_CM_NAME" == "test-config-1.0" ]]; then
echo "✅ Volume correctly references ConfigMap!"
else
echo "❌ Volume doesn't reference correct ConfigMap: $VOLUME_CM_NAME"
VERIFICATION_RESULT=1
fi
echo "::endgroup::"
if [ $VERIFICATION_RESULT -eq 0 ]; then
echo "deployment_verified=true" >> $GITHUB_OUTPUT
else
echo "deployment_verified=false" >> $GITHUB_OUTPUT
fi
- name: Verify pod configuration
id: verify-pod
continue-on-error: true
run: |
echo "::group::Verifying pod configuration"
# Restart the deployment to pick up changes
kubectl rollout restart deployment/test-app -n capsule-test
kubectl rollout status deployment/test-app -n capsule-test --timeout=60s
# Get the new pod name
POD_NAME=$(kubectl get pods -n capsule-test -l app=test-app -o jsonpath="{.items[0].metadata.name}")
echo "Pod name: $POD_NAME"
# Verify the volume mount exists in the pod
MOUNTS=$(kubectl get pod $POD_NAME -n capsule-test -o jsonpath='{.spec.containers[0].volumeMounts[*].name}')
echo "Pod volume mounts: $MOUNTS"
VERIFICATION_RESULT=0
if [[ $MOUNTS == *"capsule-test-config-1.0"* ]]; then
echo "✅ Capsule volume mount successfully added to pod!"
else
echo "❌ Capsule volume mount not found in pod"
VERIFICATION_RESULT=1
fi
# Verify mount path
MOUNT_PATH=$(kubectl get pod $POD_NAME -n capsule-test -o jsonpath='{.spec.containers[0].volumeMounts[?(@.name=="capsule-test-config-1.0")].mountPath}')
echo "Mount path: $MOUNT_PATH"
if [[ "$MOUNT_PATH" == "/capsules/test-config/1.0" ]]; then
echo "✅ Volume mounted at correct path!"
else
echo "❌ Volume mounted at incorrect path: $MOUNT_PATH"
VERIFICATION_RESULT=1
fi
# Try to access the capsule data from the pod
echo "Attempting to access capsule in pod:"
kubectl exec $POD_NAME -n capsule-test -- ls -la /capsules/test-config/1.0/ || {
echo "⚠️ Could not access capsule path in pod"
VERIFICATION_RESULT=1
}
# Try to view the actual config content
echo "Attempting to view config content:"
kubectl exec $POD_NAME -n capsule-test -- cat /capsules/test-config/1.0/config.yml || {
echo "⚠️ Could not view config content"
}
echo "::endgroup::"
if [ $VERIFICATION_RESULT -eq 0 ]; then
echo "pod_verified=true" >> $GITHUB_OUTPUT
else
echo "pod_verified=false" >> $GITHUB_OUTPUT
fi
- name: Display logs on failure
if: failure()
run: |
echo "==== kubectl get all ===="
kubectl get all -n capsule-test
echo "==== Deployment YAML ===="
kubectl get deployment test-app -n capsule-test -o yaml
echo "==== Pod logs ===="
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")
if [ "$POD_NAME" != "no-pod-found" ]; then
kubectl logs $POD_NAME -n capsule-test
fi