Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable running integration tests via prow #731

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
94 changes: 94 additions & 0 deletions .ci/prow/integration-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/bash

# SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Gardener contributors
#
# SPDX-License-Identifier: Apache-2.0

set -u
set -e

REPO_ROOT="$(dirname $0)/../.."
cd "${REPO_ROOT}"
REPO_ROOT="$(pwd)"
export REPO_ROOT

TMP_DIR="/tmp"
EXPORT_DIR="/logs/artifacts"
BIN_DIR="$TMP_DIR/bin"
GOBIN="$BIN_DIR"
mkdir -p "$EXPORT_DIR"
mkdir -p "$BIN_DIR"
export PATH="$BIN_DIR:$PATH"

export EFFECTIVE_VERSION=$($REPO_ROOT/hack/get-version.sh)
export KUBECONFIG="$TMP_DIR/kubeconfig"

export K8S_VERSION="v1.25.3"
export KIND_VERSION="v0.18.0"
export CLUSTER_NAME="int-test"

function export_resources() {
for res in "$@"; do
echo "exporting $res"
kubectl get "$res" -A -o yaml > "$EXPORT_DIR/$res.yaml"
done
}

# prow merges the PR with the master branch, which adds a commit and messes up the version logic
last_commit_message=$(git log -1 --pretty=%B)
if [[ "$last_commit_message" == "Merge commit '"*"'" ]] && [[ $PULL_PULL_SHA ]]; then
echo "Reverting merge with master branch ..."
git checkout "$PULL_PULL_SHA"
EFFECTIVE_VERSION="$(cat $REPO_ROOT/VERSION)-$PULL_PULL_SHA"
echo "Setting EFFECTIVE_VERSION to $EFFECTIVE_VERSION."
fi

# download kind if not there
echo ">>> Checking for kind"
kv=""
if ! kv=$(kind version 2>/dev/null); then
echo "kind not found, downloading version $KIND_VERSION"
curl -L -o "$BIN_DIR/kind" "https://kind.sigs.k8s.io/dl/$KIND_VERSION/kind-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')"
chmod +x "$BIN_DIR/kind"
else
echo "kind found: $kv"
fi

# install ginkgo if not there
echo ">>> Checking for ginkgo"
gv=""
if ! gv=$(ginkgo version 2>/dev/null); then
echo "ginkgo not found, installing it"
go install "github.com/onsi/ginkgo/v2/ginkgo"
else
echo "ginkgo found: $gv"
fi

# create kind cluster
echo ">>> Creating kind cluster"
kind create cluster --image="kindest/node:$K8S_VERSION" --name="$CLUSTER_NAME" --wait=300s
echo ""

# export logs and remove kind cluster after execution
trap '{
echo ">>> Exporting logs and resources"
kind export logs --name="$CLUSTER_NAME" "$EXPORT_DIR"
export_resources deployments installations executions deployitems
echo ""
echo ">>> Deleting kind cluster"
kind delete cluster --name="$CLUSTER_NAME"
echo ""
}' EXIT

# install Landscaper
echo ">>> Installing Landscaper"
${REPO_ROOT}/hack/install-landscaper-for-integration-test.sh
echo ""

# run tests
echo ">>> Running integration tests"
ginkgo -timeout=60m -v -progress -no-color -seed=17 -fail-fast ${REPO_ROOT}/test/integration -- \
--kubeconfig=$KUBECONFIG \
--ls-namespace=ls-system \
--ls-version=$EFFECTIVE_VERSION
echo ""
5 changes: 0 additions & 5 deletions .ci/testruns/integration-test/Chart.yaml

This file was deleted.

63 changes: 0 additions & 63 deletions .ci/testruns/integration-test/templates/testrun.yaml

This file was deleted.

19 changes: 0 additions & 19 deletions .test-defs/create-cluster.yaml

This file was deleted.

20 changes: 0 additions & 20 deletions .test-defs/create-registry.yaml

This file was deleted.

