Skip to content

Commit

Permalink
chore: migrate 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 authored and eljohnson92 committed Mar 5, 2024
1 parent 18ff77d commit dbf7a90
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 20 deletions.
12 changes: 12 additions & 0 deletions .chainsaw.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 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:
timeouts:
assert: 5m0s
cleanup: 5m0s
delete: 5m0s
error: 5m0s
exec: 5m0s
59 changes: 59 additions & 0 deletions .github/workflows/build_test_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,65 @@ jobs:
name: logs
path: .logs/*

chainsaw-test:
needs: [go-build-test, docker-build]
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.linode.com:443
api.github.com:443
github.com:443
gcr.io:443
proxy.golang.org:443
sum.golang.org:443
*.githubusercontent.com:443
docker.io:443
registry-1.docker.io:443
auth.docker.io:443
production.cloudflare.docker.com:443
storage.googleapis.com:443
registry.k8s.io:443
*.pkg.dev:443
*.amazonaws.com:443
*.blob.core.windows.net:443
quay.io:443
*.quay.io:443
api.snapcraft.io:443
cloud.tilt.dev:443
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'

- name: Docker cache
uses: ScribeMD/[email protected]
with:
key: docker-${{ runner.os }}-${{ hashFiles('go.sum') }}}

- name: Chainsaw test
run: make chainsaw-test
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
LINODE_TOKEN: ${{ secrets.LINODE_TOKEN }}

- name: Copy logs
if: ${{ always() }}
run: docker cp tilt-control-plane:/var/log .logs

- uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: logs
path: .logs/*

docker-build:
runs-on: ubuntu-latest
steps:
Expand Down
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,18 @@ test: manifests generate fmt vet envtest ## Run tests.
e2etest:
make --no-print-directory _e2etest # Workaround to force the flag on Github Action

local-deploy: kind ctlptl tilt kuttl kustomize clusterctl
local-deploy: kind ctlptl tilt kuttl chainsaw kustomize clusterctl
@echo -n "LINODE_TOKEN=$(LINODE_TOKEN)" > config/default/.env.linode
$(CTLPTL) apply -f .tilt/ctlptl-config.yaml
$(TILT) ci --timeout 240s -f Tiltfile

_e2etest: manifests generate local-deploy
ROOT_DIR="$(PWD)" $(KUTTL) test --config e2e/kuttl-config.yaml

.PHONY: chainsaw-test
chainsaw-test: manifests generate local-deploy
$(CHAINSAW) test ./e2e/linodecluster-controller

## --------------------------------------
## Build
## --------------------------------------
Expand Down Expand Up @@ -291,6 +295,7 @@ CONTROLLER_GEN ?= $(CACHE_BIN)/controller-gen
TILT ?= $(LOCALBIN)/tilt
KIND ?= $(LOCALBIN)/kind
KUTTL ?= $(LOCALBIN)/kubectl-kuttl
CHAINSAW ?= $(CACHE_BIN)/chainsaw
ENVTEST ?= $(CACHE_BIN)/setup-envtest
HUSKY ?= $(LOCALBIN)/husky
NILAWAY ?= $(LOCALBIN)/nilaway
Expand All @@ -304,12 +309,13 @@ CONTROLLER_TOOLS_VERSION ?= v0.14.0
TILT_VERSION ?= 0.33.6
KIND_VERSION ?= 0.20.0
KUTTL_VERSION ?= 0.15.0
CHAINSAW_VERSION ?= v0.1.7
HUSKY_VERSION ?= v0.2.16
NILAWAY_VERSION ?= latest
GOVULNC_VERSION ?= v1.0.1

.PHONY: tools
tools: $(KUSTOMIZE) $(CTLPTL) $(CLUSTERCTL) $(CONTROLLER_GEN) $(TILT) $(KIND) $(KUTTL) $(ENVTEST) $(HUSKY) $(NILAWAY) $(GOVULNC)
tools: $(KUSTOMIZE) $(CTLPTL) $(CLUSTERCTL) $(CONTROLLER_GEN) $(TILT) $(KIND) $(KUTTL) $(CHAINSAW) $(ENVTEST) $(HUSKY) $(NILAWAY) $(GOVULNC)

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
Expand Down Expand Up @@ -354,6 +360,11 @@ $(KUTTL): $(LOCALBIN)
curl -Lso $(KUTTL) https://github.com/kudobuilder/kuttl/releases/download/v$(KUTTL_VERSION)/kubectl-kuttl_$(KUTTL_VERSION)_$(OS)_$(ARCH)
chmod +x $(KUTTL)

.PHONY: chainsaw
chainsaw: $(CHAINSAW) ## Download chainsaw locally if necessary.
$(CHAINSAW): $(CACHE_BIN)
GOBIN=$(CACHE_BIN) go install github.com/kyverno/chainsaw@$(CHAINSAW_VERSION)

.PHONY: envtest
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
$(ENVTEST): $(LOCALBIN)
Expand Down
1 change: 0 additions & 1 deletion e2e/kuttl-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestSuite
testDirs:
- e2e/linodecluster-controller
- e2e/linodemachine-controller
- e2e/linodevpc-controller
- e2e/linodeobjectstoragebucket-controller
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# 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: minimal-linodecluster
spec:
steps:
- name: step-00
try:
- assert:
file: 00-assert.yaml
- name: step-01
try:
- apply:
file: 01-create-cluster.yaml
- name: step-02
try:
- apply:
file: 02-create-linodecluster.yaml
- assert:
file: 02-assert.yaml
- name: step-03
try:
- script:
env:
- name: TARGET_API
value: api.linode.com
- name: TARGET_API_VERSION
value: v4beta
- name: URI
value: nodebalancers
- name: FILTER
value: '{"label":"linodecluster-test-api-server"}'
content: |
set -e
curl -s \
-H "Authorization: Bearer $LINODE_TOKEN" \
-H "X-Filter: $FILTER" \
-H "Content-Type: application/json" \
"https://$TARGET_API/$TARGET_API_VERSION/$URI"
check:
($error): ~
(json_parse($stdout)):
results: 1
- name: step-04
try:
- delete:
ref:
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
name: cluster-test
- error:
file: 04-error.yaml
- name: step-05
try:
- script:
env:
- name: TARGET_API
value: api.linode.com
- name: TARGET_API_VERSION
value: v4beta
- name: URI
value: nodebalancers
- name: FILTER
value: '{"label":"linodecluster-test-api-server"}'
content: |
set -e
curl -s \
-H "Authorization: Bearer $LINODE_TOKEN" \
-H "X-Filter: $FILTER" \
-H "Content-Type: application/json" \
"https://$TARGET_API/$TARGET_API_VERSION/$URI"
check:
($error): ~
(json_parse($stdout)):
results: 0
- name: step-06
try:
- apply:
file: 06-cleanup-cluster.yaml

0 comments on commit dbf7a90

Please sign in to comment.