Skip to content

Commit

Permalink
Added pre-main e2e jobs with lifecycle-manager (#81)
Browse files Browse the repository at this point in the history
Added pre-main e2e job with lifecycle-manager
  • Loading branch information
mfaizanse authored Jul 18, 2023
1 parent 7804ed1 commit 9241d3b
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 7 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ jobs:
make install IMG=$DOCKER_IMAGE
- name: Wait for the 'pull-nats-manager-build' job to succeed
uses: lewagon/wait-on-check-action@v1.3.1
uses: mfaizanse/wait-for-git-commit-status-action@v1.0.6
with:
ref: ${{ github.ref }}
running-workflow-name: 'pull-nats-manager-build'
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 10
allowed-conclusions: success
verbose: false # change for debugging
context: "pull-nats-manager-build"
commit_ref: "${{ github.event.pull_request.head.sha }}" # Note: 'github.event.pull_request.head.sha' is not same as 'github.sha' on pull requests.
timeout: 600000 # 10 minutes in milliseconds
# The check interval is kept long otherwise it will exhaust the GitHub rate limit (More info: https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#rate-limiting)
check_interval: 60000 # 1 minute in milliseconds
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
GITHUB_OWNER: "${{ github.repository_owner }}"
GITHUB_REPO: "nats-manager"

- name: Create kyma-system namespace
run: |
Expand Down
94 changes: 94 additions & 0 deletions .github/workflows/pull-with-lifecycle-manager.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: pull-with-lifecycle-manager

env:
DOCKER_IMAGE: europe-docker.pkg.dev/kyma-project/dev/nats-manager:PR-${{ github.event.number }}
E2E_LOG_LEVEL: debug
KYMA_STABILITY: "unstable"
KYMA: "./hack/kyma"

on:
pull_request:
branches: [ "main" ]

jobs:
e2e:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install k3d tools
uses: nolar/setup-k3d-k3s@v1
with:
# This is the Kubernetes version used by k3d. See https://kubernetes.io/releases/
version: v1.26.5
skip-creation: true

- name: Install Kyma CLI & setup k3d cluster using kyma CLI
run: |
make kyma
make -C hack/ci/ create-k3d
kubectl version
kubectl cluster-info
- name: Deploy lifecycle-manager
run: |
make -C hack/ci/ install-lifecycle-manager
- name: Wait for the 'pull-nats-manager-build' job to succeed
uses: mfaizanse/[email protected]
with:
context: "pull-nats-manager-build"
commit_ref: "${{ github.event.pull_request.head.sha }}" # Note: 'github.event.pull_request.head.sha' is not same as 'github.sha' on pull requests.
timeout: 600000 # 10 minutes in milliseconds
# The check interval is kept long otherwise it will exhaust the GitHub rate limit (More info: https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#rate-limiting)
check_interval: 60000 # 1 minute in milliseconds
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
GITHUB_OWNER: "${{ github.repository_owner }}"
GITHUB_REPO: "nats-manager"

- name: Wait for the 'pull-nats-module-build' job to succeed
id: wait-nats-module-build
uses: mfaizanse/[email protected]
with:
context: "pull-nats-module-build"
commit_ref: "${{ github.event.pull_request.head.sha }}" # Note: 'github.event.pull_request.head.sha' is not same as 'github.sha' on pull requests.
timeout: 600000 # 10 minutes in milliseconds
# The check interval is kept long otherwise it will exhaust the GitHub rate limit (More info: https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#rate-limiting)
check_interval: 60000 # 1 minute in milliseconds
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
GITHUB_OWNER: "${{ github.repository_owner }}"
GITHUB_REPO: "nats-manager"

- name: Download & validate NATS module template
env:
PR_NUMBER: "${{ github.event.number }}"
COMMIT_STATUS_JSON: "${{ steps.wait-nats-module-build.outputs.json }}"
run: |
make -C hack/ci/ download-module-template
kubectl apply -f module-template.yaml --dry-run=client
- name: Install & enabled NATS module template
run: |
make -C hack/ci/ install-module-template
make -C hack/ci/ enable-module-without-default-cr
- name: Setup and test NATS CR
run: |
make e2e-setup
- name: Run NATS bench
run: |
go install github.com/nats-io/natscli/nats@latest
export PATH=$HOME/go/bin:$PATH
make e2e-bench
- name: Test NATS-server
run: |
make e2e-nats-server
- name: Cleanup NATS CR
run: |
make e2e-cleanup
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ bin/*

# Vendor
vendor/

module-template.yaml
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ $(KYMA):
## Downloading Kyma CLI: https://storage.googleapis.com/kyma-cli-$(KYMA_STABILITY)/$(KYMA_FILE_NAME)
test -f $@ || curl -s -Lo $(KYMA) https://storage.googleapis.com/kyma-cli-$(KYMA_STABILITY)/$(KYMA_FILE_NAME)
chmod 0100 $(KYMA)
${KYMA} version -c

# e2e testing is done here
.PHONY: e2e-setup
Expand Down
29 changes: 29 additions & 0 deletions hack/ci/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
PROJECT_ROOT ?= ../..
KYMA_CLI ?= "${PROJECT_ROOT}/${KYMA}"
CLUSTER_NAME ?= kyma
REGISTRY_PORT ?= 5001

include ${PROJECT_ROOT}/.env

Expand All @@ -18,3 +21,29 @@ module-build: ## Build the Module, push it to a registry and print it based on t
@cat ${ARTIFACTS}/module-template.yaml
@echo "\n~~~~~~~~~~~~~~~END OF MODULE TEMPLATE~~~~~~~~~~~~~~~~"

.PHONY: download-module-template
download-module-template: ## Downloads the module-template from the module-build prow job.
export PROJECT_ROOT="${PROJECT_ROOT}" \
&& ../get_module_template_from_build_job.sh

.PHONY: create-kyma-system-ns
create-kyma-system-ns: ## Create kyma-system namespace.
kubectl create ns kyma-system

.PHONY: install-module-template
install-module-template: ## Apply NATS moduletemplate.
kubectl apply -f ${PROJECT_ROOT}/module-template.yaml

.PHONY: enable-module-without-default-cr
enable-module-without-default-cr: ## Enable NATS module without creating default NATS CR.
"${KYMA_CLI}" alpha enable module nats -c fast -n kyma-system -p Ignore

.PHONY: install-lifecycle-manager
install-lifecycle-manager: ## Deploys lifecycle-manager.
"${KYMA_CLI}" alpha deploy \
--ci \
--force-conflicts

.PHONY: create-k3d
create-k3d: ## Create k3d with kyma CRDs.
"${KYMA_CLI}" provision k3d -p 8081:80@loadbalancer -p 8443:443@loadbalancer --registry-port ${REGISTRY_PORT} --name ${CLUSTER_NAME} --ci
41 changes: 41 additions & 0 deletions hack/get_module_template_from_build_job.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

## This script requires the following env variables:
# PR_NUMBER (e.g. 82)
# COMMIT_STATUS_JSON
# PROJECT_ROOT (e.g. "../")

# Example of `COMMIT_STATUS_JSON`
# {
# "url": "https://api.github.com/repos/kyma-project/nats-manager/statuses/12345678765432345676543",
# "avatar_url": "https://avatars.githubusercontent.com/u/123456",
# "id": 123456789,
# "node_id": "SC_kwDOJBeAG123456789",
# "state": "success",
# "description": "Job succeeded.",
# "target_url": "https://status.build.kyma-project.io/view/gs/kyma-prow-logs/pr-logs/pull/kyma-project_nats-manager/81/pull-nats-module-build/123456789",
# "context": "pull-nats-module-build",
# "created_at": "2023-07-18T11:39:23Z",
# "updated_at": "2023-07-18T11:39:23Z"
# }

## define variables
MODULE_TEMPLATE_FILE="${PROJECT_ROOT}/module-template.yaml"
ARTIFACTS_BASE_URL="https://gcsweb.build.kyma-project.io/gcs/kyma-prow-logs/pr-logs/pull/kyma-project_nats-manager"
TEMPLATE_FILE_BASE_URL="${ARTIFACTS_BASE_URL}/${PR_NUMBER}/pull-nats-module-build"

### Extract the prow job ID.
echo "Extracting prow job Id from: ${COMMIT_STATUS_JSON}"
TARGET_URL=$(echo ${COMMIT_STATUS_JSON} | jq -r '.target_url')
PROW_JOB_ID=$(echo ${TARGET_URL##*/})
echo "Prow Job ID: ${PROW_JOB_ID}, Link: ${TARGET_URL}"

## Download the module-template.yaml from the build job.
TEMPLATE_FILE_URL="${TEMPLATE_FILE_BASE_URL}/${PROW_JOB_ID}/artifacts/module-template.yaml"
echo "Downloading ${MODULE_TEMPLATE_FILE} from: ${TEMPLATE_FILE_URL}"
curl -s -L -o ${MODULE_TEMPLATE_FILE} ${TEMPLATE_FILE_URL}

## print the module-template.yaml
echo "~~~~~~~~~~~~BEGINNING OF MODULE TEMPLATE~~~~~~~~~~~~~~"
cat ${MODULE_TEMPLATE_FILE}
echo "~~~~~~~~~~~~~~~END OF MODULE TEMPLATE~~~~~~~~~~~~~~~~"

0 comments on commit 9241d3b

Please sign in to comment.