Skip to content

Commit 296391d

Browse files
committed
feat(operator/ci): add unit and end to end test workflows
1 parent ae6b657 commit 296391d

File tree

5 files changed

+108
-16
lines changed

5 files changed

+108
-16
lines changed

.github/workflows/operator-ci.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Operator unit and functional tests
2+
on:
3+
pull_request:
4+
paths:
5+
- operator/**
6+
- .github/workflows/operator-ci.yaml
7+
env:
8+
REGISTRY: ghcr.io
9+
jobs:
10+
unit-test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Setup Go 1.23
15+
uses: actions/setup-go@v5
16+
with:
17+
go-version: 1.23
18+
- name: Unit tests
19+
run: |
20+
cd operator
21+
make unit-tests
22+
k8s-tests:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
with:
27+
fetch-tags: true
28+
fetch-depth: 0
29+
- name: Setup Go 1.23
30+
uses: actions/setup-go@v5
31+
with:
32+
go-version: 1.23
33+
- name: Log in to the Container registry
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
- name: Kubernetes KinD Cluster
40+
id: kind
41+
uses: helm/kind-action@v1
42+
with:
43+
version: v0.26.0
44+
install_only: true
45+
- name: end-to-end-tests
46+
run: |
47+
cd operator
48+
GITHUB_TOKEN=${{ secrets.github_token }} make create-kind-cluster
49+
make e2e-tests

k8s-tests/chainsaw/skyhook/interrupt-grouping/chainsaw-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ spec:
2020
name: interrupt-grouping
2121
format: yaml
2222
timeouts:
23-
assert: 360s ## needs to be long to run at the same time as the other interrupt test, they we fight each other to cordon nodes
23+
assert: 600s ## needs to be long to run at the same time as the other interrupt test, they we fight each other to cordon nodes
2424
# skip: true
2525
steps:
2626
- try:

operator/Makefile

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ GO_LDFLAGS := -ldflags "-X github.com/NVIDIA/skyhook/internal/version.GIT_SHA=$
4343
-X github.com/NVIDIA/skyhook/internal/version.VERSION=$(VERSION)"
4444
GOFLAGS := -mod=vendor
4545

46-
# CONTAINER_TOOL defines the container tool to be used for building images.
46+
# DOCKER_CMD defines the container tool to be used for building images.
4747
# Be aware that the target commands are only tested with Docker which is
4848
# scaffolded by default. However, you might want to replace it to use other
4949
# tools. (i.e. podman)
50-
CONTAINER_TOOL ?= podman
50+
DOCKER_CMD ?= podman
51+
52+
ifdef CI
53+
DOCKER_CMD = docker
54+
endif
5155

5256
# Setting SHELL to bash allows bash commands to be executed by recipes.
5357
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
@@ -137,7 +141,7 @@ $(REPORTING):
137141
.PHONY: test
138142
test:: reporting manifests generate fmt vet lint helm-tests e2e-tests unit-tests ## Run all tests.
139143

140-
ifndef GITLAB_CI
144+
ifndef CI
141145
## we double define test so we can do thing different if in ci vs local
142146
test:: merge-coverage
143147
echo "Total Code Coverage: $(shell go tool cover -func $(REPORTING)/cover.out | grep total | awk '{print $$NF}')"
@@ -153,19 +157,21 @@ watch-tests: ## watch unit tests and auto run on changes.
153157
$(GINKGO) watch $(GOFLAGS) -p -vv ./...
154158

155159
.PHONY: unit-test
156-
unit-tests: reporting envtest ginkgo kill ## Run unit tests.
157-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" $(GINKGO) $(GOFLAGS) --coverprofile=$(REPORTING)/unit.coverprofile -vv --trace --junit-report=$(REPORTING)/unit.xml --keep-going --timeout=90s ./...
160+
unit-tests: reporting manifests generate envtest ginkgo kill ## Run unit tests.
161+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" $(GINKGO) $(GOFLAGS) --coverprofile=$(REPORTING)/unit.coverprofile -vv --trace --junit-report=$(REPORTING)/unit.xml --keep-going --timeout=180s ./...
158162

159163
## exec time is for things like scripts and commands, if we new more of these, might want to switch to a config file
160164
## https://kyverno.github.io/chainsaw/latest/reference/commands/chainsaw_test/
161165
## https://kyverno.github.io/chainsaw/latest/configuration/file/
162166
CHAINSAW_ARGS:=--exec-timeout 30s
163167

164168
e2e-tests: chainsaw run ## Run end to end tests.
169+
echo $(VERSION)
170+
echo $(GO_LDFLAGS)
165171
## requires a cluster to be running with access
166172
## locally use kind to create clusters
167173
## in ci, the plan current is to have a real cluster, and create a node pool for testing
168-
$(CHAINSAW) test --test-dir e2e/chainsaw/skyhook $(CHAINSAW_ARGS)
174+
$(CHAINSAW) test --test-dir ../k8s-tests/chainsaw/skyhook/interrupt-grouping $(CHAINSAW_ARGS)
169175
$(MAKE) kill
170176
go tool covdata textfmt -i=$(REPORTING)/int -o reporting/int.coverprofile
171177

@@ -176,17 +182,24 @@ helm-tests: helm chainsaw
176182
$(MAKE) run
177183
$(MAKE) uninstall ignore-not-found=true
178184
$(MAKE) kill
185+
$(CHAINSAW) test --test-dir ../k8s-tests/chainsaw/helm $(CHAINSAW_ARGS)
179186

180-
$(CHAINSAW) test --test-dir e2e/chainsaw/helm $(CHAINSAW_ARGS)
187+
188+
ifeq ($(DOCKER_CMD),docker)
189+
DOCKER_AUTH_FILE=${HOME}/.docker/config.json
190+
else
191+
DOCKER_AUTH_FILE=${HOME}/.config/containers/auth.json
192+
endif
181193

182194
create-kind-cluster: ## deletes and creates a new kind cluster. versions is set via KIND_VERSION
195+
ifdef CI
196+
@echo $(GITHUB_TOKEN) | docker login ghcr.io -u $(GITHUB_ACTOR) --password-stdin
197+
endif
183198
kind delete cluster && kind create cluster --image=kindest/node:v$(KIND_VERSION) --config config/local-dev/kind-config.yaml
184199
$(KUBECTL) label node/kind-worker skyhook.nvidia.com/test-node=skyhooke2e
185-
186-
## sets you local podman creds into a secret in kind in the skyhook namespace
187-
$(KUBECTL) create namespace $(SKYHOOK_NAMESPACE) --dry-run=client -o yaml | kubectl apply -f -
200+
$(KUBECTL) create namespace skyhook
188201
$(KUBECTL) create secret generic node-init-secret --type=kubernetes.io/dockerconfigjson -n $(SKYHOOK_NAMESPACE) \
189-
--from-file=.dockerconfigjson=${HOME}/.config/containers/auth.json
202+
--from-file=.dockerconfigjson=$(DOCKER_AUTH_FILE)
190203

191204
podman-create-machine: ## creates a podman machine
192205
podman machine stop podman-machine-default || true
@@ -240,7 +253,7 @@ build: manifests generate fmt vet lint ## Build manager binary.
240253
.PHONY: run
241254
ENABLE_WEBHOOKS?=false
242255
BACKGROUND?=true
243-
AGENT_IMAGE?=nvcr.io/nvidian/swgpu-baseos/agentless-test:6.2.0
256+
AGENT_IMAGE?=ghcr.io/nvidia/skyhook/agentless:6.2.0
244257
LOG_LEVEL?=info
245258
run: manifests generate fmt vet lint reporting install kill ## Run a controller from your host.
246259
mkdir -p $(REPORTING)/int
@@ -263,7 +276,7 @@ kill:
263276
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
264277
.PHONY: docker-build
265278
docker-build: ## Build docker image with the manager.
266-
$(CONTAINER_TOOL) build -f containers/operator.Dockerfile -t ${IMG} .
279+
$(DOCKER_CMD) build -f containers/operator.Dockerfile -t ${IMG} .
267280

268281
##@ Deployment
269282

operator/api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apiVersion: kyverno.io/v1
2+
kind: ClusterPolicy
3+
metadata:
4+
name: add-imagepullsecrets
5+
annotations:
6+
policies.kyverno.io/title: Add imagePullSecrets
7+
policies.kyverno.io/category: Sample
8+
policies.kyverno.io/subject: Pod
9+
policies.kyverno.io/minversion: 1.6.0
10+
spec:
11+
rules:
12+
- name: add-imagepullsecret
13+
match:
14+
any:
15+
- resources:
16+
kinds:
17+
- Pod
18+
namespaceSelector:
19+
matchExpressions:
20+
- key: namespacekind
21+
operator: In
22+
values:
23+
- skyhook
24+
mutate:
25+
patchStrategicMerge:
26+
spec:
27+
containers:
28+
- <(image): "ghcr.io/*"
29+
imagePullSecrets:
30+
- name: node-init-secret

0 commit comments

Comments
 (0)