diff --git a/tests/components/application-connector/Dockerfile.compass-runtime-agent b/tests/components/application-connector/Dockerfile.compass-runtime-agent new file mode 100644 index 000000000000..9eb312584f6c --- /dev/null +++ b/tests/components/application-connector/Dockerfile.compass-runtime-agent @@ -0,0 +1,16 @@ +FROM eu.gcr.io/kyma-project/external/golang:1.18.3-alpine3.16 as builder + +WORKDIR /compass-test/ + +COPY go.mod go.sum ./ +RUN go mod download && go mod verify + +COPY . . + +RUN CGO_ENABLED=0 go test -v -c -o compass-test ./test/compass-runtime-agent/ + +FROM scratch + +COPY --from=builder /compass-test/compass-test / +ENTRYPOINT [ "/compass-test" ] +CMD ["-test.v"] diff --git a/tests/components/application-connector/Makefile b/tests/components/application-connector/Makefile index 6f8e5fabc296..537b5af72e31 100644 --- a/tests/components/application-connector/Makefile +++ b/tests/components/application-connector/Makefile @@ -2,19 +2,21 @@ NAMESPACE ?= test GOPATH ?= $(shell go env GOPATH) GATEWAY_TEST_IMAGE = "$(DOCKER_PUSH_REPOSITORY)$(DOCKER_PUSH_DIRECTORY)/gateway-test:$(DOCKER_TAG)" +COMPASS_TEST_IMAGE = "$(DOCKER_PUSH_REPOSITORY)$(DOCKER_PUSH_DIRECTORY)/compass-runtime-agent-test:$(DOCKER_TAG)" MOCK_APP_IMAGE = "$(DOCKER_PUSH_REPOSITORY)$(DOCKER_PUSH_DIRECTORY)/mock-app:$(DOCKER_TAG)" MOCK_SERVICE_NAME="mock-application" APP_URL = "$(MOCK_SERVICE_NAME).$(NAMESPACE).svc.cluster.local" TEST_TIMEOUT = "2m" -.PHONY: release test-os test-skr test image publish clean image-gateway-test publish-gateway-test test-gateway test-gateway-debug image-mock-app publish-mock-app disable-sidecar-for-mtls-test enable-sidecar-after-mtls-test generate-certs +.PHONY: release test image clean +.PHONY: test-gateway test-gateway-debug clean-gateway-test publish-gateway-test image-gateway-test publish-mock-app image-mock-app disable-sidecar-for-mtls-test enable-sidecar-after-mtls-test generate-certs +.PHONY: test-compass-runtime-agent test-compass-runtime-agent-debug clean-compass-runtime-agent-test image-compass-runtime-agent-test publish-compass-runtime-agent-test -test: test-gateway -image: image-gateway-test -clean: clean-gateway-test - -release: publish-gateway-test publish-mock-app +release: publish-gateway-test publish-mock-app publish-compass-runtime-agent-test +test: test-gateway test-compass-runtime-agent +image: image-gateway-test image-compass-runtime-agent-test +clean: clean-gateway-test clean-compass-runtime-agent-test test-gateway: disable-sidecar-for-mtls-test generate-certs test-gateway-debug clean-gateway-test enable-sidecar-after-mtls-test @@ -31,7 +33,7 @@ test-gateway-debug: @echo "" @echo "Gateway test results:" - ./scripts/check-pod-logs.sh + ./scripts/check-pod-logs.sh application-gateway-test clean-gateway-test: helm template resources/charts/gateway-test | kubectl delete -f - @@ -60,4 +62,31 @@ generate-certs: ./scripts/generate-self-signed-certs.sh $(APP_URL) ./resources/charts/gateway-test/certs/positive ./scripts/generate-self-signed-certs.sh $(APP_URL) ./resources/charts/gateway-test/certs/negative +test-compass-runtime-agent: test-compass-runtime-agent-debug clean-compass-runtime-agent-test + +test-compass-runtime-agent-debug: + @echo $(GOPATH)/bin/go-junit-report --help + kubectl create namespace $(NAMESPACE) --dry-run=client -o yaml | kubectl apply -f - + + helm template resources/charts/compass-runtime-agent-test \ + --set namespace=$(NAMESPACE) \ + --set mockServiceName=$(MOCK_SERVICE_NAME) \ + | kubectl apply -f - + + -kubectl wait --for=condition=complete --timeout=$(TEST_TIMEOUT) -n $(NAMESPACE) job/compass-runtime-agent-test + @echo "" + @echo "Compass test results:" + + ./scripts/check-pod-logs.sh compass-runtime-agent-test + +clean-compass-runtime-agent-test: + helm template resources/charts/compass-runtime-agent-test | kubectl delete -f - + kubectl delete ns $(NAMESPACE) --ignore-not-found + +publish-compass-runtime-agent-test: image-compass-runtime-agent-test + docker push $(COMPASS_TEST_IMAGE) + +image-compass-runtime-agent-test: + docker build -t $(COMPASS_TEST_IMAGE) -f Dockerfile.compass-runtime-agent . + diff --git a/tests/components/application-connector/resources/charts/compass-runtime-agent-test/Chart.yaml b/tests/components/application-connector/resources/charts/compass-runtime-agent-test/Chart.yaml new file mode 100644 index 000000000000..9b3c49e9548e --- /dev/null +++ b/tests/components/application-connector/resources/charts/compass-runtime-agent-test/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: compass-runtime-agent-test +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "0.1.0" diff --git a/tests/components/application-connector/resources/charts/compass-runtime-agent-test/templates/_helpers.tpl b/tests/components/application-connector/resources/charts/compass-runtime-agent-test/templates/_helpers.tpl new file mode 100644 index 000000000000..9cba139160b4 --- /dev/null +++ b/tests/components/application-connector/resources/charts/compass-runtime-agent-test/templates/_helpers.tpl @@ -0,0 +1,12 @@ + +{{/* +Create a URL for container images +*/}} +{{- define "imageurl" -}} +{{- $registry := default $.reg.path $.img.containerRegistryPath -}} +{{- if hasKey $.img "directory" -}} +{{- printf "%s/%s/%s:%s" $registry $.img.directory $.img.name $.img.version -}} +{{- else -}} +{{- printf "%s/%s:%s" $registry $.img.name $.img.version -}} +{{- end -}} +{{- end -}} diff --git a/tests/components/application-connector/resources/charts/compass-runtime-agent-test/templates/test.yaml b/tests/components/application-connector/resources/charts/compass-runtime-agent-test/templates/test.yaml new file mode 100644 index 000000000000..ab2d8a6764fa --- /dev/null +++ b/tests/components/application-connector/resources/charts/compass-runtime-agent-test/templates/test.yaml @@ -0,0 +1,14 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: compass-runtime-agent-test + namespace: {{ .Values.namespace }} +spec: + template: + spec: + containers: + - name: compass-runtime-agent-test + image: {{ include "imageurl" (dict "reg" .Values.containerRegistry "img" .Values.images.compassTest) }} + imagePullPolicy: Always + restartPolicy: Never + backoffLimit: 0 \ No newline at end of file diff --git a/tests/components/application-connector/resources/charts/compass-runtime-agent-test/values.yaml b/tests/components/application-connector/resources/charts/compass-runtime-agent-test/values.yaml new file mode 100644 index 000000000000..09ca34ecdeef --- /dev/null +++ b/tests/components/application-connector/resources/charts/compass-runtime-agent-test/values.yaml @@ -0,0 +1,9 @@ +namespace: "test" + +containerRegistry: + path: "eu.gcr.io/kyma-project" + +images: + compassTest: + name: "compass-runtime-agent-test" + version: "PR-15024" diff --git a/tests/components/application-connector/scripts/check-pod-logs.sh b/tests/components/application-connector/scripts/check-pod-logs.sh index 245413179966..e73659fcdedd 100755 --- a/tests/components/application-connector/scripts/check-pod-logs.sh +++ b/tests/components/application-connector/scripts/check-pod-logs.sh @@ -1,9 +1,15 @@ #!/usr/bin/env bash NAMESPACE=test GOPATH=$(go env GOPATH) +JOB_NAME=$1 + +if [ $# -ne 1 ]; then + echo "Usage: check-pod-logs.sh " + exit 1 +fi if ([[ ${EXPORT_RESULT} == true ]]); then - kubectl -n $NAMESPACE logs -f job/application-gateway-test | tee /dev/stderr | $GOPATH/bin/go-junit-report -set-exit-code > junit-report.xml + kubectl -n $NAMESPACE logs -f job/"$JOB_NAME" | tee /dev/stderr | $GOPATH/bin/go-junit-report -set-exit-code > junit-report.xml else - kubectl -n $NAMESPACE logs -f job/application-gateway-test + kubectl -n $NAMESPACE logs -f job/"$JOB_NAME" fi diff --git a/tests/components/application-connector/test/compass-runtime-agent/suite_test.go b/tests/components/application-connector/test/compass-runtime-agent/suite_test.go new file mode 100644 index 000000000000..f6d5a9b767a5 --- /dev/null +++ b/tests/components/application-connector/test/compass-runtime-agent/suite_test.go @@ -0,0 +1,34 @@ +package compass_runtime_agent + +import ( + "net/http" + "testing" + + cli "github.com/kyma-project/kyma/components/application-operator/pkg/client/clientset/versioned" + "github.com/stretchr/testify/suite" + "k8s.io/client-go/rest" +) + +type CompassRuntimeAgentSuite struct { + suite.Suite + cli *cli.Clientset +} + +func (gs *CompassRuntimeAgentSuite) SetupSuite() { + cfg, err := rest.InClusterConfig() + gs.Require().Nil(err) + + gs.cli, err = cli.NewForConfig(cfg) + gs.Require().Nil(err) +} + +func (gs *CompassRuntimeAgentSuite) TearDownSuite() { + _, err := http.Post("http://localhost:15000/quitquitquit", "", nil) + gs.Nil(err) + _, err = http.Post("http://localhost:15020/quitquitquit", "", nil) + gs.Nil(err) +} + +func TestCompassRuntimeAgentSuite(t *testing.T) { + suite.Run(t, new(CompassRuntimeAgentSuite)) +} diff --git a/tests/components/application-connector/test/compass-runtime-agent/synchronisation_test.go b/tests/components/application-connector/test/compass-runtime-agent/synchronisation_test.go new file mode 100644 index 000000000000..9e8a85e90511 --- /dev/null +++ b/tests/components/application-connector/test/compass-runtime-agent/synchronisation_test.go @@ -0,0 +1,4 @@ +package compass_runtime_agent + +func (gs *CompassRuntimeAgentSuite) TestCreatingApplications() { +}