Added integration tests for optional namesace to github workflow #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Minikube Integration Tests - Namespace Optional | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| - 'releases/*' | |
| push: | |
| branches: | |
| - main | |
| - 'releases/*' | |
| workflow_dispatch: | |
| jobs: | |
| run-integration-test: | |
| name: Run Namespace Optional Integration Tests | |
| runs-on: ubuntu-22.04 | |
| env: | |
| KUBECONFIG: /home/runner/.kube/config | |
| NAMESPACE1: integration-test-namespace1-${{ github.run_id }} | |
| NAMESPACE2: integration-test-namespace2-${{ github.run_id }} | |
| steps: | |
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| - name: Install dependencies | |
| run: | | |
| rm -rf node_modules/ | |
| npm install | |
| - name: Install ncc | |
| run: npm i -g @vercel/ncc | |
| - name: Install conntrack | |
| run: sudo apt-get install -y conntrack | |
| - name: Build | |
| run: ncc build src/run.ts -o lib | |
| - uses: Azure/setup-kubectl@3e0aec4d80787158d308d7b364cb1b702e7feb7f # v4.0.0 | |
| name: Install Kubectl | |
| - id: setup-minikube | |
| name: Setup Minikube | |
| uses: medyagh/setup-minikube@cea33675329b799adccc9526aa5daccc26cd5052 # v0.0.19 | |
| with: | |
| minikube-version: 1.34.0 | |
| kubernetes-version: 1.31.0 | |
| driver: 'none' | |
| timeout-minutes: 3 | |
| - name: Create namespaces for tests | |
| run: | | |
| kubectl create ns ${{ env.NAMESPACE1 }} | |
| kubectl create ns ${{ env.NAMESPACE2 }} | |
| - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # 5.6.0 | |
| name: Install Python | |
| with: | |
| python-version: '3.x' | |
| - name: Cleaning any previously created items | |
| run: | | |
| python test/integration/k8s-deploy-delete.py 'Deployment' 'all' ${{ env.NAMESPACE1 }} | |
| python test/integration/k8s-deploy-delete.py 'Deployment' 'all' ${{ env.NAMESPACE2 }} | |
| - name: Create test manifests | |
| run: | | |
| echo "Creating test manifests..." | |
| cat <<EOF > test_with_ns.yaml | |
| apiVersion: apps/v1 | |
| kind: Deployment | |
| metadata: | |
| name: test-deployment | |
| namespace: ${{ env.NAMESPACE1 }} | |
| spec: | |
| replicas: 1 | |
| selector: | |
| matchLabels: | |
| app: test-app | |
| template: | |
| metadata: | |
| labels: | |
| app: test-app | |
| spec: | |
| containers: | |
| - name: test-container | |
| image: nginx:latest | |
| ports: | |
| - containerPort: 80 | |
| - name: Test - Handles namespace correctly based on manifest | |
| uses: ./ | |
| with: | |
| images: nginx:1.14.2 | |
| manifests: | | |
| test_with_ns.yaml | |
| test/integration/manifests/test_no_ns.yaml | |
| action: deploy | |
| - name: Verify deployment in namespace1 | |
| run: | | |
| python test/integration/k8s-deploy-test.py namespace=${{ env.NAMESPACE1 }} kind=Deployment name=test-deployment containerName=nginx:1.14.2 labels=app:test-app selectorLabels=app:test-app | |
| - name: Verify deployment in default namespace | |
| run: | | |
| python test/integration/k8s-deploy-test.py namespace=default kind=Deployment name=test-deployment-no-ns containerName=nginx:1.14.2 labels=app:test-app selectorLabels=app:test-app | |
| - name: Test - Deploys the same resource to two different namespaces without conflict | |
| uses: ./ | |
| with: | |
| namespace: ${{ env.NAMESPACE1 }},${{ env.NAMESPACE2 }} | |
| images: nginx:1.14.2 | |
| manifests: | | |
| test/integration/manifests/test_no_ns.yaml | |
| action: deploy | |
| - name: Verify deployment in namespace2 | |
| run: | | |
| python test/integration/k8s-deploy-test.py namespace=${{ env.NAMESPACE1 }} kind=Deployment name=test-deployment-no-ns containerName=nginx:1.14.2 labels=app:test-app selectorLabels=app:test-app | |
| python test/integration/k8s-deploy-test.py namespace=${{ env.NAMESPACE2 }} kind=Deployment name=test-deployment-no-ns containerName=nginx:1.14.2 labels=app:test-app selectorLabels=app:test-app | |
| - name: Cleanup | |
| run: | | |
| echo "Cleaning up resources..." | |
| python test/integration/k8s-deploy-delete.py 'Deployment' 'test-deployment' ${{ env.NAMESPACE1 }} | |
| python test/integration/k8s-deploy-delete.py 'Deployment' 'test-deployment-no-ns' ${{ env.NAMESPACE1 }} | |
| python test/integration/k8s-deploy-delete.py 'Deployment' 'test-deployment-no-ns' ${{ env.NAMESPACE2 }} | |
| python test/integration/k8s-deploy-delete.py 'Deployment' 'test-deployment-no-ns' default | |
| kubectl delete ns ${{ env.NAMESPACE1 }} | |
| kubectl delete ns ${{ env.NAMESPACE2 }} | |
| rm -rf test_with_ns.yaml | |