Skip to content

Commit

Permalink
add integration test framework (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
reshnm authored May 24, 2022
1 parent c649ba0 commit f950aa6
Show file tree
Hide file tree
Showing 3,610 changed files with 1,089,845 additions and 29 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Files:
go.sum
VERSION
vendor/*
integration-test/vendor/*
integration-test/go.mod
integration-test/go.sum
pkg/crdmanager/crdresources/*
pkg/apis/.schemes/*
pkg/apis/openapi/api_violations.report
Expand Down
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ install-requirements:
.PHONY: revendor
revendor:
@$(REPO_ROOT)/hack/revendor.sh
@cd $(REPO_ROOT)/integration-test && $(REPO_ROOT)/hack/revendor.sh

.PHONY: format
format:
@$(REPO_ROOT)/hack/format.sh $(REPO_ROOT)/pkg $(REPO_ROOT)/cmd $(REPO_ROOT)/hack
@$(REPO_ROOT)/hack/format.sh $(REPO_ROOT)/pkg $(REPO_ROOT)/cmd $(REPO_ROOT)/hack $(REPO_ROOT)/test $(REPO_ROOT)/integration-test/pkg

.PHONY: check
check:
@$(REPO_ROOT)/hack/check.sh --golangci-lint-config=./.golangci.yaml $(REPO_ROOT)/cmd/... $(REPO_ROOT)/pkg/... $(REPO_ROOT)/hack/...
@$(REPO_ROOT)/hack/check.sh --golangci-lint-config=./.golangci.yaml $(REPO_ROOT)/cmd/... $(REPO_ROOT)/pkg/... $(REPO_ROOT)/hack/... $(REPO_ROOT)/test/...
@cd $(REPO_ROOT)/integration-test && $(REPO_ROOT)/hack/check.sh --golangci-lint-config=$(REPO_ROOT)/.golangci.yaml ./pkg/...

.PHONY: verify
verify: check
Expand All @@ -38,6 +40,10 @@ setup-testenv:
test: setup-testenv
@$(REPO_ROOT)/hack/test.sh

.PHONY: integration-test
integration-test:
@cd $(REPO_ROOT)/integration-test && go run ./pkg --kubeconfig $(KUBECONFIG) --laas-version $(EFFECTIVE_VERSION) --laas-repository $(REGISTRY) --provider-type $(CLUSTER_PROVIDER_TYPE)

.PHONY: generate-code
generate-code:
@cd $(REPO_ROOT)/pkg/apis && $(REPO_ROOT)/hack/generate.sh ./... && cd $(REPO_ROOT)
Expand Down
2 changes: 1 addition & 1 deletion hack/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ folders=()
for f in $@; do
folders+=( "$(echo $f | sed 's/\(.*\)\/\.\.\./\1/')" )
done
unformatted_files="$(goimports -l -local=github.com/gardener/landscapercli ${folders[*]})"
unformatted_files="$(goimports -l -local=github.com/gardener/landscaper-service ${folders[*]})"
if [[ "$unformatted_files" ]]; then
echo "Unformatted files detected:"
echo "$unformatted_files"
Expand Down
62 changes: 62 additions & 0 deletions hack/integration-test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python3

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

import os
import sys
import utils
import yaml
import json
import model.container_registry
import oci.auth as oa

from util import ctx
from subprocess import run

project_root = os.environ["PROJECT_ROOT"]
target_cluster = os.environ["TARGET_CLUSTER"]
target_cluster_provider = os.environ["TARGET_CLUSTER_PROVIDER"]
laas_version = os.environ["LAAS_VERSION"]
laas_repository = os.environ["LAAS_REPOSITORY"]
repo_ctx_base_url = os.environ["REPO_CTX_BASE_URL"]
repo_auth_url = os.environ["REPO_AUTH_URL"]

factory = ctx().cfg_factory()
print(f"Getting kubeconfig for {target_cluster}")
landscape_kubeconfig = factory.kubernetes(target_cluster)

print(f"Getting credentials for {repo_ctx_base_url}")
cr_conf = model.container_registry.find_config(repo_ctx_base_url, oa.Privileges.READONLY)

with utils.TempFileAuto(prefix="landscape_kubeconfig_") as kubeconfig_temp_file, utils.TempFileAuto(prefix="registry_auth_", suffix=".json") as registry_temp_file:
kubeconfig_temp_file.write(yaml.safe_dump(landscape_kubeconfig.kubeconfig()))
landscape_kubeconfig_path = kubeconfig_temp_file.switch()

auth = utils.base64_encode_to_string(cr_conf.credentials().username() + ":" + cr_conf.credentials().passwd())
auths = {
"auths": {
repo_auth_url: {
"auth": auth
}
}
}

registry_temp_file.write(json.dumps(auths))
registry_secrets_path = registry_temp_file.switch()

command = ["go", "run", "./pkg/main.go",
"--kubeconfig", landscape_kubeconfig_path,
"--provider-type", target_cluster_provider,
"--laas-version", laas_version,
"--laas-repository", laas_repository,
"--registry-secrets", registry_secrets_path]

print(f"Running integration test with command: {' '.join(command)}")

mod_path = os.path.join(project_root, "integration-test")
run = run(command, cwd=mod_path)

if run.returncode != 0:
raise EnvironmentError("Integration test exited with errors")
31 changes: 30 additions & 1 deletion hack/integration-test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
#!/bin/sh

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

set -e

apk add --no-cache --no-progress bash

if ! command -v git &> /dev/null
then
apk add --no-cache --no-progress git
fi

PROJECT_ROOT="$(dirname $0)/.."
TARGET_CLUSTER="laas-integration-test"
TARGET_CLUSTER_PROVIDER="gcp"
LAAS_VERSION="$("${SOURCE_PATH}"/hack/get-version.sh)"
LAAS_REPOSITORY="eu.gcr.io/sap-se-gcr-k8s-private/cnudie/gardener/development"
REPO_AUTH_URL="https://eu.gcr.io"
REPO_CTX_BASE_URL="eu.gcr.io/sap-se-gcr-k8s-private"

export PROJECT_ROOT
export TARGET_CLUSTER
export TARGET_CLUSTER_PROVIDER
export LAAS_VERSION
export LAAS_REPOSITORY
export REPO_AUTH_URL
export REPO_CTX_BASE_URL


if ! command -v curl &> /dev/null
then
Expand All @@ -19,7 +47,6 @@ then
echo "Helm could not be found"
echo "Try installing it..."
export DESIRED_VERSION="v3.7.1"
apk add --no-cache --no-progress bash
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
# symlink to /bin/helm3 as it is required by the integration test script
ln -s "$(which helm)" /bin/helm3
Expand All @@ -38,3 +65,5 @@ pip3 install --upgrade pip

echo "Running pip3 install gardener-cicd-libs"
pip3 install gardener-cicd-libs

"${PROJECT_ROOT}/hack/integration-test.py"
33 changes: 33 additions & 0 deletions hack/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# SPDX-FileCopyrightText: 2022 "SAP SE or an SAP affiliate company and Gardener contributors"
#
# SPDX-License-Identifier: Apache-2.0

import os
import tempfile
import base64


class TempFileAuto(object):
def __init__(self, prefix=None, mode='w+', suffix=".yaml"):
self.file_obj = tempfile.NamedTemporaryFile(mode=mode, prefix=prefix, suffix=suffix, delete=False)
self.name = self.file_obj.name
def __enter__(self):
return self
def write(self, b):
self.file_obj.write(b)
def writelines(self, lines):
self.file_obj.writelines(lines)
def switch(self):
self.file_obj.close()
return self.file_obj.name
def __exit__(self, type, value, traceback):
if not self.file_obj.closed:
self.file_obj.close()
os.remove(self.file_obj.name)
return False

def base64_encode_to_string(value):
value = value.rstrip()
if isinstance(value, str):
value = value.encode('utf-8')
return base64.b64encode(value).decode('utf-8')
97 changes: 97 additions & 0 deletions integration-test/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
module github.com/gardener/landscaper-service/test/integration

go 1.17

require (
github.com/gardener/component-spec/bindings-go v0.0.53
github.com/gardener/landscaper-service v0.0.0-00010101000000-000000000000
github.com/gardener/landscaper/apis v0.23.0
github.com/gardener/landscaper/controller-utils v0.23.0
github.com/gardener/landscapercli v0.16.1-0.20220408051006-1a25c3c0b246
github.com/go-logr/logr v0.4.0
k8s.io/api v0.22.2
k8s.io/apimachinery v0.22.2
k8s.io/client-go v0.22.2
sigs.k8s.io/controller-runtime v0.10.3
)

require (
github.com/Microsoft/go-winio v0.5.0 // indirect
github.com/Microsoft/hcsshim v0.8.23 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/containerd/containerd v1.5.10 // indirect
github.com/containerd/continuity v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/cli v20.10.7+incompatible // indirect
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v17.12.0-ce-rc1.0.20200618181300-9dc6525e6118+incompatible // indirect
github.com/docker/docker-credential-helpers v0.6.3 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/evanphx/json-patch v4.11.0+incompatible // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/gardener/component-cli v0.36.0 // indirect
github.com/gardener/landscaper v0.21.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-logr/zapr v0.4.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/go-containerregistry v0.5.0 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/mandelsoft/filepath v0.0.0-20200909114706-3df73d378d55 // indirect
github.com/mandelsoft/spiff v1.6.1 // indirect
github.com/mandelsoft/vfs v0.0.0-20210530103237-5249dc39ce91 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/moby/locker v1.0.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/opencontainers/distribution-spec v1.0.0-rc1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/opencontainers/runc v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spf13/cobra v1.2.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.19.1 // indirect
golang.org/x/net v0.0.0-20211005215030-d2e5035098b3 // indirect
golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20211004093028-2c5d950f24ef // indirect
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20211005153810-c76a74d43a8e // indirect
google.golang.org/grpc v1.41.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/component-base v0.22.2 // indirect
k8s.io/klog/v2 v2.9.0 // indirect
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e // indirect
k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)

replace github.com/gardener/landscaper-service => ../
Loading

0 comments on commit f950aa6

Please sign in to comment.