Skip to content

Commit

Permalink
chore: migrate testanalysis to chainsaw
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
eddycharly committed Feb 6, 2024
1 parent 62e667c commit 2218d57
Show file tree
Hide file tree
Showing 30 changed files with 1,279 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ 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/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/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!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
apiVersion: v1
kind: Namespace
metadata:
name: testy
---
apiVersion: metrics.keptn.sh/v1beta1
kind: AnalysisValueTemplate
metadata:
name: ready
namespace: testy
spec:
provider:
name: my-mocked-provider
namespace: testy
query: 'sum(kube_pod_container_status_ready{namespace="{{.ns}}"})'
---
apiVersion: metrics.keptn.sh/v1beta1
kind: AnalysisDefinition
metadata:
name: ed-my-proj-dev-svc1
namespace: testy
spec:
objectives:
- analysisValueTemplateRef:
name: ready
namespace: testy
target:
failure:
lessThan:
fixedValue: 2
warning:
lessThan:
fixedValue: 3
weight: 1
keyObjective: false
totalScore:
passPercentage: 90
warningPercentage: 75
---
apiVersion: metrics.keptn.sh/v1beta1
kind: Analysis
metadata:
name: analysis-sample
namespace: testy
spec:
timeframe:
from: 2023-09-14T07:33:19Z
to: 2023-09-14T08:33:19Z
args:
"ns": "keptn-system"
analysisDefinition:
name: ed-my-proj-dev-svc1
namespace: testy
status:
storedValues:
my-provider-query-1:
objectiveReference:
name: objective-template-1
value: 1
errMsg: ""

