Skip to content

Commit

Permalink
Stub compas runetime agent tests (kyma-project#15024)
Browse files Browse the repository at this point in the history
* Stub structure for testing the compass-runtime-agent

* Temporary delete SA

* Remove the unnecessary inputs

* Fix typos

* Change target name to align with old pipeline target name

* Change job name in script, rember to figure out different approach

* Replace Docker image repository

* Make script universal

* Code review changes #1

* Code review changes #1

* Code review changes #2

* Code review changes #2

Co-authored-by: Arkadiusz Galwas <arkadiusz.galwas@sap.com>
  • Loading branch information
mvshao and akgalwas authored Aug 10, 2022
1 parent 721bfd5 commit 9e3f251
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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"]
43 changes: 36 additions & 7 deletions tests/components/application-connector/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 -
Expand Down Expand Up @@ -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 .


Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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 -}}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace: "test"

containerRegistry:
path: "eu.gcr.io/kyma-project"

images:
compassTest:
name: "compass-runtime-agent-test"
version: "PR-15024"
10 changes: 8 additions & 2 deletions tests/components/application-connector/scripts/check-pod-logs.sh
Original file line number Diff line number Diff line change
@@ -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 <job name>"
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
Original file line number Diff line number Diff line change
@@ -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))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package compass_runtime_agent

func (gs *CompassRuntimeAgentSuite) TestCreatingApplications() {
}

0 comments on commit 9e3f251

Please sign in to comment.