Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: chainsaw e2e test #29

Merged
merged 22 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ docs/
.gitignore
sonar-project.properties
LICENSE
chainsaw/
50 changes: 50 additions & 0 deletions .github/workflows/chainsaw.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# $schema: https://json.schemastore.org/github-workflow.json

name: chainsaw E2E test
on:
workflow_call:

jobs:
chainsaw-e2e-tests:
name: Chainsaw E2E test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Chainsaw
uses: kyverno/action-install-chainsaw@v0.2.12

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: './go.mod'
id: go

- name: extract kubernetes version
id: k8s_version
run: echo "k8s_version=$(go list -m -f '{{.Version}}' k8s.io/kubernetes)" >> $GITHUB_OUTPUT

- name: Create kind cluster
uses: helm/kind-action@v1
with:
node_image: "kindest/node:${{ steps.k8s_version.outputs.k8s_version }}"

- name: Install helm
uses: azure/setup-helm@v4

- name: Check chainsaw install
run: chainsaw version

- name: Check kind cluster install
run: |
kubectl version
kubectl wait --for=jsonpath='{.status.phase}'=Running pod --all -A --timeout 120s
kubectl get pods -A
kubectl get nodes

- name: Check helm version
run: helm version

- name: run chainsaw
run: chainsaw test chainsaw/*
17 changes: 16 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# $schema: https://json.schemastore.org/github-workflow.json
name: Build docker image

on:
Expand All @@ -21,7 +22,7 @@ env:
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
docker-build:

runs-on: ubuntu-latest
permissions:
Expand All @@ -31,6 +32,8 @@ jobs:
# with sigstore/fulcio when running outside of PRs.
id-token: write

outputs:
dockerTag: ${{ steps.docker-tag.outputs.dockerTag }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand Down Expand Up @@ -76,4 +79,16 @@ jobs:
build-args: ${{ github.event_name == 'push' && github.ref_type == 'tag' && format('RELEASE_VERSION={0}', github.ref_name) || '' }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache
cache-to: ${{ github.event_name != 'pull_request' && format( 'type=registry,ref={0}/{1}:buildcache,mode=max', env.REGISTRY, env.IMAGE_NAME ) || '' }}
- name: output tag
id: docker-tag
run: |
echo "dockerTag=$( echo "${{ steps.meta.outputs.tags }}" | cut -d ',' -f 1 | cut -d ':' -f 2 | head -n 1 )" >> $GITHUB_OUTPUT

chainsaw-e2e-tests:
uses: ./.github/workflows/chainsaw.yaml
needs:
- docker-build
strategy:
matrix:
IMAGE_TAG:
- "${{ needs.docker-build.outputs.dockerTag }}"
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ docker:

local:
bin/thundering-herd-scheduler --config manifests/development/scheduler.yaml

kind:
echo "{\"kind\": \"Cluster\", \"apiVersion\": \"kind.x-k8s.io/v1alpha4\", \"nodes\":[{\"role\":\"control-plane\", \"image\": \"kindest/node:$(go list -m -f '{{.Version}}' k8s.io/kubernetes)\"}]}" | kind create cluster --config -
chainsaw:
IMAGE_TAG=v1.30.0-0 chainsaw test
72 changes: 72 additions & 0 deletions chainsaw/e2e-test/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# 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: e2e-test
spec:
timeouts:
apply: 30s
assert: 15s
cleanup: 2m
delete: 1m
error: 1m
exec: 1m
steps:
- name: Install thundering-herd-scheduler
try:
- description: Install thundering-herd-scheduler
script:
timeout: 2m
content: |
helm upgrade --install --namespace=kube-system thundering-herd-scheduler ../../charts/thundering-herd-scheduler --wait --timeout 90s --set replicaCount=1 --set image.tag=${IMAGE_TAG}
env:
- name: IMAGE_TAG
value: (env('IMAGE_TAG'))
cleanup:
- script:
timeout: 1m
content: |
helm uninstall --namespace=kube-system thundering-herd-scheduler --wait --timeout 45s
- name: perform test
try:
- description: install example workload
apply:
file: ../../manifests/development/example.yaml
- description: wait for deployment to be completed
wait:
apiVersion: apps/v1
kind: Deployment
timeout: 5m
for:
jsonPath:
path: .status.readyReplicas
value: "5"
- description: find if "delay" events present
script:
content: |
kubectl get events -n $NAMESPACE -ojson | jq -r '[.items[] | select(.message == "0/1 nodes are available: 1 rejected due to timeout after waiting 25s at plugin ThunderingHerdScheduling.")] | length > 0'
env:
- name: NAMESPACE
value: ($namespace)
check:
(contains($stdout, 'true')): true
catch:
- script:
content: helm list
timeout: 1m

- get:
kind: Pod
apiVersion: v1
namespace: kube-system
- get:
kind: Pod
apiVersion: v1
- get:
kind: Deployment
apiVersion: apps/v1
- events: {}
- podLogs:
timeout: 30s
tail: 200
selector: app.kubernetes.io/instance=thundering-herd-scheduler
Loading