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

ci: Rewrite e2e test suite from bash to golang #217

Merged
merged 29 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6fdfc44
ci: Implement first draft of new e2e test suite
konrad-ohms Sep 9, 2024
5d6d0ab
ci: Ensure that e2e are not cachable
konrad-ohms Sep 9, 2024
d4a379c
fix(ci): Adjust paths
konrad-ohms Sep 10, 2024
be53b13
test: Make cleanup more robust (remove finalizer on CR)
konrad-ohms Sep 10, 2024
2acf3db
fix: Linting issue and run e2e without waiting for olm
konrad-ohms Sep 10, 2024
d5d3fd3
test: Improve error handling
konrad-ohms Sep 10, 2024
9f5a76a
ci(test): Refactor e2e initialization
konrad-ohms Sep 12, 2024
624017f
test: Extend initial install, reorder e2e execution
konrad-ohms Sep 12, 2024
adaefaf
ci: Fixup script path
konrad-ohms Sep 12, 2024
c77229c
test: Use sdk to change scc instead of oc cli
konrad-ohms Sep 12, 2024
b258b6e
fixup
konrad-ohms Sep 12, 2024
72e025d
test: Refactor install test
konrad-ohms Sep 13, 2024
f867aa6
test: Check agent logs for successful connection
konrad-ohms Sep 13, 2024
9d60228
test: Wait for controller-manager before applying CR, Readme update
konrad-ohms Sep 13, 2024
11910b4
test: Use correct agent download key secret
konrad-ohms Sep 23, 2024
80d8890
test: Implement update install, introduce test api
konrad-ohms Sep 23, 2024
32e0a98
test: Add test to check reconciliation of new operator
konrad-ohms Sep 23, 2024
884e6b6
test: Refactor config and logging
konrad-ohms Sep 24, 2024
0dcb37d
test: Cleanup test API
konrad-ohms Sep 24, 2024
d946465
test: Add initial install test, reuse logic if possible
konrad-ohms Sep 24, 2024
3b05b72
test: Add multi-backend test to new e2e framework
konrad-ohms Sep 24, 2024
d1759b6
test: Exec into pod to check configuration
konrad-ohms Sep 26, 2024
822a27e
test: Remove old e2e test bash script
konrad-ohms Sep 26, 2024
afc1c45
test: Add explicit test for keysSecret and inline secret
konrad-ohms Sep 26, 2024
d127c35
chore: Fix linting issues
konrad-ohms Sep 26, 2024
333ce47
chore: Add support for building with podman
konrad-ohms Oct 4, 2024
de46813
fix: Restore Dockerfile to work on non-amd64 hosts
konrad-ohms Oct 4, 2024
b10c47f
chore: Add support for local podman build via buildkit
konrad-ohms Oct 7, 2024
f6376cf
test: Align test suite with k8s multi-backend changes
konrad-ohms Oct 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ instana-agent-operator
# CI
backend.cfg

e2e/.env
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# (c) Copyright IBM Corp. 2021
# (c) Copyright IBM Corp. 2021, 2024
# (c) Copyright Instana Inc.
#

Expand Down Expand Up @@ -75,4 +75,4 @@ RUN chown -R ${USER_UID}:${USER_UID} .cache
RUN chmod -R 777 .cache

USER ${USER_UID}:${USER_UID}
ENTRYPOINT ["/manager"]
ENTRYPOINT ["/manager"]
45 changes: 38 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ ifeq ($(uname), Darwin)
get_ip_addr := ipconfig getifaddr en0
endif

# Detect if podman or docker is available locally
ifeq ($(shell command -v podman 2> /dev/null),)
CONTAINER_CMD = docker
else
CONTAINER_CMD = podman
endif

all: build

Expand Down Expand Up @@ -88,13 +94,16 @@ vet: ## Run go vet against code
lint: golangci-lint ## Run the golang-ci linter
$(GOLANGCI_LINT) run --timeout 5m

EXCLUDED_TEST_DIRS = mocks
EXCLUDED_TEST_DIRS = mocks e2e
EXCLUDE_PATTERN = $(shell echo $(EXCLUDED_TEST_DIRS) | sed 's/ /|/g')
PACKAGES = $(shell go list ./... | grep -vE "$(EXCLUDE_PATTERN)" | tr '\n' ' ')
KUBEBUILDER_ASSETS=$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)
test: gen-mocks manifests generate fmt vet lint envtest ## Run tests but ignore specific directories that match EXCLUDED_TEST_DIRS
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test $(PACKAGES) -coverprofile=coverage.out

