ci: agent policy process unit test #3807
Workflow file for this run
This file contains 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: ci | |
on: | |
pull_request: | |
branches: | |
- '**' | |
push: | |
branches: [ main, release-1.0 ] | |
schedule: | |
# 7:00 UTC+8 | |
- cron: "0 23 * * *" | |
jobs: | |
build-unit-test-image: | |
runs-on: [self-hosted, build] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: build unit-test image | |
uses: docker/build-push-action@v4 | |
with: | |
file: build/images/unit-test/Dockerfile | |
tags: registry.smtx.io/everoute/unit-test | |
context: ./build/images/unit-test/ | |
push: true | |
pr-check: | |
needs: [build-unit-test-image, static-check, generate-check] | |
runs-on: [self-hosted, pod] | |
strategy: | |
matrix: | |
act: [docker-test-ci, docker-race-test-ci, docker-cover-test-ci] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: run everoute unit test | |
run: make ${{ matrix.act }} | |
- uses: codecov/codecov-action@v2 | |
with: | |
files: ./coverage.out | |
static-check: | |
runs-on: [ubuntu-20.04] | |
steps: | |
- uses: actions/setup-go@v3 | |
with: | |
go-version: '1.20' | |
- uses: actions/checkout@v2 | |
- name: Check conventional commits | |
uses: webiny/action-conventional-commits@v1.1.0 | |
- name: Check spelling | |
uses: crate-ci/typos@v1.0.4 | |
- name: Check golang lint | |
# skip it for branch main can't pass this check | |
if: ${{ github.event_name == 'pull_request' }} | |
uses: golangci/golangci-lint-action@v3 | |
with: | |
version: v1.53 | |
only-new-issues: true | |
# skip cache because of flaky behaviors | |
skip-build-cache: true | |
skip-pkg-cache: true | |
run-e2e: | |
runs-on: [ubuntu-20.04] | |
needs: [static-check, generate-check, pr-check] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: run everoute e2e test | |
run: sudo make docker-e2e-test | |
build-k8s-e2e-image: | |
runs-on: [self-hosted, build] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: build everoute image | |
uses: docker/build-push-action@v4 | |
with: | |
file: build/images/release/Dockerfile | |
tags: registry.smtx.io/everoute/everoute_release:${{ github.sha }} | |
context: . | |
push: true | |
run-k8s-e2e: | |
needs: [build-k8s-e2e-image, static-check, generate-check, pr-check] | |
strategy: | |
fail-fast: false | |
matrix: | |
enable-proxy: [true, false] | |
encap-mode: ["", geneve] | |
include: | |
- ipam: "everoute" | |
enable-proxy: true | |
encap-mode: "geneve" | |
runs-on: [self-hosted, pod-k8s-e2e-v2] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: config PATH | |
run: | | |
mkdir -p /runner/_work/bin/ | |
echo "/runner/_work/bin/" >> $GITHUB_PATH | |
- name: set env | |
run: | | |
echo "PoolName=$PoolName" >> $GITHUB_ENV | |
echo "Tmpl=$Tmpl" >> $GITHUB_ENV | |
- name: install helm | |
run: cp /home/runner/tool/helm /runner/_work/bin/ | |
- name: install k8se2e binary | |
run: sudo mkdir -p /runner/_work/everoute/everoute/k8se2e && sudo cp -r /home/runner/k8se2e/bin/ /runner/_work/everoute/everoute/k8se2e/bin/ | |
- name: generate everoute cni deploy yaml | |
run: helm template deploy/chart -n ci-deploy-cni --set CNIConf.encapMode=${{ matrix.encap-mode }},CNIConf.enableProxy=${{ matrix.enable-proxy }},CNIConf.ipam=${{ matrix.ipam }},image.repository=registry.smtx.io/everoute/everoute_release,image.tag=${{ github.sha }} > deploy/everoute.yaml | |
- name: test kubectl connect to sks | |
run: kubectl get crd --kubeconfig /home/runner/sksconfig/sksconfig | grep smart | |
- name: allocate cluster vip | |
run: | | |
out=$(curl -X POST 'https://ip.dev.smtx.io/v1/ips?name=${{ env.PoolName }}') | |
success=$(echo $out | grep "fullSuccess" |wc -l) | |
if [ $success != 1 ]; then exit 1; fi | |
ipright=${out#*\"ips\":[\"} | |
ip=${ipright%\"],\"ipNets\"*} | |
echo "VIP=$ip" >> $GITHUB_ENV | |
- name: gen k8s cluster name | |
run: echo "CLUSTER_NAME=k8s-e2e-$RANDOM" >> $GITHUB_ENV | |
- name: create k8s cluster... | |
run: | | |
echo "new k8s cluster name is ${{ env.CLUSTER_NAME }}" | |
sed -i s/{{k8s-e2e-cluster-name}}/${{ env.CLUSTER_NAME }}/g hack/${{ env.Tmpl }} | |
echo "k8s cluster vip is ${{ env.VIP }}" | |
sed -i s/{{k8s-e2e-cluster-vip}}/${{ env.VIP }}/g hack/${{ env.Tmpl }} | |
kubectl --v=9 apply -f hack/${{ env.Tmpl }} --kubeconfig /home/runner/sksconfig/sksconfig | |
kubectl --kubeconfig /home/runner/sksconfig/sksconfig wait --for=jsonpath='{.status.controlPlaneAvailable}'=true KubeSmartCluster/${{ env.CLUSTER_NAME }} --timeout=10m | |
- name: get new k8s cluster kubeconfig and test connection | |
run: | | |
kubectl --kubeconfig /home/runner/sksconfig/sksconfig get secret ${{ env.CLUSTER_NAME }}-kubeconfig -o template --template={{.data.value}} > rawkubeconfig | |
mkdir -p $HOME/.kube | |
base64 --decode rawkubeconfig > $HOME/.kube/config | |
kubectl version | |
- name: delete control plane node taint | |
run: | | |
kubectl taint node node-role.kubernetes.io/control-plane=:NoSchedule --all --overwrite=true | |
kubectl taint node node-role.kubernetes.io/control-plane=:NoSchedule- --all | |
kubectl taint node node-role.kubernetes.io/master=:NoSchedule --all --overwrite=true | |
kubectl taint node node-role.kubernetes.io/master=:NoSchedule- --all | |
- name: deploy everoute cni | |
run: | | |
kubectl create ns ci-deploy-cni | |
kubectl apply -f deploy/chart/templates/crds/ipam.everoute.io_ippools.yaml | |
echo "wait ippool crd install" && sleep 5 | |
kubectl apply -f hack/ippool_ci.yaml | |
kubectl apply -f deploy/everoute.yaml | |
- name: wait k8s cluster ready | |
timeout-minutes: 10 | |
run: | | |
kubectl --kubeconfig /home/runner/sksconfig/sksconfig wait --for=jsonpath='{.status.phase}'=Ready KubeSmartCluster/${{ env.CLUSTER_NAME }} --timeout=10m | |
mastercount=$(kubectl --kubeconfig /home/runner/sksconfig/sksconfig get ksc ${{ env.CLUSTER_NAME }} -o template --template={{.status.controlPlanes.totalCount}}) | |
workercount=$(kubectl --kubeconfig /home/runner/sksconfig/sksconfig get ksc ${{ env.CLUSTER_NAME }} -o template --template={{.status.workers.totalCount}}) | |
echo "mastercount: $mastercount, workercount: $workercount" | |
kubectl --kubeconfig /home/runner/sksconfig/sksconfig wait --for=jsonpath='{.status.controlPlanes.readyCount}'=$mastercount KubeSmartCluster/${{ env.CLUSTER_NAME }} --timeout=2m | |
kubectl --kubeconfig /home/runner/sksconfig/sksconfig wait --for=jsonpath='{.status.workers.readyCount}'=$workercount KubeSmartCluster/${{ env.CLUSTER_NAME }} --timeout=10m | |
kubectl wait --for=condition=Ready nodes --all --timeout=10m | |
kubectl wait --for=condition=Ready pods --all -A --timeout=5m | |
kubectl --kubeconfig /home/runner/sksconfig/sksconfig get ksc ${{ env.CLUSTER_NAME }} | |
kubectl get nodes -owide | |
- name: run ServiceProxy cases | |
if: matrix.enable-proxy == true | |
timeout-minutes: 20 | |
run: ./k8se2e/bin/ginkgo -nodes=5 --skip="NodePort|SCTP|hairpin|ProxyTerminatingEndpoints|rejected|IPv6|Networking" --focus="Services" ./k8se2e/bin/e2e.test -- --disable-log-dump --provider="skeleton" --kubeconfig=/home/runner/.kube/config | |
- name: run NetworkPolicy case | |
timeout-minutes: 25 | |
run: ./k8se2e/bin/ginkgo -nodes=10 --skip="SCTP" --focus="NetworkPolicy" ./k8se2e/bin/e2e.test -- --disable-log-dump --provider="skeleton" --kubeconfig=/home/runner/.kube/config | |
- name: delete test k8s cluster | |
id: delenv | |
if: ${{ always() }} | |
run: kubectl --kubeconfig /home/runner/sksconfig/sksconfig delete -f hack/${{ env.Tmpl }} | |
- name: recycle vip | |
if: ${{ always() && steps.delenv.conclusion == 'success' }} | |
run: curl -X DELETE "https://ip.dev.smtx.io/v1/ips?name="${{ env.PoolName }}"&ip="${{ env.VIP }} | |
# run-tower-e2e: | |
# runs-on: [self-hosted, tower] | |
# needs: [static-check, generate-check] | |
# steps: | |
# - uses: actions/checkout@v3 | |
# # TODO: Not implemented | |
# # - name: reset environment | |
# # - name: build everoute | |
# # - name: install everoute | |
# # - name: setup environment | |
# - name: skip-known-bugs | |
# run: git am -s < hack/0001-Skip-known-bugs-in-everoute-1.1.0.patch | |
# - name: run test cases | |
# run: sudo go test ./tests/e2e/cases/. -v --count=1 --timeout=1h | |
generate-check: | |
runs-on: [ubuntu-20.04] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: make docker-generate | |
run: sudo sh -c "make image-generate && make docker-generate" | |
- name: check if code changes | |
run: sudo sh -c "git add -A && git diff HEAD --exit-code" | |
- name: show message if failed | |
if: ${{ failure() }} | |
run: echo "::error::Please run \"make generate\" or \"make docker-generate\" before commit." | |
slack-notification: | |
if: ${{ always() }} | |
needs: [ pr-check,static-check,run-e2e,run-k8s-e2e,generate-check ] | |
runs-on: [ ubuntu-20.04 ] | |
env: | |
SLACK_COLOR: 2EA44F | |
RESULT_PR_CHECK: ":white_check_mark:" | |
RESULT_STATIC_CHECK: ":white_check_mark:" | |
RESULT_RUN_E2E: ":white_check_mark:" | |
RESULT_RUN_K8S_E2E: ":white_check_mark:" | |
RESULT_RUN_TOWER_E2E: ":white_check_mark:" | |
RESULT_GENERATE_CHECK: ":white_check_mark:" | |
steps: | |
- if: ${{ needs.pr-check.result == 'failure'}} | |
run: echo "SLACK_COLOR=DF0000" >> $GITHUB_ENV && echo "RESULT_PR_CHECK=:x:" >> $GITHUB_ENV | |
- if: ${{ needs.static-check.result == 'failure'}} | |
run: echo "SLACK_COLOR=DF0000" >> $GITHUB_ENV && echo "RESULT_STATIC_CHECK=:x:" >> $GITHUB_ENV | |
- if: ${{ needs.run-e2e.result == 'failure'}} | |
run: echo "SLACK_COLOR=DF0000" >> $GITHUB_ENV && echo "RESULT_RUN_E2E=:x:" >> $GITHUB_ENV | |
- if: ${{ needs.run-k8s-e2e.result == 'failure'}} | |
run: echo "SLACK_COLOR=DF0000" >> $GITHUB_ENV && echo "RESULT_RUN_K8S_E2E=:x:" >> $GITHUB_ENV | |
- if: ${{ needs.run-tower-e2e.result == 'failure'}} | |
run: echo "SLACK_COLOR=DF0000" >> $GITHUB_ENV && echo "RESULT_RUN_TOWER_E2E=:x:" >> $GITHUB_ENV | |
- if: ${{ needs.generate-check.result == 'failure'}} | |
run: echo "SLACK_COLOR=DF0000" >> $GITHUB_ENV && echo "RESULT_GENERATE_CHECK=:x:" >> $GITHUB_ENV | |
- if: ${{ needs.pr-check.result == 'cancelled'}} | |
run: echo "RESULT_PR_CHECK=:ballot_box_with_check:" >> $GITHUB_ENV | |
- if: ${{ needs.static-check.result == 'cancelled'}} | |
run: echo "RESULT_STATIC_CHECK=:ballot_box_with_check:" >> $GITHUB_ENV | |
- if: ${{ needs.run-e2e.result == 'cancelled'}} | |
run: echo "RESULT_RUN_E2E=:ballot_box_with_check:" >> $GITHUB_ENV | |
- if: ${{ needs.run-k8s-e2e.result == 'cancelled'}} | |
run: echo "RESULT_RUN_K8S_E2E=:ballot_box_with_check:" >> $GITHUB_ENV | |
- if: ${{ needs.run-tower-e2e.result == 'cancelled'}} | |
run: echo "RESULT_RUN_TOWER_E2E=:ballot_box_with_check:" >> $GITHUB_ENV | |
- if: ${{ needs.generate-check.result == 'cancelled'}} | |
run: echo "RESULT_GENERATE_CHECK=:ballot_box_with_check:" >> $GITHUB_ENV | |
- name: generate short commit sha | |
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-7`" >> $GITHUB_ENV | |
- name: send message to slack | |
uses: slackapi/slack-github-action@v1.17.0 | |
with: | |
payload: | | |
{ | |
"blocks": [ | |
{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": "Finish Github Action CI, details <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | `here`>" | |
} | |
} | |
], | |
"attachments": [ | |
{ | |
"color": "${{ env.SLACK_COLOR }}", | |
"blocks": [ | |
{"type": "section","fields": [ | |
{ | |
"type": "mrkdwn", | |
"text": "*type: * ${{ github.event_name }}" | |
}, | |
{ | |
"type": "mrkdwn", | |
"text": "*ref: * ${{ github.ref }}" | |
}, | |
{ | |
"type": "mrkdwn", | |
"text": "*actor: * <${{ github.server_url }}/${{ github.actor }} | `${{ github.actor }}`>" | |
}, | |
{ | |
"type": "mrkdwn", | |
"text": "*commit: * <${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} | `${{ env.SHORT_SHA }}`>" | |
} | |
]}, | |
{"type": "section","fields": [ | |
{ | |
"type": "mrkdwn", | |
"text": "${{ env.RESULT_PR_CHECK }} => *pr-check*" | |
}, | |
{ | |
"type": "mrkdwn", | |
"text": "${{ env.RESULT_STATIC_CHECK }} => *static-check*" | |
}, | |
{ | |
"type": "mrkdwn", | |
"text": "${{ env.RESULT_RUN_E2E }} => *run-e2e*" | |
}, | |
{ | |
"type": "mrkdwn", | |
"text": "${{ env.RESULT_RUN_K8S_E2E }} => *run-k8s-e2e*" | |
}, | |
{ | |
"type": "mrkdwn", | |
"text": "${{ env.RESULT_RUN_TOWER_E2E }} => *run-tower-e2e*" | |
}, | |
{ | |
"type": "mrkdwn", | |
"text": "${{ env.RESULT_GENERATE_CHECK }} => *generate-check*" | |
} | |
]} | |
] | |
} | |
] | |
} | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_E2E_URL }} | |
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK |