Skip to content

Commit

Permalink
test: refactor kuttl test using env var
Browse files Browse the repository at this point in the history
Signed-off-by: realanna <[email protected]>

test: clean version

Signed-off-by: realanna <[email protected]>

test: clean version

Signed-off-by: realanna <[email protected]>

test: rename without -

Signed-off-by: realanna <[email protected]>

test: rename without -

Signed-off-by: realanna <[email protected]>

test: rename job

Signed-off-by: realanna <[email protected]>

test: rename job

Signed-off-by: realanna <[email protected]>

test: refactor kuttl test using env var

Signed-off-by: realanna <[email protected]>

test: refactor kuttl test using env var

Signed-off-by: realanna <[email protected]>

test: refactor kuttl test using env var

Signed-off-by: realanna <[email protected]>
  • Loading branch information
RealAnna committed Apr 12, 2023
1 parent 72396cd commit 44c845c
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 33 deletions.
13 changes: 4 additions & 9 deletions test/integration/expose-keptn-metric/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
apiVersion: batch/v1
kind: Job
metadata:
name: test
status:
conditions:
- type: Complete
status: 'True'
succeeded: 1
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
commands:
- script: PREFIX="kuttl-test-" && NAME=$(echo $NAMESPACE | sed "s/^$PREFIX//" ) && kubectl wait --for=condition=complete job $NAME-1
11 changes: 11 additions & 0 deletions test/integration/expose-keptn-metric/00-teststep.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: kuttl.dev/v1
kind: TestStep
commands: #generating job and metric based on namespace to avoid interference between runs
- script: |
export NAME=$( echo $NAMESPACE | tr -d -)
echo "installing first job"
envsubst < no-metrics.yaml | kubectl apply -f -
- script: |
export NAME=$( echo $NAMESPACE | tr -d -)
echo "asserting first job"
kubectl wait --for=condition=complete job $NAME-job1 -n $NAMESPACE
9 changes: 0 additions & 9 deletions test/integration/expose-keptn-metric/01-assert.yaml

This file was deleted.

12 changes: 12 additions & 0 deletions test/integration/expose-keptn-metric/01-teststep.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: kuttl.dev/v1
kind: TestStep
commands:
- script: | #generating job and metric based on namespace to avoid interference between runs
export NAME=$( echo $NAMESPACE | tr -d -)
echo "installing second job"
envsubst < metrics.yaml | kubectl apply -f -
- script: | #generating job assertion file
export NAME=$( echo $NAMESPACE | tr -d -)
echo "asserting second job"
kubectl wait --for=condition=complete job $NAME-job2 -n $NAMESPACE
4 changes: 0 additions & 4 deletions test/integration/expose-keptn-metric/02-teststep.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: metrics.keptn.sh/v1alpha2
kind: KeptnMetric
metadata:
name: keptnmetric-sample
namespace: keptn-lifecycle-toolkit-system
name: $NAME
namespace: $NAMESPACE
spec:
provider:
name: "provider"
Expand All @@ -12,7 +12,8 @@ spec:
apiVersion: batch/v1
kind: Job
metadata:
name: test2
name: $NAME-job2
namespace: $NAMESPACE
spec:
backoffLimit: 5
template:
Expand All @@ -25,7 +26,8 @@ spec:
- -ec
- |
curl -s metrics-operator-service.keptn-lifecycle-toolkit-system.svc.cluster.local:9999/metrics > ~/out.txt
if grep -Fxq "# HELP keptnmetric_sample keptnmetric-sample" ~/out.txt
echo ~/out.txt
if grep -Fxq "# HELP $NAME $NAME" ~/out.txt
then
exit 0
fi
Expand All @@ -37,8 +39,9 @@ spec:
- /bin/sh
- -ec
- |
curl -s metrics-operator-service.keptn-lifecycle-toolkit-system.svc.cluster.local:9999/api/v1/metrics/keptn-lifecycle-toolkit-system/keptnmetric-sample > ~/out.txt
if grep -F "keptnmetric-sample" ~/out.txt
curl -s metrics-operator-service.keptn-lifecycle-toolkit-system.svc.cluster.local:9999/api/v1/metrics/$NAMESPACE/$NAME > ~/out.txt
echo ~/out.txt
if grep -F "$NAME" ~/out.txt
then
exit 0
fi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
apiVersion: batch/v1
kind: Job
metadata:
name: test
name: $NAME-job1
namespace: $NAMESPACE
spec:
backoffLimit: 0
backoffLimit: 3
template:
spec:
containers:
Expand All @@ -14,19 +15,27 @@ spec:
- -ec
- |
curl -s metrics-operator-service.keptn-lifecycle-toolkit-system.svc.cluster.local:9999/metrics > ~/out.txt
if grep -Fxq "# HELP keptnmetric_sample keptnmetric-sample" ~/out.txt
cat ~/out.txt
if grep -Fxq "# HELP $NAME $NAME" ~/out.txt
then
cat ~/out.txt
sleep 55
exit 1
fi
exit 0
- name: test-api-endpoint
image: curlimages/curl:8.00.1
args:
- /bin/sh
- -ec
- |
curl -s metrics-operator-service.keptn-lifecycle-toolkit-system.svc.cluster.local:9999/api/v1/metrics//keptnmetric-sample > ~/out.txt
if grep -F "keptnmetric-sample" ~/out.txt
curl -s metrics-operator-service.keptn-lifecycle-toolkit-system.svc.cluster.local:9999/api/v1/metrics/$NAMESPACE/$NAME > ~/out.txt
cat ~/out.txt
if grep -F "$NAME" ~/out.txt
then
cat ~/out.txt
sleep 55
exit 1
fi
exit 0
restartPolicy: Never

0 comments on commit 44c845c

Please sign in to comment.