Skip to content

Commit

Permalink
chore: migrate e2e tests from kuttl 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 Jan 26, 2024
1 parent b31ea78 commit 8d7e679
Show file tree
Hide file tree
Showing 15 changed files with 395 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .chainsaw-local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/configuration-chainsaw-v1alpha1.json
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Configuration
metadata:
name: configuration-local
spec:
timeouts:
assert: 5m
cleanup: 5m
error: 5m
11 changes: 11 additions & 0 deletions .chainsaw.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/configuration-chainsaw-v1alpha1.json
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Configuration
metadata:
name: configuration
spec:
skipDelete: true
timeouts:
assert: 6m40s
cleanup: 6m40s
error: 6m40s
2 changes: 2 additions & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ carryforward
certificatehandler
certmanager
certwebhook
chainsaw
Chans
Checkmarx
clientgoscheme
Expand Down Expand Up @@ -370,6 +371,7 @@ kustomizeconfig
kuttl
kwi
kwv
kyverno
lastword
Lato
LFC
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,50 @@ jobs:
with:
name: logs-integration-tests-${{ inputs.scheduling-gates }}-${{ inputs.allowed-namespaces }}
path: .github/scripts/logs

run-chainsaw-test:
name: Run Chainsaw Tests
runs-on: ubuntu-22.04
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Setup cluster
uses: ./.github/actions/deploy-keptn-on-cluster
with:
runtime_tag: ${{ inputs.runtime_tag }}
scheduling-gates: ${{ inputs.scheduling-gates }}
allowed-namespaces: ${{ inputs.allowed-namespaces }}

- name: Install and expose Prometheus
uses: ./.github/actions/deploy-prometheus-on-cluster

- name: Install Chainsaw
uses: kyverno/action-install-chainsaw@56be3cb4ec65a987b6ef4d7ab3a55ee17760a57c # v0.1.2

- name: (Chainsaw) Run Scheduling Gates Integration Tests
if: inputs.scheduling-gates == 'gates_on' && inputs.allowed-namespaces == 'allowed_ns_off'
working-directory: .
run: chainsaw test --test-dir ./test-chainsaw/scheduling-gates

- name: (Chainsaw) Run Allowed namespaces Integration Tests
if: inputs.allowed-namespaces == 'allowed_ns_on'
working-directory: .
run: chainsaw test --test-dir ./test-chainsaw/allowed-namespaces

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

- name: Create reports
if: failure()
working-directory: ./.github/scripts
run: ./create-reports-full.sh

- name: Upload cluster logs
if: failure()
uses: actions/upload-artifact@v3
with:
name: logs-chainsaw-integration-tests-${{ inputs.scheduling-gates }}-${{ inputs.allowed-namespaces }}
path: .github/scripts/logs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: test
name: test
namespace: allowed-ns-test
status:
readyReplicas: 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: allowed-ns-test
annotations:
keptn.sh/lifecycle-toolkit: enabled
---
apiVersion: lifecycle.keptn.sh/v1beta1
kind: KeptnTaskDefinition
metadata:
name: pre-deployment-hello
namespace: allowed-ns-test
spec:
function:
inline:
code: |
console.log("Pre-Deployment Task has been executed");
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: test
name: test
namespace: allowed-ns-test
annotations:
keptn.sh/workload: waiter
keptn.sh/version: "0.4"
keptn.sh/pre-deployment-tasks: pre-deployment-hello
keptn.sh/post-deployment-tasks: pre-deployment-hello
spec:
replicas: 2
selector:
matchLabels:
app: test
strategy: {}
template:
metadata:
labels:
app: test
spec:
containers:
- image: busybox
name: busybox
command: ['sh', '-c', 'echo The app is running! && sleep infinity']
initContainers:
- name: init-myservice
image: busybox:1.36.1
command: ['sh', '-c', 'sleep 10']
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: lifecycle.keptn.sh/v1beta1
kind: KeptnWorkload
metadata:
name: waiter-waiter
namespace: allowed-ns-test
---
apiVersion: lifecycle.keptn.sh/v1beta1
kind: KeptnWorkloadVersion
metadata:
name: waiter-waiter-0.4
namespace: allowed-ns-test
status:
currentPhase: Completed
deploymentStatus: Succeeded
postDeploymentEvaluationStatus: Succeeded
postDeploymentStatus: Succeeded
postDeploymentTaskStatus:
- status: Succeeded
definitionName: pre-deployment-hello
preDeploymentEvaluationStatus: Succeeded
preDeploymentStatus: Succeeded
preDeploymentTaskStatus:
- status: Succeeded
definitionName: pre-deployment-hello
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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: simple-deployment-allowed
spec:
steps:
- name: step-00
try:
- apply:
file: 00-install.yaml
- assert:
file: 00-assert.yaml
- name: step-01
try:
- assert:
file: 01-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: test
name: test
namespace: not-allowed-ns-test
status:
readyReplicas: 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: not-allowed-ns-test
annotations:
keptn.sh/lifecycle-toolkit: enabled
---
apiVersion: lifecycle.keptn.sh/v1beta1
kind: KeptnTaskDefinition
metadata:
name: pre-deployment-hello
namespace: not-allowed-ns-test
spec:
function:
inline:
code: |
console.log("Pre-Deployment Task has been executed");
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: test
name: test
namespace: not-allowed-ns-test
annotations:
keptn.sh/workload: waiter
keptn.sh/version: "0.4"
keptn.sh/pre-deployment-tasks: pre-deployment-hello
keptn.sh/post-deployment-tasks: pre-deployment-hello
spec:
replicas: 2
selector:
matchLabels:
app: test
strategy: {}
template:
metadata:
labels:
app: test
spec:
containers:
- image: busybox
name: busybox
command: ['sh', '-c', 'echo The app is running! && sleep infinity']
initContainers:
- name: init-myservice
image: busybox:1.36.1
command: ['sh', '-c', 'sleep 10']
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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: simple-deployment-not-allowed
spec:
steps:
- name: step-00
try:
- apply:
file: 00-install.yaml
- assert:
file: 00-assert.yaml
- name: step-01
try:
# we expect none of these resources to be present
- error:
resource:
apiVersion: lifecycle.keptn.sh/v1beta1
kind: KeptnTask
metadata:
namespace: not-allowed-ns-test
- error:
resource:
apiVersion: lifecycle.keptn.sh/v1beta1
kind: KeptnWorkload
metadata:
namespace: not-allowed-ns-test
- error:
resource:
apiVersion: lifecycle.keptn.sh/v1beta1
kind: KeptnApp
metadata:
namespace: not-allowed-ns-test
20 changes: 20 additions & 0 deletions test-chainsaw/scheduling-gates/simple-deployment/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: test
name: test
status:
readyReplicas: 1
---
apiVersion: v1
kind: Pod
metadata:
annotations:
keptn.sh/scheduling-gate-removed: "true"
labels:
app: test
spec:
schedulerName: default-scheduler
status:
phase: Running
40 changes: 40 additions & 0 deletions test-chainsaw/scheduling-gates/simple-deployment/00-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: lifecycle.keptn.sh/v1beta1
kind: KeptnTaskDefinition
metadata:
name: pre-deployment-hello
spec:
function:
inline:
code: |
console.log("Pre-Deployment Task has been executed");
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: test
name: test
spec:
replicas: 1
selector:
matchLabels:
app: test
strategy: {}
template:
metadata:
labels:
app: test
annotations:
keptn.sh/workload: waiter
keptn.sh/version: "0.4"
keptn.sh/pre-deployment-tasks: pre-deployment-hello
keptn.sh/post-deployment-tasks: pre-deployment-hello
spec:
containers:
- image: busybox
name: busybox
command: ['sh', '-c', 'echo The app is running! && sleep infinity']
initContainers:
- name: init-myservice
image: busybox:1.36.1
command: ['sh', '-c', 'sleep 30']
32 changes: 32 additions & 0 deletions test-chainsaw/scheduling-gates/simple-deployment/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: lifecycle.keptn.sh/v1beta1
kind: KeptnWorkload
metadata:
name: waiter-waiter
---
apiVersion: lifecycle.keptn.sh/v1beta1
kind: KeptnWorkloadVersion
metadata:
name: waiter-waiter-0.4
status:
currentPhase: Completed
deploymentStatus: Succeeded
postDeploymentEvaluationStatus: Succeeded
postDeploymentStatus: Succeeded
postDeploymentTaskStatus:
- definitionName: pre-deployment-hello
status: Succeeded
preDeploymentEvaluationStatus: Succeeded
preDeploymentStatus: Succeeded
preDeploymentTaskStatus:
- definitionName: pre-deployment-hello
status: Succeeded
---
apiVersion: lifecycle.keptn.sh/v1beta1
kind: KeptnApp
metadata:
name: waiter
---
apiVersion: lifecycle.keptn.sh/v1beta1
kind: KeptnAppVersion
metadata:
name: waiter-0.4-6b86b273
Loading

0 comments on commit 8d7e679

Please sign in to comment.