Skip to content
This repository was archived by the owner on May 10, 2025. It is now read-only.
Draft
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
36 changes: 36 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: "End-to-end tests"

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
e2e-tests:
name: End-to-end tests
runs-on: ubuntu-20.04
strategy:
matrix:
kube-version:
- "1.21"
- "1.22"
- "1.23"

steps:

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: Check out code into the Go module directory
uses: actions/checkout@v2.4.0

- name: "install kuttl"
run: ./hack/install-kuttl.sh

- name: "run tests"
env:
KUBE_VERSION: ${{ matrix.kube-version }}
run: make prepare-e2e e2e KUBE_VERSION=$KUBE_VERSION
75 changes: 75 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ SHELL = /usr/bin/env bash -o pipefail

all: build

## Kind Test
KUBE_VERSION ?= 1.21
KIND_CONFIG ?= kind-$(KUBE_VERSION).yaml

##@ General

# The help target prints out all targets with their descriptions organized
Expand Down Expand Up @@ -105,6 +109,77 @@ sample_deployment:
delete_sample_deployment:
kubectl delete -f config/samples/sample-deployment.yaml

# end-to-tests
# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
go get -d $(2)@$(3) ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef

.PHONY: kuttl
kuttl:
ifeq (, $(shell which kubectl-kuttl))
echo ${PATH}
ls -l /usr/local/bin
which kubectl-kuttl
@{ \
set -e ;\
echo "" ;\
echo "ERROR: kuttl not found." ;\
echo "Please check https://kuttl.dev/docs/cli.html for installation instructions and try again." ;\
echo "" ;\
exit 1 ;\
}
else
KUTTL=$(shell which kubectl-kuttl)
endif

.PHONY: kind
kind:
ifeq (, $(shell which kind))
@{ \
set -e ;\
echo "" ;\
echo "ERROR: kind not found." ;\
echo "Please check https://kind.sigs.k8s.io/docs/user/quick-start/#installation for installation instructions and try again." ;\
echo "" ;\
exit 1 ;\
}
else
KIND=$(shell which kind)
endif

.PHONY: set-image-controller
set-image-controller: manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}

.PHONY: container
container:
podman build -t ${IMG} .

.PHONY: start-kind
start-kind:
kind create cluster --config $(KIND_CONFIG)

.PHONY: e2e
e2e:
$(KUTTL) test

.PHONY: prepare-e2e
prepare-e2e: kuttl set-image-controller container start-kind
mkdir -p tests/_build/crds tests/_build/manifests
$(KUSTOMIZE) build config/default -o tests/_build/manifests/snoopy-operator.yaml
$(KUSTOMIZE) build config/crd -o tests/_build/crds/

##@ Build
build: generate fmt vet ## Build manager binary.
go build -o bin/manager main.go
Expand Down
5 changes: 5 additions & 0 deletions hack/install-kuttl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

sudo curl -Lo /usr/local/bin/kubectl-kuttl https://github.com/kudobuilder/kuttl/releases/download/v0.11.1/kubectl-kuttl_0.11.1_linux_x86_64
sudo chmod +x /usr/local/bin/kubectl-kuttl
export PATH=$PATH:/usr/local/bin
12 changes: 12 additions & 0 deletions kind-1.21.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
image: quay.io/fennec-project/kindnode-crio:1.21@sha256:3c43afca813cf724e02efe70bf0ee0ceee498b49ee746781f6951db5bafb6b39
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
criSocket: unix:///run/crio/crio.sock
kubeletExtraArgs:
cgroup-driver: cgroupfs
12 changes: 12 additions & 0 deletions kind-1.22.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
image: quay.io/fennec-project/kindnode-crio:1.22@sha256:46948065311fd050ae9fb5bf7af76674ad167d9f1a41fba0460bc1467424abc2
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
criSocket: unix:///run/crio/crio.sock
kubeletExtraArgs:
cgroup-driver: cgroupfs
12 changes: 12 additions & 0 deletions kind-1.23.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
image: quay.io/fennec-project/kindnode-crio:1.23@sha256:76548d7eff138dae6dd9c29bfc55a836fb2ed87a19f234f7d3e6c9f8bb0eb71c
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
criSocket: unix:///run/crio/crio.sock
kubeletExtraArgs:
cgroup-driver: cgroupfs
23 changes: 23 additions & 0 deletions kuttl-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: kuttl.dev/v1beta1
kind: TestSuite
crdDir: ./tests/_build/crds/
artifactsDir: ./tests/_build/artifacts/
kindContainers:
- local/snoopy-operator:e2e
commands:
- command: kubectl apply -f ./tests/_build/manifests/snoopy-operator.yaml
- command: kubectl get pods -n snoopy-operator
- command: sleep 5s
- command: kubectl get pods -n snoopy-operator
- command: sleep 10s
- command: kubectl get pods -n snoopy-operator
- command: sleep 10s
- command: kubectl get pods -n snoopy-operator
- command: sleep 10s
- command: kubectl get pods -n snoopy-operator
- command: sleep 10s
- command: kubectl wait --timeout=5m --for=condition=available deployment snoopy-operator -n snoopy-operator
- command: sleep 5s
testDirs:
- ./tests/e2e/
timeout: 300
13 changes: 13 additions & 0 deletions tests/e2e/snoopyjob-tcpdump/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: job.fennecproject.io/v1alpha1
kind: SnoopyJob
metadata:
name: snoopy-samplejob
spec:
args: -i eth0 -U -w -
command: tcpdump
labelSelector:
networkMonitor: "true"
targetNamespace: cnf-telco
timer: 30s
status:
cronJobList:
14 changes: 14 additions & 0 deletions tests/e2e/snoopyjob-tcpdump/00-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: job.fennecproject.io/v1alpha1
kind: SnoopyJob
metadata:
name: snoopy-samplejob
spec:
command: "tcpdump"
args: "-n -i eth0"
labelSelector: {
networkMonitor: "true",
}
targetNamespace: cnf-telco
timer: "30s"
dataServiceIP: "snoopy-data-svc.snoopy-operator.svc.cluster.local"
dataServicePort: "51001"