From bbbfcd66fbc471c9ba814469d8cb43ba087c9f22 Mon Sep 17 00:00:00 2001 From: Heba Elayoty Date: Thu, 8 Sep 2022 15:31:49 -0700 Subject: [PATCH] Update package setup for e2e pipeline --- .github/workflows/chart.yml | 2 +- .github/workflows/create-release.yml | 2 +- .github/workflows/e2e-tests.yml | 33 ++++++------------ .github/workflows/publish-images.yml | 50 ++++++++++++++++++++++++++++ Makefile | 6 ++-- hack/e2e/aks.sh | 36 ++++++++++++++++++-- 6 files changed, 99 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/publish-images.yml diff --git a/.github/workflows/chart.yml b/.github/workflows/chart.yml index 20247c45..b5e24d38 100644 --- a/.github/workflows/chart.yml +++ b/.github/workflows/chart.yml @@ -9,7 +9,7 @@ on: - "charts/**" create: # Publish semver tags as releases. - tags: [ 'v*.*.*' ] + tags: [ 'v*.*.*.*' ] permissions: contents: write diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index 2afac217..4e0bac8c 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -2,7 +2,7 @@ name: create_release on: create: # Publish semver tags as releases. - tags: [ 'v*.*.*' ] + tags: [ 'v*.*.*.*' ] permissions: contents: write diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index f7942f3e..64bb8df9 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -9,9 +9,8 @@ on: paths-ignore: [ docs/**, "**.md", "**.mdx", "**.png", "**.jpg" ] permissions: - id-token: write - contents: read - packages: write + id-token: write + contents: read env: REGISTRY: ghcr.io @@ -48,6 +47,7 @@ jobs: env: REGISTRY: ${{ needs.export-registry.outputs.registry }} E2E_IMG_TAG: "e2e-ci" + PR_COMMIT_REF: ${{ github.event.pull_request.head.ref }} runs-on: ubuntu-latest steps: - name: Set up Go @@ -57,29 +57,20 @@ jobs: - name: Checkout uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} - name: Set e2e Cluster Name run: | rand=$RANDOM echo "CLUSTER_NAME=vk-aci-test-${rand}" >> $GITHUB_ENV - - name: Login to ${{ env.REGISTRY }} - uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build image - run: | - OUTPUT_TYPE=type=registry make docker-build-image - env: - VERSION: ${{ env.E2E_IMG_TAG}} - - name: Install Azure CLI latest run: | curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash az version + - uses: azure/login@v1.4.5 with: client-id: ${{ secrets.CLIENTID }} @@ -88,21 +79,17 @@ jobs: - name: Run e2e test run: | - make e2e-test + OUTPUT_TYPE=type=registry make e2e-test env: REGISTRY: ${{ env.REGISTRY}} E2E_REGION: ${{ secrets.E2E_REGION}} CLUSTER_NAME: ${{ env.CLUSTER_NAME }} VERSION: ${{ env.E2E_IMG_TAG}} + E2E_TARGET: "pr" + PR_COMMIT_REF: ${{ env.PR_COMMIT_REF }} - name: Cleanup e2e resources if: ${{ always() }} run: | set +e az group delete --name "${{ env.CLUSTER_NAME }}" --yes --no-wait || true - - - uses: actions/delete-package-versions@v3 - if: ${{ always() }} - with: - package-name: 'virtual-kubelet' - token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/publish-images.yml b/.github/workflows/publish-images.yml new file mode 100644 index 00000000..7577be25 --- /dev/null +++ b/.github/workflows/publish-images.yml @@ -0,0 +1,50 @@ +name: publish_images + +on: + create: + # Publish semver tags as releases. + tags: [ 'v*.*.*.*' ] + +permissions: + contents: read + packages: write + +env: + REGISTRY: ghcr.io + IMAGE_NAME: virtual-kubelet + +jobs: + export-registry: + runs-on: ubuntu-20.04 + needs: detect-noop + if: needs.detect-noop.outputs.noop != 'true' + outputs: + registry: ${{ steps.export.outputs.registry }} + steps: + - id: export + run: | + # registry must be in lowercase + echo "::set-output name=registry::$(echo "${{ env.REGISTRY }}/${{ github.repository }}" | tr [:upper:] [:lower:])" + + publish-images: + needs: export-registry + env: + REGISTRY: ${{ needs.export-registry.outputs.registry }} + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + with: + submodules: true + fetch-depth: 0 + - name: Login to ${{ env.REGISTRY }} + uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build image + run: | + OUTPUT_TYPE=type=registry make docker-build-image + env: + VERSION: ${{ env.E2E_IMG_TAG}} diff --git a/Makefile b/Makefile index 85504286..53a98f62 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ TEST_LOGANALYTICS_JSON ?= $(TEST_CREDENTIALS_DIR)/loganalytics.json export TEST_CREDENTIALS_JSON TEST_LOGANALYTICS_JSON IMG_NAME ?= virtual-kubelet -IMG_REPO ?= $(REGISTRY)/$(IMG_NAME) +IMAGE ?= $(REGISTRY)/$(IMG_NAME) LOCATION := $(E2E_REGION) E2E_CLUSTER_NAME := $(CLUSTER_NAME) @@ -59,7 +59,7 @@ docker-build-image: docker-buildx-builder --output=$(OUTPUT_TYPE) \ --platform="$(BUILDPLATFORM)" \ --pull \ - --tag $(IMG_REPO):$(IMG_TAG) . + --tag $(IMAGE):$(IMG_TAG) . .PHONY: build build: bin/virtual-kubelet @@ -80,7 +80,7 @@ test: .PHONY: e2e-test e2e-test: - IMG_URL=$(REGISTRY) IMG_REPO=$(IMG_NAME) IMG_TAG=$(IMG_TAG) LOCATION=$(LOCATION) RESOURCE_GROUP=$(E2E_CLUSTER_NAME) $(AKS_E2E_SCRIPT) go test -timeout 30m -v ./e2e + PR_RAND=$(PR_COMMIT_REF) E2E_TARGET=$(E2E_TARGET) IMG_URL=$(REGISTRY) IMG_REPO=$(IMG_NAME) IMG_TAG=$(IMG_TAG) LOCATION=$(LOCATION) RESOURCE_GROUP=$(E2E_CLUSTER_NAME) $(AKS_E2E_SCRIPT) go test -timeout 30m -v ./e2e .PHONY: vet vet: diff --git a/hack/e2e/aks.sh b/hack/e2e/aks.sh index f09ea698..740e0982 100755 --- a/hack/e2e/aks.sh +++ b/hack/e2e/aks.sh @@ -13,7 +13,12 @@ if ! type go > /dev/null; then exit 1 fi -: "${RANDOM_NUM:=$RANDOM}" +: "${RANDOM_NUM:=${PR_RAND}}" + +if [ "$PR_RAND" = "" ]; then + RANDOM_NUM=$RANDOM +fi + : "${RESOURCE_GROUP:=vk-aci-test-$RANDOM_NUM}" : "${LOCATION:=westus2}" : "${CLUSTER_NAME:=${RESOURCE_GROUP}}" @@ -29,7 +34,7 @@ fi : "${VNET_NAME=myAKSVNet}" : "${CLUSTER_SUBNET_NAME=myAKSSubnet}" : "${ACI_SUBNET_NAME=myACISubnet}" - +: "${ACR_NAME=vkacr$RANDOM_NUM}" : "${CSI_DRIVER_STORAGE_ACCOUNT_NAME=vkcsidrivers$RANDOM_NUM}" : "${CSI_DRIVER_SHARE_NAME=vncsidriversharename}" @@ -68,6 +73,16 @@ fi az group create --name "$RESOURCE_GROUP" --location "$LOCATION" +if [ "$E2E_TARGET" = "pr" ]; then + az acr create --resource-group "$RESOURCE_GROUP" \ + --name "$ACR_NAME" --sku Basic + + az acr login --name "$ACR_NAME" + IMG_URL=$ACR_NAME.azurecr.io + IMG_REPO="virtual-kubelet" + OUTPUT_TYPE=type=registry IMG_TAG=$IMG_TAG IMAGE=$ACR_NAME.azurecr.io/$IMG_REPO make docker-build-image + +fi KUBE_DNS_IP=10.0.0.10 @@ -95,6 +110,23 @@ node_identity="$(az identity create --name "${RESOURCE_GROUP}-node-identity" --r node_identity_id="$(az identity show --name ${RESOURCE_GROUP}-node-identity --resource-group ${RESOURCE_GROUP} --query id -o tsv)" cluster_identity_id="$(az identity show --name ${RESOURCE_GROUP}-aks-identity --resource-group ${RESOURCE_GROUP} --query id -o tsv)" + +if [ "$E2E_TARGET" = "pr" ]; then +az aks create \ + -g "$RESOURCE_GROUP" \ + -l "$LOCATION" \ + -c "$NODE_COUNT" \ + --node-vm-size standard_d8_v3 \ + -n "$CLUSTER_NAME" \ + --network-plugin azure \ + --vnet-subnet-id "$aks_subnet_id" \ + --dns-service-ip "$KUBE_DNS_IP" \ + --assign-kubelet-identity "$node_identity_id" \ + --assign-identity "$cluster_identity_id" \ + --generate-ssh-keys \ + --attach-acr "$ACR_NAME" +fi + az aks create \ -g "$RESOURCE_GROUP" \ -l "$LOCATION" \