.PHONY: e2e
e2e:
go test -timeout=10m -count=1 -v github.com/instana/instana-agent-operator/e2e

##@ Build

Expand All @@ -105,12 +114,13 @@ run: export DEBUG_MODE=true
run: generate fmt vet manifests ## Run against the configured Kubernetes cluster in ~/.kube/config (run the "install" target to install CRDs into the cluster)
go run ./

docker-build: test ## Build docker image with the manager.
docker build --build-arg VERSION=${VERSION} --build-arg GIT_COMMIT=${GIT_COMMIT} --build-arg DATE="$$(date)" -t ${IMG} .
docker-build: test container-build ## Build docker image with the manager.

docker-push: ## Push the docker image with the manager.
docker push ${IMG}
${CONTAINER_CMD} push ${IMG}

container-build: buildctl
$(BUILDCTL) --addr=${CONTAINER_CMD}-container://buildkitd build --frontend=dockerfile.v0 --local context=. --local dockerfile=. --output type=oci,name=${IMG} --opt build-arg:VERSION=0.0.1 --opt build-arg:GIT_COMMIT=${GIT_COMMIT} --opt build-arg:DATE="$$(date)" | $(CONTAINER_CMD) load

##@ Deployment

Expand Down Expand Up @@ -167,6 +177,26 @@ endif
operator-sdk: ## Download the Operator SDK binary locally if necessary.
$(call curl-get-tool,$(OPERATOR_SDK),https://github.com/operator-framework/operator-sdk/releases/download/v1.16.0,operator-sdk_$${OS}_$${ARCH})

BUILDCTL = $(shell pwd)/bin/buildctl
BUILDKITD_CONTAINER_NAME = buildkitd
# Test if buildctl is available in the GOPATH, if not, set to local and download if needed
buildctl: ## Download the buildctl cli locally if necessary.
@if [ "`podman ps -a -q -f name=$(BUILDKITD_CONTAINER_NAME)`" ]; then \
if [ "`podman ps -aq -f status=exited -f name=$(BUILDKITD_CONTAINER_NAME)`" ]; then \
echo "Starting buildkitd container $(BUILDKITD_CONTAINER_NAME)"; \
$(CONTAINER_CMD) start $(BUILDKITD_CONTAINER_NAME) || true; \
echo "Allowing 5 seconds to bootup"; \
sleep 5; \
else \
echo "Buildkit daemon is already running, skip container creation"; \
fi \
else \
echo "$(BUILDKITD_CONTAINER_NAME) container is not present, launching it now"; \
$(CONTAINER_CMD) run -d --name buildkitd --privileged docker.io/moby/buildkit:v0.16.0; \
echo "Allowing 5 seconds to bootup"; \
sleep 5; \
fi
$(call go-install-tool,$(BUILDCTL),github.com/moby/buildkit/cmd/buildctl@v0.16)

# go-install-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
Expand Down Expand Up @@ -220,8 +250,9 @@ bundle: operator-sdk manifests kustomize ## Create the OLM bundle
$(OPERATOR_SDK) bundle validate ./bundle

.PHONY: bundle-build
bundle-build: ## Build the bundle image for OLM.
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
bundle-build: buildctl ## Build the bundle image for OLM.
#docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
$(BUILDCTL) --addr=${CONTAINER_CMD}-container://buildkitd build --frontend gateway.v0 --opt source=docker/dockerfile --opt filename=./bundle.Dockerfile --local context=. --local dockerfile=. --output type=oci,name=${BUNDLE_IMG} | $(CONTAINER_CMD) load

controller-yaml: manifests kustomize ## Output the YAML for deployment, so it can be packaged with the release. Use `make --silent` to suppress other output.
cd config/manager && $(KUSTOMIZE) edit set image "instana/instana-agent-operator=$(IMG)"
Expand All @@ -243,4 +274,4 @@ gen-mocks: get-mockgen
mockgen --source ./pkg/k8s/object/builders/common/builder/builder.go --destination ./mocks/builder_mock.go --package mocks
mockgen --source ./pkg/json_or_die/json.go --destination ./mocks/json_or_die_marshaler_mock.go --package mocks
mockgen --source ./pkg/k8s/operator/status/agent_status_manager.go --destination ./mocks/agent_status_manager_mock.go --package mocks
mockgen --source ./pkg/k8s/operator/lifecycle/dependent_lifecycle_manager.go --destination ./mocks/dependent_lifecycle_manager_mock.go --package mocks
mockgen --source ./pkg/k8s/operator/lifecycle/dependent_lifecycle_manager.go --destination ./mocks/dependent_lifecycle_manager_mock.go --package mocks
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,32 @@ Now you should have a successful running Operator.
To remove the Operator again, run:
* `kubectl delete -f config/samples/instana_v1_instanaagent_demo.yaml`
* `make undeploy`.

### Running tests

Unit tests can be executed by running `make test` without adjustments of the local environment.

For end-to-end testing, it is necessary to have a valid kubeconfig in the default location and to export variables before starting the test.
An example template file is available in [e2e/.env.template](./e2e/.env.template), copy it to `./e2e/.env` and adjust it accordingly.

The test can be executed by sourcing the config `source ./e2e/.env` and running `make e2e` or by using the VSCode.

For VSCode, ensure to have a valid `.vscode/settings.json` in your root folder.

Example:

```json
{
"wcaForGP.enable": true,
"go.testEnvVars": {
"KUBEBUILDER_ASSETS": "~/.local/share/kubebuilder-envtest/k8s/1.30.0-linux-amd64",
"INSTANA_API_KEY": "xxx",
"ARTIFACTORY_USERNAME": "xxx",
"ARTIFACTORY_PASSWORD": "xxx",
"OPERATOR_IMAGE_NAME": "xxx",
"OPERATOR_IMAGE_TAG": "xxx"
},
"wca.enable": false,
"go.testTimeout": "600s"
}
```
22 changes: 17 additions & 5 deletions ci/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,19 @@ jobs:
INSTANA_ENDPOINT_HOST: ((instana-qa.endpoint_host))
INSTANA_ENDPOINT_PORT: 443
BUILD_BRANCH: main
INSTANA_API_KEY: ((qa-instana-api-token))
INSTANA_API_KEY: ((qa-instana-agent-key))
ARTIFACTORY_USERNAME: ((delivery-instana-io-internal-project-artifact-read-writer-creds.username))
ARTIFACTORY_PASSWORD: ((delivery-instana-io-internal-project-artifact-read-writer-creds.password))
inputs:
- name: pipeline-source
run:
path: pipeline-source/ci/scripts/end-to-end-test.sh
path: bash
args:
- -ceu
- |
cd pipeline-source
bash ./ci/scripts/cluster-authentication.sh
make e2e
on_success:
put: gh-status
inputs: [ pipeline-source ]
Expand Down Expand Up @@ -603,13 +609,19 @@ jobs:
INSTANA_API_URL: ((instana-qa.api_url))
INSTANA_API_TOKEN: ((instana-qa.api_token))
BUILD_BRANCH: main
INSTANA_API_KEY: ((qa-instana-api-token))
INSTANA_API_KEY: ((qa-instana-agent-key))
ARTIFACTORY_USERNAME: ((delivery-instana-io-internal-project-artifact-read-writer-creds.username))
ARTIFACTORY_PASSWORD: ((delivery-instana-io-internal-project-artifact-read-writer-creds.password))
inputs:
- name: pipeline-source
run:
path: pipeline-source/ci/scripts/end-to-end-test.sh
path: bash
args:
- -ceu
- |
cd pipeline-source
bash ./ci/scripts/cluster-authentication.sh
make e2e
on_success:
put: gh-status
inputs: [ pipeline-source ]
Expand Down Expand Up @@ -684,7 +696,7 @@ jobs:
# INSTANA_API_URL: ((instana-qa.api_url))
# INSTANA_API_TOKEN: ((instana-qa.api_token))
# BUILD_BRANCH: main
# INSTANA_API_KEY: ((qa-instana-api-token))
# INSTANA_API_KEY: ((qa-instana-agent-key))
# ARTIFACTORY_USERNAME: ((delivery-instana-io-internal-project-artifact-read-writer-creds.username))
# ARTIFACTORY_PASSWORD: ((delivery-instana-io-internal-project-artifact-read-writer-creds.password))
# inputs:
Expand Down
24 changes: 18 additions & 6 deletions ci/pr-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ jobs:
plan:
- get: pipeline-source
trigger: true
passed: [operator-olm-build, docker-build]
passed: [docker-build]
- load_var: git-commit
file: pipeline-source/.git/short_ref
reveal: true
Expand Down Expand Up @@ -600,13 +600,19 @@ jobs:
INSTANA_ENDPOINT_HOST: ((instana-qa.endpoint_host))
INSTANA_ENDPOINT_PORT: 443
BUILD_BRANCH: ((branch))
INSTANA_API_KEY: ((qa-instana-api-token))
INSTANA_API_KEY: ((qa-instana-agent-key))
ARTIFACTORY_USERNAME: ((delivery-instana-io-internal-project-artifact-read-writer-creds.username))
ARTIFACTORY_PASSWORD: ((delivery-instana-io-internal-project-artifact-read-writer-creds.password))
inputs:
- name: pipeline-source
run:
path: pipeline-source/ci/scripts/end-to-end-test.sh
path: bash
args:
- -ceu
- |
cd pipeline-source
bash ./ci/scripts/cluster-authentication.sh
make e2e
on_success:
put: gh-status
inputs: [pipeline-source]
Expand Down Expand Up @@ -683,13 +689,19 @@ jobs:
INSTANA_API_URL: ((instana-qa.api_url))
INSTANA_API_TOKEN: ((instana-qa.api_token))
BUILD_BRANCH: ((branch))
INSTANA_API_KEY: ((qa-instana-api-token))
INSTANA_API_KEY: ((qa-instana-agent-key))
ARTIFACTORY_USERNAME: ((delivery-instana-io-internal-project-artifact-read-writer-creds.username))
ARTIFACTORY_PASSWORD: ((delivery-instana-io-internal-project-artifact-read-writer-creds.password))
inputs:
- name: pipeline-source
run:
path: pipeline-source/ci/scripts/end-to-end-test.sh
path: bash
args:
- -ceu
- |
cd pipeline-source
bash ./ci/scripts/cluster-authentication.sh
make e2e
on_success:
put: gh-status
inputs: [pipeline-source]
Expand Down Expand Up @@ -768,7 +780,7 @@ jobs:
# INSTANA_API_URL: ((instana-qa.api_url))
# INSTANA_API_TOKEN: ((instana-qa.api_token))
# BUILD_BRANCH: ((branch))
# INSTANA_API_KEY: ((qa-instana-api-token))
# INSTANA_API_KEY: ((qa-instana-agent-key))
# ARTIFACTORY_USERNAME: ((delivery-instana-io-internal-project-artifact-read-writer-creds.username))
# ARTIFACTORY_PASSWORD: ((delivery-instana-io-internal-project-artifact-read-writer-creds.password))
# inputs:
Expand Down
22 changes: 4 additions & 18 deletions ci/scripts/cluster-authentication.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@
set -e
set -o pipefail

function cleanup_namespace() {
echo "Deleting the namespaces"
if kubectl get namespace/instana-agent ; then
kubectl delete namespace/instana-agent
kubectl wait --for=delete namespace/instana-agent --timeout=30s
echo "Deleted namespace instana-agent"
else
echo "Namespace instana-agent does not exist; skipping delete"
fi
echo "OK"
}

case "${CLUSTER_TYPE}" in
gke)
echo 'Testing on a GKE cluster'
Expand All @@ -42,19 +30,17 @@ case "${CLUSTER_TYPE}" in
export USE_GKE_GCLOUD_AUTH_PLUGIN=True
gcloud container clusters get-credentials "${GKE_CLUSTER_NAME}" --zone "${GKE_ZONE}" --project "${GKE_PROJECT}"

cleanup_namespace
;;
openshift)
echo "${KUBECONFIG_SOURCE}" > kubeconfig
chmod 0400 kubeconfig
KUBECONFIG="$(pwd)/kubeconfig"
export KUBECONFIG

cleanup_namespace

echo 'Download OpenShift CLI to modify rights for default ServiceAccount, so it has priviliged access'
curl -L --fail --show-error --silent https://mirror.openshift.com/pub/openshift-v4/clients/oc/latest/linux/oc.tar.gz -o /tmp/oc.tar.gz
tar -xzvf /tmp/oc.tar.gz --overwrite --directory /tmp
# go test does not require oc cli
# echo 'Download OpenShift CLI to modify rights for default ServiceAccount, so it has priviliged access'
# curl -L --fail --show-error --silent https://mirror.openshift.com/pub/openshift-v4/clients/oc/latest/linux/oc.tar.gz -o /tmp/oc.tar.gz
# tar -xzvf /tmp/oc.tar.gz --overwrite --directory /tmp

;;
*)
Expand Down
Loading