Skip to content

Commit

Permalink
chore: migrate testcertificate and testmetrics to chainsaw (#2942)
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
  • Loading branch information
eddycharly committed Feb 6, 2024
1 parent f2d18e6 commit 62e667c
Show file tree
Hide file tree
Showing 32 changed files with 748 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ envsubst
envtest
errorlint
Etco
euo
evaluatemetrics
evaluationdefinition
evaluationhandler
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ jobs:
working-directory: .
run: make chainsaw-integration-test-allowed-namespaces

# - name: (Chainsaw) Run Integration Tests
# if: inputs.allowed-namespaces == 'allowed_ns_off'
# working-directory: .
# run: make integration-test
- name: (Chainsaw) Run Integration Tests
if: inputs.allowed-namespaces == 'allowed_ns_off'
working-directory: .
run: make chainsaw-integration-test

- name: Create reports
if: failure()
Expand Down
1 change: 1 addition & 0 deletions .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
sonar.projectKey=keptn_lifecycle-toolkit
sonar.projectName=lifecycle-toolkit
sonar.exclusions=test/kuttl/**/*.yaml,\
test/chainsaw/**/*.yaml,\
docs/docs/**/*.yaml,\
test/prometheus/**/*.yaml,\
examples/**/*.yaml
Expand Down
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ integration-test-allowed-namespaces-local: install-prometheus
# CHAINSAW #
############

.PHONY: chainsaw-integration-test #these tests should run on a real cluster!
chainsaw-integration-test:
kubectl apply -f ./lifecycle-operator/config/crd/bases
# chainsaw test --test-dir ./test/chainsaw/integration/
chainsaw test --test-dir ./test/chainsaw/testmetrics/
# chainsaw test --test-dir ./test/chainsaw/testanalysis/
chainsaw test --test-dir ./test/chainsaw/testcertificate/

.PHONY: chainsaw-integration-test-local #these tests should run on a real cluster!
chainsaw-integration-test-local:
kubectl apply -f ./lifecycle-operator/config/crd/bases
# chainsaw test --test-dir ./test/chainsaw/integration/ --config ./.chainsaw-local.yaml
chainsaw test --test-dir ./test/chainsaw/testmetrics/ --config ./.chainsaw-local.yaml
# chainsaw test --test-dir ./test/chainsaw/testanalysis/ --config ./.chainsaw-local.yaml
chainsaw test --test-dir ./test/chainsaw/testcertificate/ --config ./.chainsaw-local.yaml

.PHONY: chainsaw-integration-test-scheduling-gates #these tests should run on a real cluster!
chainsaw-integration-test-scheduling-gates:
chainsaw test --test-dir ./test/chainsaw/scheduling-gates/
Expand Down
24 changes: 24 additions & 0 deletions test/chainsaw/testcertificate/cert-recreates/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# certificate is recreated and there are operators instances available
apiVersion: v1
kind: Secret
metadata:
name: keptn-certs
namespace: keptn-system
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: keptn-system
labels:
control-plane: metrics-operator
status:
readyReplicas: 1
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: keptn-system
labels:
control-plane: lifecycle-operator
status:
readyReplicas: 1
24 changes: 24 additions & 0 deletions test/chainsaw/testcertificate/cert-recreates/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# certificate is recreated and there are operators instances available
apiVersion: v1
kind: Secret
metadata:
name: keptn-certs
namespace: keptn-system
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: keptn-system
labels:
control-plane: metrics-operator
status:
readyReplicas: 1
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: keptn-system
labels:
control-plane: lifecycle-operator
status:
readyReplicas: 1
6 changes: 6 additions & 0 deletions test/chainsaw/testcertificate/cert-recreates/01-delete.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# second scenario: certificate is removed with no restart
apiVersion: v1
kind: Secret
metadata:
name: keptn-certs
namespace: keptn-system
26 changes: 26 additions & 0 deletions test/chainsaw/testcertificate/cert-recreates/02-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# certificate is recreated and there are operators instances available
apiVersion: v1
kind: Secret
metadata:
name: keptn-certs
namespace: keptn-system
annotations:
mycert: "true" # make sure this is the latest secret
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
control-plane: metrics-operator
namespace: keptn-system
status:
readyReplicas: 1
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
control-plane: lifecycle-operator
namespace: keptn-system
status:
readyReplicas: 1
13 changes: 13 additions & 0 deletions test/chainsaw/testcertificate/cert-recreates/02-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# third scenario: certificate is invalid/expired
apiVersion: v1
kind: Secret
metadata:
name: keptn-certs
namespace: keptn-system
annotations:
mycert: "true"
data:
# yamllint disable rule:line-length
tls.crt: "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNkekNDQWg2Z0F3SUJBZ0lRZUpBWkJMcmxCY2VqNzh3cm4wV1ZIekFLQmdncWhrak9QUVFEQWpDQmlURUwKa0ZGY1FpY29hdE8yRFJnPQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0t"
# yamllint disable rule:line-length
tls.key: "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNkekNDQWg2Z0F3SUJBZ0lRZUpBWkJMcmxCY2VqNzh3cm4wV1ZIekFLQmdncWhrak9QUVFEQWpDQmlURUwKa0ZGY1FpY29hdE8yRFJnPQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0t"
44 changes: 44 additions & 0 deletions test/chainsaw/testcertificate/cert-recreates/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: cert-recreates
spec:
steps:
- name: step-00
try:
- delete:
ref:
apiVersion: v1
kind: Secret
namespace: keptn-system
name: keptn-certs
- script:
content: |
set -e
kubectl rollout restart deployment -n keptn-system -l control-plane=lifecycle-operator
kubectl rollout restart deployment -n keptn-system -l control-plane=metrics-operator
- assert:
file: 00-assert.yaml
- name: step-01
try:
- apply:
file: 01-delete.yaml
- assert:
file: 01-assert.yaml
- name: step-02
try:
- apply:
file: 02-install.yaml
- script:
content: |
str1=$(kubectl get secret keptn-certs -n keptn-system -o=go-template='{{index .data "tls.crt"}}')
str2="LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNkekNDQWg2Z0F3SUJBZ0lRZUpBWkJMcmxCY2VqNzh3cm4wV1ZIekFLQmdncWhrak9QUVFEQWpDQmlURUwKa0ZGY1FpY29hdE8yRFJnPQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0t"
if [ "$str1" == "$str2" ]; then
echo "Strings are equal" $str1
exit 1
else
echo "Strings are not equal" $str1 "!=" $str2
fi
- assert:
file: 02-assert.yaml
49 changes: 49 additions & 0 deletions test/chainsaw/testmetrics/metrics-hpa/00-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: podtato-head-entry
labels:
app: podtato-head
spec:
selector:
matchLabels:
component: podtato-head-entry
replicas: 1
template:
metadata:
labels:
component: podtato-head-entry
spec:
terminationGracePeriodSeconds: 5
containers:
- name: server
image: ghcr.io/podtato-head/entry:0.2.8
imagePullPolicy: Always
resources:
limits:
cpu: 10m
memory: 128Mi
requests:
cpu: 5m
memory: 64Mi
ports:
- containerPort: 9000
env:
- name: PODTATO_PORT
value: "9000"
---
apiVersion: v1
kind: Service
metadata:
name: podtato-head-entry
labels:
app: podtato-head
spec:
selector:
component: podtato-head-entry
ports:
- name: http
port: 9000
protocol: TCP
targetPort: 9000
type: ClusterIP
30 changes: 30 additions & 0 deletions test/chainsaw/testmetrics/metrics-hpa/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
creationTimestamp: null
name: metrics-hpa
spec:
steps:
- name: step-00
try:
- apply:
file: 00-install.yaml
- script:
content: |
kubectl apply -f mock-server.yaml -n $NAMESPACE
- script:
content: |
echo "registering the metric"
envsubst < metric.yaml | kubectl apply -f - -n $NAMESPACE
echo "configuring HPA"
kubectl apply -f hpa.yaml -n $NAMESPACE
catch:
- podLogs:
selector: app=podtato-head
- script:
content: |
kubectl logs -l app=metrics-operator -n keptn-system
kubectl describe keptnmetric podtatometric -n $NAMESPACE
kubectl describe keptnmetricsprovider dynatrace -n $NAMESPACE
kubectl describe pods -l app=podtato-head -n $NAMESPACE
15 changes: 15 additions & 0 deletions test/chainsaw/testmetrics/metrics-hpa/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: podtato-head-entry
labels:
app: podtato-head
spec:
selector:
matchLabels:
component: podtato-head-entry
replicas: 3
template:
metadata:
labels:
component: podtato-head-entry
23 changes: 23 additions & 0 deletions test/chainsaw/testmetrics/metrics-hpa/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: podtato-metrics-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: podtato-head-entry
minReplicas: 1
maxReplicas: 3
metrics:
- type: Object
object:
metric:
name: cpu-throttling
describedObject:
apiVersion: metrics.keptn.sh/v1beta1
kind: KeptnMetric
name: cpu-throttling
target:
type: Value
value: "0.05"
19 changes: 19 additions & 0 deletions test/chainsaw/testmetrics/metrics-hpa/metric.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: metrics.keptn.sh/v1beta1
kind: KeptnMetricsProvider
metadata:
name: my-provider
spec:
type: prometheus
targetServer: "http://mockserver.$NAMESPACE.svc.cluster.local:1080"
---
apiVersion: metrics.keptn.sh/v1beta1
kind: KeptnMetric
metadata:
name: cpu-throttling
spec:
provider:
name: my-provider
query: 'avg(rate(container_cpu_cfs_throttled_seconds_total{container="server", namespace="podtato-metrics"}))'
fetchIntervalSeconds: 10
range:
interval: "1m"

0 comments on commit 62e667c

Please sign in to comment.