Skip to content

Commit

Permalink
basic kuttle stuff
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Bigler <nicolas.bigler@vshn.ch>
  • Loading branch information
TheBigLee committed Nov 30, 2023
1 parent f8e2188 commit 8ea7690
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 1 deletion.
20 changes: 20 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: E2E
on:
pull_request:
branches:
- master
jobs:
test-e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get KUBECONFIG
shell: bash
env:
LAB_KUBECONFIG: ${{ secrets.LAB_KUBECONFIG }}
run: |
echo "$LAB_KUBECONFIG" > kubeconfig
- name: Run tests
run: make e2e-test
env:
KUBECONFIG: kubeconfig
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ SHELL := bash

include Makefile.vars.mk

# testing
include tests/tests.mk

.PHONY: all
all: help

Expand Down
2 changes: 1 addition & 1 deletion component/component/rbac_e2e.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ local e2eSAToken = kube.Secret('appcat-e2e-github') + {
};

if params.services.vshn.e2eTests then {
'20_rbac_vshn_e2e_tests': [ e2eNs, e2eSA, e2eRoleBinding, e2eSAToken ]
'20_rbac_vshn_e2e_tests': [ e2eNs, e2eSA, e2eRoleBinding, e2eSAToken ],
} else {}
6 changes: 6 additions & 0 deletions tests/e2e/kuttl-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestSuite
testDirs:
- ./test/e2e/
namespace: appcat-e2e
timeout: 60
49 changes: 49 additions & 0 deletions tests/e2e/mariadb/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 600
---
apiVersion: vshn.appcat.vshn.io/v1
kind: VSHNMariaDB
metadata:
finalizers:
- finalizer.apiextensions.crossplane.io
name: mariadb-e2e-test
namespace: appcat-e2e
spec:
compositeDeletePolicy: Background
compositionRef:
name: vshnmariadb.vshn.appcat.vshn.io
compositionUpdatePolicy: Automatic
parameters:
backup: {}
service:
serviceLevel: besteffort
version: "11.2"
size:
plan: standard-2
tls:
authClients: true
enabled: true
resourceRef:
apiVersion: vshn.appcat.vshn.io/v1
kind: XVSHNMariaDB
writeConnectionSecretToRef:
name: mariadb-e2e-test-creds
status:
conditions:
- status: "True"
type: Synced
- reason: Available
status: "True"
type: Ready
---
apiVersion: v1
kind: Secret
type: connection.crossplane.io/v1alpha1
metadata:
name: mariadb-e2e-test-creds
namespace: appcat-e2e
ownerReferences:
- apiVersion: vshn.appcat.vshn.io/v1
kind: VSHNMariaDB
name: mariadb-e2e-test
11 changes: 11 additions & 0 deletions tests/e2e/mariadb/00-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: vshn.appcat.vshn.io/v1
kind: VSHNMariaDB
metadata:
name: mariadb-e2e-test
namespace: appcat-e2e
spec:
parameters:
size:
plan: standard-2
writeConnectionSecretToRef:
name: mariadb-e2e-test-creds
15 changes: 15 additions & 0 deletions tests/e2e/mariadb/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 240
---
apiVersion: batch/v1
kind: Job
metadata:
name: connect-mariadb
namespace: appcat-e2e
status:
conditions:
- type: Complete
status: 'True'
succeeded: 1
ready: 0
36 changes: 36 additions & 0 deletions tests/e2e/mariadb/01-connect.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: batch/v1
kind: Job
metadata:
name: connect-mariadb
namespace: appcat-e2e
spec:
backoffLimit: 10
template:
metadata:
labels:
e2e-test: mariadb
spec:
restartPolicy: Never
containers:
- name: connect
image: dockerhub.vshn.net/bitnami/mariadb:latest
imagePullPolicy: IfNotPresent
command:
- bash
args:
- -c
- echo "Testing Select...\n" && mariadb -h $MARIADB_HOST -u $MARIADB_USERNAME --password="$MARIADB_PASSWORD" -P $MARIADB_PORT --ssl-verify-server-cert --ssl-ca=/etc/mariadb-tls/ca.crt -e "select 1;"
envFrom:
- secretRef:
name: mariadb-e2e-test-creds
volumeMounts:
- name: mariadb-tls-secrets
mountPath: /etc/mariadb-tls
readOnly: true
volumes:
- name: mariadb-tls-secrets
secret:
secretName: mariadb-e2e-test-creds
items:
- key: ca.crt
path: ca.crt
17 changes: 17 additions & 0 deletions tests/e2e/mariadb/02-delete.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
delete:
# This will wait until resources are really gone
- apiVersion: batch/v1
kind: Job
name: connect-mariadb
namespace: appcat-e2e
- apiVersion: v1
kind: Pod
labels:
e2e-test: mariadb
namespace: appcat-e2e
- apiVersion: vshn.appcat.vshn.io/v1
kind: VSHNMariaDB
name: mariadb-e2e-test
namespace: appcat-e2e
35 changes: 35 additions & 0 deletions tests/tests.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
###
### E2E Tests
### with KUTTL (https://kuttl.dev)
###

go_bin ?= $(PWD)/.work/bin
$(go_bin):
@mkdir -p $@

kuttl_bin = $(go_bin)/kubectl-kuttl
$(kuttl_bin): export GOBIN = $(go_bin)
$(kuttl_bin): | $(go_bin)
go install github.com/kudobuilder/kuttl/cmd/kubectl-kuttl@latest

.PHONY: .e2e-test
e2e-test: $(kuttl_bin) ## Run e2e tests
GOBIN=$(go_bin) $(kuttl_bin) test ./tests/e2e --config ./tests/e2e/kuttl-test.yaml --suppress-log=Events
@rm -f kubeconfig
# kuttl leaves kubeconfig garbage: https://github.com/kudobuilder/kuttl/issues/297

.PHONY: .run-single-e2e
run-single-e2e:
GOBIN=$(go_bin) $(kuttl_bin) test ./tests/e2e --config ./tests/e2e/kuttl-test.yaml --suppress-log=Events --test $(test)
@rm -f kubeconfig

.PHONY: .e2e-test-clean
.e2e-test-clean:
@if [ -f $(KUBECONFIG) ]; then \
kubectl delete mariadb --all; \
kubectl delete jobs --all; \
kubectl delete pods --all; \
else \
echo "no kubeconfig found"; \
fi
rm -f $(kuttl_bin)

0 comments on commit 8ea7690

Please sign in to comment.