|
| 1 | +name: E2E Deploy Changes CI |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + release: |
| 6 | + types: [created] |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + - v* |
| 11 | + paths: |
| 12 | + - "test/deploy_changes/**" |
| 13 | + |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 17 | + cancel-in-progress: true |
| 18 | + |
| 19 | +env: |
| 20 | + REPOSITORY_NAME: ghcr.io/${{ github.repository }}-ci |
| 21 | + TAG_NAME: PR${{ github.event.number }} |
| 22 | + VCLUSTER_SUFFIX: vcluster |
| 23 | + VCLUSTER_NAME: vcluster |
| 24 | + VCLUSTER_NAMESPACE: vcluster |
| 25 | + |
| 26 | +jobs: |
| 27 | + build-and-push-syncer-image: |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - name: Checkout repository |
| 31 | + uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + fetch-depth: 0 |
| 34 | + - run: git fetch --force --tags |
| 35 | + - name: Set up Go |
| 36 | + uses: actions/setup-go@v5 |
| 37 | + with: |
| 38 | + go-version: "1.22" |
| 39 | + - name: Setup Just |
| 40 | + uses: extractions/setup-just@v2 |
| 41 | + - name: Setup Syft |
| 42 | + uses: anchore/sbom-action/download-syft@v0.17.0 |
| 43 | + - name: Setup GoReleaser |
| 44 | + uses: goreleaser/goreleaser-action@v6 |
| 45 | + with: |
| 46 | + install-only: true |
| 47 | + version: latest |
| 48 | + - name: Build and save syncer image |
| 49 | + run: | |
| 50 | + set -x |
| 51 | + TELEMETRY_PRIVATE_KEY="" goreleaser build --single-target --snapshot --id vcluster --clean --output ./vcluster |
| 52 | + docker build -t "${{ env.REPOSITORY_NAME }}:${{ env.TAG_NAME }}" -f Dockerfile.release --build-arg TARGETARCH=amd64 --build-arg TARGETOS=linux . |
| 53 | + docker save -o vcluster_syncer "${{ env.REPOSITORY_NAME }}:${{ env.TAG_NAME }}" |
| 54 | + - name: Upload syncer image to artifact |
| 55 | + uses: actions/upload-artifact@v4 |
| 56 | + with: |
| 57 | + name: vcluster_syncer |
| 58 | + path: ./vcluster_syncer |
| 59 | + retention-days: 7 |
| 60 | + |
| 61 | + build-vcluster-cli: |
| 62 | + runs-on: ubuntu-latest |
| 63 | + steps: |
| 64 | + - name: Checkout repository |
| 65 | + uses: actions/checkout@v4 |
| 66 | + with: |
| 67 | + fetch-depth: 0 |
| 68 | + - run: git fetch --force --tags |
| 69 | + - name: Set up Go |
| 70 | + uses: actions/setup-go@v5 |
| 71 | + with: |
| 72 | + go-version: "1.22" |
| 73 | + - name: Setup Just |
| 74 | + uses: extractions/setup-just@v2 |
| 75 | + - name: Setup Syft |
| 76 | + uses: anchore/sbom-action/download-syft@v0.17.0 |
| 77 | + - name: Setup GoReleaser |
| 78 | + uses: goreleaser/goreleaser-action@v6 |
| 79 | + with: |
| 80 | + install-only: true |
| 81 | + - name: Build vcluster cli |
| 82 | + run: | |
| 83 | + set -x |
| 84 | + TELEMETRY_PRIVATE_KEY="" goreleaser build --single-target --snapshot --id vcluster-cli --clean --output ./vcluster |
| 85 | + - name: Upload vcluster cli to artifact |
| 86 | + uses: actions/upload-artifact@v4 |
| 87 | + with: |
| 88 | + name: vcluster |
| 89 | + path: ./vcluster |
| 90 | + retention-days: 7 |
| 91 | + |
| 92 | + build-tests: |
| 93 | + name: Build tests binaries |
| 94 | + runs-on: ubuntu-latest |
| 95 | + steps: |
| 96 | + - name: Checkout |
| 97 | + uses: actions/checkout@v4 |
| 98 | + |
| 99 | + - name: Configure git |
| 100 | + run: git config --global url.https://$GH_ACCESS_TOKEN@github.com/.insteadOf https://github.com/ |
| 101 | + env: |
| 102 | + GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }} |
| 103 | + |
| 104 | + - name: Set up Go |
| 105 | + uses: actions/setup-go@v4 |
| 106 | + with: |
| 107 | + go-version-file: go.mod |
| 108 | + |
| 109 | + - name: Build e2e binary |
| 110 | + run: | |
| 111 | + cd ./test |
| 112 | + go run -mod=vendor github.com/onsi/ginkgo/v2/ginkgo build --require-suite -r --mod vendor $(ls -d ./deploy_changes/deploy_* | jq -R . | jq -rcs '. | join(" \\\n")') |
| 113 | + env: |
| 114 | + GOWORK: off |
| 115 | + |
| 116 | + - name: Upload test binaries to artifacts |
| 117 | + uses: actions/upload-artifact@v4 |
| 118 | + with: |
| 119 | + name: test-binaries |
| 120 | + path: test/deploy_changes/**/*.test |
| 121 | + retention-days: 7 |
| 122 | + |
| 123 | + generate-matrix: |
| 124 | + runs-on: ubuntu-latest |
| 125 | + steps: |
| 126 | + - name: Checkout code |
| 127 | + uses: actions/checkout@v4 |
| 128 | + |
| 129 | + - name: List test directories |
| 130 | + id: set-paths-matrix |
| 131 | + run: | |
| 132 | + cd ./test |
| 133 | + set -x |
| 134 | + sudo apt-get install -y jq |
| 135 | +
|
| 136 | + paths=$(ls -d ./deploy_changes/*/ | grep -v 'common/') |
| 137 | + echo "matrix=$(printf '%s\n' "${paths}" | jq -R . | jq -cs .)" >> "$GITHUB_OUTPUT" |
| 138 | +
|
| 139 | + outputs: |
| 140 | + matrix: ${{ steps.set-paths-matrix.outputs.matrix }} |
| 141 | + |
| 142 | + execute-deploy-tests: |
| 143 | + needs: |
| 144 | + - build-and-push-syncer-image |
| 145 | + - build-vcluster-cli |
| 146 | + - build-tests |
| 147 | + - generate-matrix |
| 148 | + |
| 149 | + runs-on: ubuntu-latest |
| 150 | + strategy: |
| 151 | + fail-fast: false |
| 152 | + matrix: |
| 153 | + test-suite-path: ${{ fromJson(needs.generate-matrix.outputs.matrix) }} |
| 154 | + steps: |
| 155 | + - name: Checkout repository |
| 156 | + uses: actions/checkout@v4 |
| 157 | + |
| 158 | + - uses: azure/setup-helm@v4 |
| 159 | + name: Setup Helm |
| 160 | + with: |
| 161 | + version: "v3.11.0" |
| 162 | + |
| 163 | + - name: Set up kind k8s cluster |
| 164 | + uses: engineerd/setup-kind@v0.5.0 |
| 165 | + with: |
| 166 | + version: "v0.20.0" |
| 167 | + image: kindest/node:v1.30.0@sha256:047357ac0cfea04663786a612ba1eaba9702bef25227a794b52890dd8bcd692e |
| 168 | + |
| 169 | + - name: Testing kind cluster set-up |
| 170 | + run: | |
| 171 | + set -x |
| 172 | + kubectl cluster-info |
| 173 | + kubectl get pods -n kube-system |
| 174 | + echo "kubectl config current-context:" $(kubectl config current-context) |
| 175 | + echo "KUBECONFIG env var:" ${KUBECONFIG} |
| 176 | +
|
| 177 | + - name: Download vcluster cli |
| 178 | + uses: actions/download-artifact@v4 |
| 179 | + with: |
| 180 | + name: vcluster |
| 181 | + |
| 182 | + - name: Download syncer image |
| 183 | + uses: actions/download-artifact@v4 |
| 184 | + with: |
| 185 | + name: vcluster_syncer |
| 186 | + |
| 187 | + - name: Download test binaries |
| 188 | + uses: actions/download-artifact@v4 |
| 189 | + with: |
| 190 | + name: test-binaries |
| 191 | + path: ./test/deploy_changes |
| 192 | + |
| 193 | + - name: Create vcluster |
| 194 | + id: create-vcluster |
| 195 | + run: | |
| 196 | + set -x |
| 197 | +
|
| 198 | + kind load image-archive vcluster_syncer |
| 199 | + |
| 200 | + chmod +x vcluster && sudo mv vcluster /usr/bin |
| 201 | +
|
| 202 | + cd ./test |
| 203 | +
|
| 204 | + sudo apt-get install -y sed |
| 205 | +
|
| 206 | + sed -i "s|REPLACE_REPOSITORY_NAME|${{ env.REPOSITORY_NAME }}|g" ${{ matrix.test-suite-path }}commonValues.yaml |
| 207 | + sed -i "s|REPLACE_TAG_NAME|${{ env.TAG_NAME }}|g" ${{ matrix.test-suite-path }}commonValues.yaml |
| 208 | +
|
| 209 | + vcluster create ${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} \ |
| 210 | + --create-namespace \ |
| 211 | + --debug \ |
| 212 | + --connect=false \ |
| 213 | + --local-chart-dir ../chart \ |
| 214 | + -f ${{ matrix.test-suite-path }}commonValues.yaml |
| 215 | + continue-on-error: true |
| 216 | + |
| 217 | + - name: Wait until vcluster is ready |
| 218 | + id: wait-until-vcluster-is-ready |
| 219 | + if: steps.create-vcluster.outcome == 'success' |
| 220 | + run: | |
| 221 | + set -x |
| 222 | +
|
| 223 | + ./hack/wait-for-pod.sh -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} |
| 224 | +
|
| 225 | + continue-on-error: true |
| 226 | + |
| 227 | + - name: Collect deployment information in case vcluster fails to start |
| 228 | + if: steps.wait-until-vcluster-is-ready.outcome != 'success' |
| 229 | + run: | |
| 230 | + set -x |
| 231 | + kubectl get pods -o yaml -n ${{ env.VCLUSTER_NAMESPACE }} |
| 232 | + echo "======================================================================================================================" |
| 233 | + kubectl get events -n ${{ env.VCLUSTER_NAMESPACE }} --sort-by='.lastTimestamp' |
| 234 | + echo "======================================================================================================================" |
| 235 | + kubectl logs -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} -c syncer --tail=-1 -p || kubectl logs -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} -c syncer --tail=-1 |
| 236 | + echo "======================================================================================================================" |
| 237 | + kubectl describe pods -n ${{ env.VCLUSTER_NAMESPACE }} |
| 238 | + exit 1 |
| 239 | + |
| 240 | + # Skips NetworkPolicy tests because they require network plugin with support (e.g. Calico) |
| 241 | + - name: Execute tests |
| 242 | + id: execute-tests |
| 243 | + run: | |
| 244 | + set -x |
| 245 | + |
| 246 | + cd ./test/deploy_changes |
| 247 | +
|
| 248 | + cd $(echo "${{ matrix.test-suite-path }}" | sed -e 's#^./deploy_changes/##' -e 's#/$##') |
| 249 | + |
| 250 | + sudo chmod +x $(echo "${{ matrix.test-suite-path }}" | sed -e 's#^./deploy_changes/##' -e 's#/$##').test |
| 251 | + |
| 252 | + VCLUSTER_SUFFIX=${{ env.VCLUSTER_SUFFIX }} VCLUSTER_NAME=${{ env.VCLUSTER_NAME }} VCLUSTER_NAMESPACE=${{ env.VCLUSTER_NAMESPACE }} ./$(echo "${{ matrix.test-suite-path }}" | sed -e 's#^./deploy_changes/##' -e 's#/$##').test -test.v --ginkgo.v --ginkgo.skip='.*NetworkPolicy.*' --ginkgo.fail-fast |
| 253 | + |
| 254 | + if kubectl logs -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} -c syncer --tail=-1 -p >/dev/null 2>/dev/null; then |
| 255 | + echo "vCluster has restarted during testing, failing..." |
| 256 | + exit 1 |
| 257 | + fi |
| 258 | +
|
| 259 | + continue-on-error: true |
| 260 | + |
| 261 | + - name: Print logs if tests fail |
| 262 | + if: steps.execute-tests.outcome == 'failure' |
| 263 | + run: | |
| 264 | + set -x |
| 265 | + kubectl get pods -o yaml -n ${{ env.VCLUSTER_NAMESPACE }} |
| 266 | + echo "======================================================================================================================" |
| 267 | + kubectl get events -n ${{ env.VCLUSTER_NAMESPACE }} --sort-by='.lastTimestamp' |
| 268 | + echo "======================================================================================================================" |
| 269 | + kubectl logs -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} -c syncer --tail=-1 -p || kubectl logs -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} -c syncer --tail=-1 |
| 270 | + echo "======================================================================================================================" |
| 271 | + kubectl describe pods -n ${{ env.VCLUSTER_NAMESPACE }} |
| 272 | + exit 1 |
| 273 | +
|
0 commit comments