---
apiVersion: metrics.keptn.sh/v1beta1
kind: KeptnMetricsProvider
metadata:
name: my-mocked-provider
namespace: testy
spec:
type: prometheus
targetServer: "http://mockserver.testy.svc.cluster.local:1080"
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
apiVersion: v1
kind: Service
metadata:
name: mockserver
namespace: testy
spec:
ports:
- name: serviceport
port: 1080
protocol: TCP
targetPort: serviceport
selector:
app: mockserver
sessionAffinity: None
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: mockserver
name: mockserver
namespace: testy
spec:
replicas: 1
selector:
matchLabels:
app: mockserver
template:
metadata:
labels:
app: mockserver
name: mockserver
spec:
containers:
- env:
- name: MOCKSERVER_LOG_LEVEL
value: INFO
- name: SERVER_PORT
value: "1080"
image: mockserver/mockserver:mockserver-5.13.0
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 10
initialDelaySeconds: 10
periodSeconds: 5
successThreshold: 1
tcpSocket:
port: serviceport
timeoutSeconds: 1
name: mockserver
ports:
- containerPort: 1080
name: serviceport
protocol: TCP
readinessProbe:
failureThreshold: 10
initialDelaySeconds: 2
periodSeconds: 2
successThreshold: 1
tcpSocket:
port: serviceport
timeoutSeconds: 1
volumeMounts:
- mountPath: /config
name: config-volume
- mountPath: /libs
name: libs-volume
terminationGracePeriodSeconds: 30
volumes:
- configMap:
defaultMode: 420
name: mockserver-config
optional: true
name: config-volume
- configMap:
defaultMode: 420
name: mockserver-config
optional: true
name: libs-volume
---
kind: ConfigMap
apiVersion: v1
metadata:
name: mockserver-config
namespace: testy
data:
initializerJson.json: |-
[
{
"httpRequest": {
"path": "/api/v1/query_range",
"method": "POST"
},
"httpResponse": {
"body": {
"status": "success",
"data": {
"resultType": "matrix",
"result": [
{
"metric": {
"__name__": "metric-name",
"job": "",
"instance": ""
},
"values": [[1669714193.275, "4"]]
}
]
}
},
"statusCode": 200
}
}
]
mockserver.properties: |-
###############################
# MockServer & Proxy Settings #
###############################
# Socket & Port Settings
# socket timeout in milliseconds (default 120000)
mockserver.maxSocketTimeout=120000
# Certificate Generation
# dynamically generated CA key pair (if they don't already exist in
specified directory)
mockserver.dynamicallyCreateCertificateAuthorityCertificate=true
# save dynamically generated CA key pair in working directory
mockserver.directoryToSaveDynamicSSLCertificate=.
# certificate domain name (default "localhost")
mockserver.sslCertificateDomainName=localhost
# comma separated list of ip addresses for Subject Alternative Name domain
names (default empty list)
mockserver.sslSubjectAlternativeNameDomains=www.example.com,www.another.com
# comma separated list of ip addresses for Subject Alternative Name ips
(default empty list)
mockserver.sslSubjectAlternativeNameIps=127.0.0.1
# CORS
# enable CORS for MockServer REST API
mockserver.enableCORSForAPI=true
# enable CORS for all responses
mockserver.enableCORSForAllResponses=true
# Json Initialization
mockserver.initializationJsonPath=/config/initializerJson.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: metrics.keptn.sh/v1beta1
kind: Analysis
metadata:
name: analysis-sample
namespace: testy
spec:
analysisDefinition:
name: ed-my-proj-dev-svc1
status:
storedValues:
ready-testy:
objectiveReference:
name: ready
namespace: testy
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: metrics.keptn.sh/v1beta1
kind: Analysis
metadata:
name: analysis-sample
namespace: testy
spec:
analysisDefinition:
name: ed-my-proj-dev-svc1
status:
pass: true
raw: '{"objectiveResults":[{"result":{"failResult":{"operator":{"lessThan":{"fixedValue":"2"}},"fulfilled":false},"warnResult":{"operator":{"lessThan":{"fixedValue":"3"}},"fulfilled":false},"warning":false,"pass":true},"objective":{"analysisValueTemplateRef":{"name":"ready","namespace":"testy"},"target":{"failure":{"lessThan":{"fixedValue":"2"}},"warning":{"lessThan":{"fixedValue":"3"}}},"weight":1},"value":4,"query":"sum(kube_pod_container_status_ready{namespace=\"keptn-system\"})","score":1}],"totalScore":1,"maximumScore":1,"pass":true,"warning":false}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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: analysis-controller-existing-status
spec:
steps:
- name: step-00
try:
- apply:
file: 00-install.yaml
- assert:
file: assert-1.yaml
catch:
- script:
content: kubectl logs -l control-plane=metrics-operator -n keptn-system
- script:
content: kubectl describe Analysis -n $NAMESPACE
- name: step-01
try:
- apply:
file: 01-install.yaml
- assert:
file: assert-2.yaml
catch:
- script:
content: kubectl logs -l control-plane=metrics-operator -n keptn-system
- script:
content: kubectl describe Analysis -n $NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: metrics.keptn.sh/v1beta1
kind: Analysis
metadata:
name: analysis-sample
spec:
analysisDefinition:
name: ed-my-proj-dev-svc1
status:
pass: true
raw: '{"objectiveResults":[{"result":{"failResult":{"operator":{"lessThan":{"fixedValue":"5"}},"fulfilled":false},"warnResult":{"operator":{"lessThan":{"fixedValue":"4"}},"fulfilled":false},"warning":false,"pass":true},"objective":{"analysisValueTemplateRef":{"name":"value-1"},"target":{"failure":{"lessThan":{"fixedValue":"5"}},"warning":{"lessThan":{"fixedValue":"4"}}},"weight":2},"value":11,"query":"query-1","score":2},{"result":{"failResult":{"operator":{"greaterThan":{"fixedValue":"20"}},"fulfilled":false},"warnResult":{"operator":{"greaterThan":{"fixedValue":"15"}},"fulfilled":true},"warning":true,"pass":false},"objective":{"analysisValueTemplateRef":{"name":"value-2"},"target":{"failure":{"greaterThan":{"fixedValue":"20"}},"warning":{"greaterThan":{"fixedValue":"15"}}},"weight":1},"value":20,"query":"query-2","score":0.5},{"result":{"failResult":{"operator":{"notInRange":{"lowBound":"25","highBound":"35"}},"fulfilled":false},"warnResult":{"operator":{},"fulfilled":false},"warning":false,"pass":true},"objective":{"analysisValueTemplateRef":{"name":"value-3"},"target":{"failure":{"notInRange":{"lowBound":"25","highBound":"35"}}},"weight":1},"value":30,"query":"query-3","score":1}],"totalScore":3.5,"maximumScore":4,"pass":true,"warning":false}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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: analysis-controller-multiple-providers
spec:
steps:
- name: step-00
try:
- script:
content: |
envsubst < mock-server.yaml | kubectl apply -f -
- script:
content: |
envsubst < install.yaml | kubectl apply -f - -n $NAMESPACE
- name: step-01
try:
- assert:
file: assert-1.yaml
catch:
- script:
content: kubectl logs -l control-plane=metrics-operator -n keptn-system
- script:
content: kubectl describe Analysis -n $NAMESPACE

Loading

0 comments on commit 2218d57

Please sign in to comment.