From 3aa8d5833edca25e47156f92daeb2b952fcc3ae2 Mon Sep 17 00:00:00 2001 From: "Kwiatosz, Krzysztof" Date: Mon, 13 Jan 2025 16:20:53 +0100 Subject: [PATCH] kyma CLI e2e test on k3d --- .github/actions/setup-go/action.yaml | 11 +++++ .github/workflows/pull.yaml | 26 ++++++++++ Makefile | 7 +++ tests/btp/Makefile | 3 ++ tests/btp/integration-test-btp.sh | 37 ++++++++++++++ .../exposed-docker-registry.yaml | 7 +++ tests/k3d/Makefile | 3 ++ tests/k3d/integration-test-k3d.sh | 48 +++++++++++++++++++ tests/k3d/sample-go/go.mod | 3 ++ tests/k3d/sample-go/main.go | 20 ++++++++ 10 files changed, 165 insertions(+) create mode 100644 .github/actions/setup-go/action.yaml create mode 100644 .github/workflows/pull.yaml create mode 100644 tests/btp/Makefile create mode 100755 tests/btp/integration-test-btp.sh create mode 100644 tests/btp/k8s-resources/exposed-docker-registry.yaml create mode 100644 tests/k3d/Makefile create mode 100755 tests/k3d/integration-test-k3d.sh create mode 100644 tests/k3d/sample-go/go.mod create mode 100644 tests/k3d/sample-go/main.go diff --git a/.github/actions/setup-go/action.yaml b/.github/actions/setup-go/action.yaml new file mode 100644 index 000000000..6da4bba61 --- /dev/null +++ b/.github/actions/setup-go/action.yaml @@ -0,0 +1,11 @@ +name: "Setup go" +description: "Action for the go setup" + +runs: + using: "composite" + steps: + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + cache-dependency-path: "go.sum" \ No newline at end of file diff --git a/.github/workflows/pull.yaml b/.github/workflows/pull.yaml new file mode 100644 index 000000000..ce20d2a80 --- /dev/null +++ b/.github/workflows/pull.yaml @@ -0,0 +1,26 @@ +name: pull + +on: + pull_request_target: + types: [ opened, edited, synchronize, reopened, ready_for_review ] + +jobs: + e2e-test-k3d: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + - uses: ./.github/actions/setup-go + - name: ensure pack + run: | + if ! which pack; then + echo "Installing pack..." + (curl -sSL "https://github.com/buildpacks/pack/releases/download/v0.36.0/pack-v0.36.0-linux.tgz" | sudo tar -C /usr/local/bin/ --no-same-owner -xzv pack) + fi + - name: build kyma@v3 binary + run: make build + - uses: kyma-project/serverless/.github/actions/create-k3d-cluster@9e8c091842e5c884e1770ef0bcc5b4b4d2894b74 + - name: test + run: make -C tests/k3d e2e-test \ No newline at end of file diff --git a/Makefile b/Makefile index 162f94821..f9feb53a5 100644 --- a/Makefile +++ b/Makefile @@ -24,3 +24,10 @@ test: ## Run unit tests. .PHONY: lint lint: golangci-lint ## Run golangci-lint. $(GOLANGCI_LINT) run -v + +.PHONY: build +build: + go build -o bin/kyma@v3 main.go + + + diff --git a/tests/btp/Makefile b/tests/btp/Makefile new file mode 100644 index 000000000..ac09ccde5 --- /dev/null +++ b/tests/btp/Makefile @@ -0,0 +1,3 @@ +.PHONY: e2e-test +e2e-test: + ./integration-test-btp.sh \ No newline at end of file diff --git a/tests/btp/integration-test-btp.sh b/tests/btp/integration-test-btp.sh new file mode 100755 index 000000000..0f3d71226 --- /dev/null +++ b/tests/btp/integration-test-btp.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +echo "Running kyma@v3 integration tests uing connected managed kyma runtime" + +# ------------------------------------------------------------------------------------- +echo "Step1: Generating temporary access for new service account" + +../../bin/kyma@v3 alpha access --clusterrole cluster-admin --name test-sa --output /tmp/kubeconfig.yaml --time 2h + +export KUBECONFIG="/tmp/kubeconfig.yaml" +if [[ $(kubectl config view --minify --raw | yq '.users[0].name') != 'test-sa' ]]; then + exit 1 +fi +echo "Running test in user context of: $(kubectl config view --minify --raw | yq '.users[0].name')" +# ------------------------------------------------------------------------------------- +echo "Step2: List modules" +../../bin/kyma@v3 alpha module list + +# ------------------------------------------------------------------------------------- +echo "Step3: Connecting to remote BTP subaccount" +# ------------------------------------------------------------------------------------- +echo "Step4: Create Shared Service Instance Reference" +# ------------------------------------------------------------------------------------- +# Enable Docker Registry +echo "Step5: Enable Docker Registry from experimental channel (with persistent BTP based storage)" +../../bin/kyma@v3 alpha module add docker-registry --channel experimental --cr-path k8s-resources/exposed-docker-registry.yaml + +echo "..waiting for docker registry" +kubectl wait --for condition=Installed dockerregistries.operator.kyma-project.io/default -n kyma-system --timeout=360s +# ------------------------------------------------------------------------------------- +echo "Step6: Map bookstore DB" +# ------------------------------------------------------------------------------------- +echo "Step7: Push bookstore application (w/o Dockerfile)" +# ------------------------------------------------------------------------------------- + + +exit 0 \ No newline at end of file diff --git a/tests/btp/k8s-resources/exposed-docker-registry.yaml b/tests/btp/k8s-resources/exposed-docker-registry.yaml new file mode 100644 index 000000000..b222c8ab2 --- /dev/null +++ b/tests/btp/k8s-resources/exposed-docker-registry.yaml @@ -0,0 +1,7 @@ +apiVersion: operator.kyma-project.io/v1alpha1 +kind: DockerRegistry +metadata: + name: default +spec: + externalAccess: + enabled: true \ No newline at end of file diff --git a/tests/k3d/Makefile b/tests/k3d/Makefile new file mode 100644 index 000000000..7e9b12d78 --- /dev/null +++ b/tests/k3d/Makefile @@ -0,0 +1,3 @@ +.PHONY: e2e-test +e2e-test: + ./integration-test-k3d.sh \ No newline at end of file diff --git a/tests/k3d/integration-test-k3d.sh b/tests/k3d/integration-test-k3d.sh new file mode 100755 index 000000000..a83694bb9 --- /dev/null +++ b/tests/k3d/integration-test-k3d.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +echo "Running basic test scenario for kyma@v3 CLI on k3d runtime" + +# ------------------------------------------------------------------------------------- +# Generate kubeconfig for service account + +echo "Step1: Generating temporary access for new service account" +../../bin/kyma@v3 alpha access --clusterrole cluster-admin --name test-sa --output /tmp/kubeconfig.yaml --time 2h +export KUBECONFIG="/tmp/kubeconfig.yaml" +if [[ $(kubectl config view --minify --raw | yq '.users[0].name') != 'test-sa' ]]; then + exit 1 +fi +echo "Running test in user context of: $(kubectl config view --minify --raw | yq '.users[0].name')" + +# ------------------------------------------------------------------------------------- +# Enable Docker Registry + +echo "Step2: Enable latest Docker Registry release" +kubectl create namespace kyma-system || true +kubectl apply -f https://github.com/kyma-project/docker-registry/releases/latest/download/dockerregistry-operator.yaml +kubectl apply -f https://github.com/kyma-project/docker-registry/releases/latest/download/default-dockerregistry-cr.yaml -n kyma-system +echo "..waiting for docker registry" +kubectl wait --for condition=Installed dockerregistries.operator.kyma-project.io/default -n kyma-system --timeout=360s + +# ------------------------------------------------------------------------------------- +# Push sample go app + +echo "Step3: Push sample Go application (tests/k3d/sample-go)" +../../bin/kyma@v3 alpha app push --name test-app --code-path sample-go +kubectl wait --for condition=Available deployment test-app --timeout=60s +kubectl port-forward deployments/test-app 8080:8080 & +sleep 3 # wait for ports to get forwarded +response=$(curl localhost:8080) +echo "HTTP response from sample app: $response" + +if [[ $response != 'okey dokey' ]]; then + exit 1 +fi + +# ------------------------------------------------------------------------------------- +# Cleanup + +echo "Step4: Cleanup" +kubectl delete deployment test-app + +# ------------------------------------------------------------------------------------- +exit 0 \ No newline at end of file diff --git a/tests/k3d/sample-go/go.mod b/tests/k3d/sample-go/go.mod new file mode 100644 index 000000000..dd13fb0e1 --- /dev/null +++ b/tests/k3d/sample-go/go.mod @@ -0,0 +1,3 @@ +module github.com/kyma-project/pack-test + +go 1.23.2 \ No newline at end of file diff --git a/tests/k3d/sample-go/main.go b/tests/k3d/sample-go/main.go new file mode 100644 index 000000000..06bc9e831 --- /dev/null +++ b/tests/k3d/sample-go/main.go @@ -0,0 +1,20 @@ +package main + +import ( + "fmt" + "net/http" + "os" +) + +func main() { + mux := &http.ServeMux{} + mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + fmt.Println("got request") + w.WriteHeader(200) + w.Write([]byte("okey dokey")) + }) + if err := http.ListenAndServe(":8080", mux); err != nil { + fmt.Println(err.Error()) + os.Exit(1) + } +}