18 changes: 0 additions & 18 deletions .test-defs/delete-cluster.yaml

This file was deleted.

18 changes: 0 additions & 18 deletions .test-defs/delete-registry.yaml

This file was deleted.

14 changes: 0 additions & 14 deletions .test-defs/install-landscaper.yaml

This file was deleted.

19 changes: 0 additions & 19 deletions .test-defs/integration.yaml

This file was deleted.

11 changes: 5 additions & 6 deletions docs/guided-tour/blueprints/echo-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ component descriptor. In detail, the connection is the following:
```yaml
name: echo-server-image
type: ociImage
version: v0.2.3
version: v0.7.0
relation: external
access:
type: ociRegistry
imageReference: hashicorp/http-echo:0.2.3
imageReference: ealen/echo-server:0.7.0
```

- The [blueprint](./blueprint/blueprint.yaml) contains a template for a `DeployItem`. Part of this is a
Expand All @@ -52,7 +52,7 @@ component descriptor. In detail, the connection is the following:

```yaml
values:
image: hashicorp/http-echo:0.2.3
image: ealen/echo-server:0.7.0
```

- Finally, the [deployment.yaml](./chart/echo-server/templates/deployment.yaml) of the chart takes the image from the
Expand Down Expand Up @@ -87,7 +87,6 @@ The procedure to install the helm chart with Landscaper is as follows:
kubectl port-forward -n example service/echo-server 8080:80
```

Then open `localhost:8080` in a browser.
Then open [`localhost:8080/?echo_body=Hello%20Landscaper!`](localhost:8080/?echo_body=Hello%20Landscaper!) in a browser.

The response should be "hello world", which is the text defined
in the [values.yaml](./chart/echo-server/values.yaml) of the chart.
The response should be "Hello Landscaper!".
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
appVersion: 1.0.0
appVersion: 1.2.0
description: Echo server chart
name: echo-server
type: application
version: 1.0.0
version: 1.2.0
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ spec:
- image: {{ .Values.image }}
imagePullPolicy: IfNotPresent
name: echo
args:
- -text="{{ .Values.text }}"
ports:
- containerPort: 5678
- containerPort: 80
env:
- name: PORT
value: "80"
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ spec:
app: echo
ports:
- protocol: TCP
port: 80
targetPort: 5678
port: {{ .Values.port }}
targetPort: 80
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
image: hashicorp/http-echo:0.2.0
text: hello world
image: ealen/echo-server:0.7.0
port: 80
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ meta:
schemaVersion: 'v2'
component:
name: 'github.com/gardener/landscaper-examples/guided-tour/echo-server'
version: '1.0.0'
version: '1.2.0'

repositoryContexts:
- type: 'ociRegistry'
Expand All @@ -17,22 +17,22 @@ component:
resources:
- name: blueprint
type: blueprint
version: 1.0.0
version: 1.2.0
relation: external
access:
type: ociRegistry
imageReference: eu.gcr.io/gardener-project/landscaper/examples/blueprints/guided-tour/echo-server:1.0.0
imageReference: eu.gcr.io/gardener-project/landscaper/examples/blueprints/guided-tour/echo-server:1.2.0
- name: echo-server-chart
type: helm.io/chart
version: 1.0.0
version: 1.2.0
relation: external
access:
type: ociRegistry
imageReference: eu.gcr.io/gardener-project/landscaper/examples/charts/guided-tour/echo-server:1.0.0
imageReference: eu.gcr.io/gardener-project/landscaper/examples/charts/guided-tour/echo-server:1.2.0
- name: echo-server-image
type: ociImage
version: v0.2.3
version: v0.7.0
relation: external
access:
type: ociRegistry
imageReference: hashicorp/http-echo:0.2.3
imageReference: ealen/echo-server:0.7.0
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
componentDescriptor:
ref:
componentName: github.com/gardener/landscaper-examples/guided-tour/echo-server
version: 1.0.0
version: 1.2.0

blueprint:
ref:
Expand Down
Loading