|
| 1 | +name: e2e |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - 'main' |
| 7 | + tags: |
| 8 | + - 'v*' |
| 9 | + pull_request: |
| 10 | + branches: [ main ] |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +env: |
| 14 | + GO_VERSION: "1.22.0" |
| 15 | + K8S_VERSION: "v1.29.2" |
| 16 | + KIND_VERSION: "v0.22.0" |
| 17 | + REGISTRY: ghcr.io |
| 18 | + IMAGE_NAME: registry.k8s.io/kube-netpol |
| 19 | + KIND_CLUSTER_NAME: kind |
| 20 | + |
| 21 | +permissions: write-all |
| 22 | + |
| 23 | +jobs: |
| 24 | + build: |
| 25 | + name: build |
| 26 | + runs-on: ubuntu-latest |
| 27 | + steps: |
| 28 | + - name: Set up Go |
| 29 | + uses: actions/setup-go@v2 |
| 30 | + with: |
| 31 | + go-version: ${{ env.GO_VERSION }} |
| 32 | + id: go |
| 33 | + |
| 34 | + - name: Check out code |
| 35 | + uses: actions/checkout@v2 |
| 36 | + |
| 37 | + - name: Build |
| 38 | + run: | |
| 39 | + docker build -t registry.k8s.io/kube-netpol:test -f Dockerfile . |
| 40 | + mkdir _output |
| 41 | + docker save registry.k8s.io/kube-netpol:test > _output/kube-netpol-image.tar |
| 42 | +
|
| 43 | + - uses: actions/upload-artifact@v2 |
| 44 | + with: |
| 45 | + name: test-image |
| 46 | + path: _output/kube-netpol-image.tar |
| 47 | + |
| 48 | + e2e: |
| 49 | + name: e2e |
| 50 | + runs-on: ubuntu-22.04 |
| 51 | + timeout-minutes: 100 |
| 52 | + needs: |
| 53 | + - build |
| 54 | + strategy: |
| 55 | + fail-fast: false |
| 56 | + matrix: |
| 57 | + # TODO add "dual", waiting on KEP https://github.com/kubernetes/enhancements/tree/master/keps/sig-network/3705-cloud-node-ips |
| 58 | + ipFamily: ["ipv4", "ipv6"] |
| 59 | + env: |
| 60 | + JOB_NAME: "kube-netpol-${{ matrix.ipFamily }}" |
| 61 | + IP_FAMILY: ${{ matrix.ipFamily }} |
| 62 | + steps: |
| 63 | + - name: Check out code |
| 64 | + uses: actions/checkout@v2 |
| 65 | + |
| 66 | + - name: Enable ipv4 and ipv6 forwarding |
| 67 | + run: | |
| 68 | + sudo sysctl -w net.ipv6.conf.all.forwarding=1 |
| 69 | + sudo sysctl -w net.ipv4.ip_forward=1 |
| 70 | +
|
| 71 | + - name: Set up environment (download dependencies) |
| 72 | + run: | |
| 73 | + TMP_DIR=$(mktemp -d) |
| 74 | + # Test binaries |
| 75 | + curl -L https://dl.k8s.io/${{ env.K8S_VERSION }}/kubernetes-test-linux-amd64.tar.gz -o ${TMP_DIR}/kubernetes-test-linux-amd64.tar.gz |
| 76 | + tar xvzf ${TMP_DIR}/kubernetes-test-linux-amd64.tar.gz \ |
| 77 | + --directory ${TMP_DIR} \ |
| 78 | + --strip-components=3 kubernetes/test/bin/ginkgo kubernetes/test/bin/e2e.test |
| 79 | + # kubectl |
| 80 | + curl -L https://dl.k8s.io/${{ env.K8S_VERSION }}/bin/linux/amd64/kubectl -o ${TMP_DIR}/kubectl |
| 81 | + # kind |
| 82 | + curl -Lo ${TMP_DIR}/kind https://kind.sigs.k8s.io/dl/${{ env.KIND_VERSION }}/kind-linux-amd64 |
| 83 | + # Install |
| 84 | + sudo cp ${TMP_DIR}/ginkgo /usr/local/bin/ginkgo |
| 85 | + sudo cp ${TMP_DIR}/e2e.test /usr/local/bin/e2e.test |
| 86 | + sudo cp ${TMP_DIR}/kubectl /usr/local/bin/kubectl |
| 87 | + sudo cp ${TMP_DIR}/kind /usr/local/bin/kind |
| 88 | + sudo chmod +x /usr/local/bin/* |
| 89 | +
|
| 90 | + - name: Create multi node cluster |
| 91 | + run: | |
| 92 | + # output_dir |
| 93 | + mkdir -p _artifacts |
| 94 | + # create cluster |
| 95 | + cat <<EOF | /usr/local/bin/kind create cluster \ |
| 96 | + --name ${{ env.KIND_CLUSTER_NAME}} \ |
| 97 | + --image kindest/node:${{ env.K8S_VERSION }} \ |
| 98 | + -v7 --wait 1m --retain --config=- |
| 99 | + kind: Cluster |
| 100 | + apiVersion: kind.x-k8s.io/v1alpha4 |
| 101 | + networking: |
| 102 | + ipFamily: ${IP_FAMILY} |
| 103 | + nodes: |
| 104 | + - role: control-plane |
| 105 | + - role: worker |
| 106 | + - role: worker |
| 107 | + EOF |
| 108 | + # dump the kubeconfig for later |
| 109 | + /usr/local/bin/kind get kubeconfig --name ${{ env.KIND_CLUSTER_NAME}} > _artifacts/kubeconfig.conf |
| 110 | +
|
| 111 | + - uses: actions/download-artifact@v2 |
| 112 | + with: |
| 113 | + name: test-image |
| 114 | + |
| 115 | + - name: Install kube-netpol |
| 116 | + run: | |
| 117 | + # preload kube-netpol image |
| 118 | + docker load --input kube-netpol-image.tar |
| 119 | + /usr/local/bin/kind load docker-image registry.k8s.io/kube-netpol:test --name ${{ env.KIND_CLUSTER_NAME}} |
| 120 | + sed -i s#registry.k8s.io/kube-netpol.*#registry.k8s.io/kube-netpol:test# install.yaml |
| 121 | + /usr/local/bin/kubectl apply -f ./install.yaml |
| 122 | +
|
| 123 | + - name: Get Cluster status |
| 124 | + run: | |
| 125 | + # wait network is ready |
| 126 | + sleep 5 |
| 127 | + /usr/local/bin/kubectl get nodes -o wide |
| 128 | + /usr/local/bin/kubectl get pods -A |
| 129 | + /usr/local/bin/kubectl wait --timeout=1m --for=condition=ready pods --namespace=kube-system -l k8s-app=kube-dns |
| 130 | + /usr/local/bin/kubectl wait --timeout=1m --for=condition=ready pods --namespace=kube-system -l app=kube-network-policies |
| 131 | +
|
| 132 | + - name: Run tests |
| 133 | + run: | |
| 134 | + export KUBERNETES_CONFORMANCE_TEST='y' |
| 135 | + export E2E_REPORT_DIR=${PWD}/_artifacts |
| 136 | +
|
| 137 | + # Run tests |
| 138 | + /usr/local/bin/ginkgo --nodes=25 \ |
| 139 | + --focus="Netpol" \ |
| 140 | + /usr/local/bin/e2e.test \ |
| 141 | + -- \ |
| 142 | + --kubeconfig=${PWD}/_artifacts/kubeconfig.conf \ |
| 143 | + --provider=local \ |
| 144 | + --dump-logs-on-failure=false \ |
| 145 | + --report-dir=${E2E_REPORT_DIR} \ |
| 146 | + --disable-log-dump=true |
| 147 | +
|
| 148 | + - name: Upload Junit Reports |
| 149 | + if: always() |
| 150 | + uses: actions/upload-artifact@v2 |
| 151 | + with: |
| 152 | + name: kind-junit-${{ env.JOB_NAME }}-${{ github.run_id }} |
| 153 | + path: './_artifacts/*.xml' |
| 154 | + |
| 155 | + - name: Export logs |
| 156 | + if: always() |
| 157 | + run: | |
| 158 | + /usr/local/bin/kind export logs --name ${KIND_CLUSTER_NAME} --loglevel=debug ./_artifacts/logs |
| 159 | +
|
| 160 | + - name: Upload logs |
| 161 | + if: always() |
| 162 | + uses: actions/upload-artifact@v2 |
| 163 | + with: |
| 164 | + name: kind-logs-${{ env.JOB_NAME }}-${{ github.run_id }} |
| 165 | + path: ./_artifacts/logs |
0 commit comments