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

feat: add E2E tests and adjust cluster resource usage for gitHub actions #48

Merged
merged 2 commits into from
Jun 26, 2024
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
15 changes: 15 additions & 0 deletions .chainsaw.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Configuration
metadata:
name: custom-config
spec:
namespace: kubedatastack
timeouts:
apply: 420s
assert: 420s
cleanup: 120s
delete: 120s
error: 300s
exec: 200s
skipDelete: false
failFast: true
40 changes: 40 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# e2e test

name: e2e-test

on: ['push', 'pull_request']

jobs:
chainsaw-test:
name: Chainsaw Test
runs-on: ubuntu-22.04
strategy:
matrix:
k8s-version: ['1.26.14', '1.27.11']
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.22'
cache: false
- name: Create KinD clustet pur
env:
KINDTEST_K8S_VERSION: ${{ matrix.k8s-version}}
KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }}
KIND_KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }}
run: make kind-create
- name: Chainsaw test setup
env:
KINDTEST_K8S_VERSION: ${{ matrix.k8s-version }}
KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }}
KIND_KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }}
run: make chainsaw-setup
# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
# timeout-minutes: 20
- name: Test with Chainsaw
env:
KINDTEST_K8S_VERSION: ${{ matrix.k8s-version }}
KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }}
KIND_KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }}
run: make chainsaw-test
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ Dockerfile.cross
*~

bundle.Dockerfile
bundle

**/__debug_*

bundle*

kind-kubeconfig*

catalog.Dockerfile
catalog

*-local.yaml
89 changes: 88 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,91 @@ catalog-docker-buildx: ## Build and push a catalog image for cross-platform supp
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
$(CONTAINER_TOOL) buildx use project-v3-builder
$(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) -f catalog.Dockerfile --tag ${CATALOG_IMG} .
$(CONTAINER_TOOL) buildx rm project-v3-builder
$(CONTAINER_TOOL) buildx rm project-v3-builder

##@ E2E

# kind
KIND_VERSION ?= v0.23.0

KINDTEST_K8S_VERSION ?= 1.26.14

KIND_IMAGE ?= kindest/node:v${KINDTEST_K8S_VERSION}

KIND_KUBECONFIG ?= ./kind-kubeconfig-$(KINDTEST_K8S_VERSION)
KIND_CLUSTER_NAME ?= ${PROJECT_NAME}-$(KINDTEST_K8S_VERSION)

.PHONY: kind
KIND = $(LOCALBIN)/kind
kind: ## Download kind locally if necessary.
ifeq (,$(shell which $(KIND)))
ifeq (,$(shell which kind 2>/dev/null))
@{ \
set -e ;\
go install sigs.k8s.io/kind@$(KIND_VERSION) ;\
}
KIND = $(GOBIN)/bin/kind
else
KIND = $(shell which kind)
endif
endif

OLM_VERSION ?= v0.28.0
KIND_CONFIG ?= test/e2e/kind-config.yaml

# Create a kind cluster, install ingress-nginx, and wait for it to be available.
.PHONY: kind-create
kind-create: kind ## Create a kind cluster.
$(KIND) create cluster --config $(KIND_CONFIG) --image $(KIND_IMAGE) --name $(KIND_CLUSTER_NAME) --kubeconfig $(KIND_KUBECONFIG) --wait 120s
KUBECONFIG=$(KIND_KUBECONFIG) make kind-setup

.PHONY: kind-setup
kind-setup: kind ## setup kind cluster base environment
@echo "\nSetup kind cluster base environment, install ingress-nginx and OLM"
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
kubectl -n ingress-nginx wait deployment ingress-nginx-controller --for=condition=available --timeout=300s
curl -sSL https://github.com/operator-framework/operator-lifecycle-manager/releases/download/$(OLM_VERSION)/install.sh | bash -s $(OLM_VERSION)

.PHONY: kind-delete
kind-delete: kind ## Delete a kind cluster.
$(KIND) delete cluster --name $(KIND_CLUSTER_NAME)

# chainsaw

CHAINSAW_VERSION ?= v0.1.8

.PHONY: chainsaw
CHAINSAW = $(LOCALBIN)/chainsaw
chainsaw: ## Download chainsaw locally if necessary.
ifeq (,$(shell which $(CHAINSAW)))
ifeq (,$(shell which chainsaw 2>/dev/null))
@{ \
set -e ;\
go install github.com/kyverno/chainsaw@$(CHAINSAW_VERSION) ;\
}
CHAINSAW = $(GOBIN)/chainsaw
else
CHAINSAW = $(shell which chainsaw)
endif
endif

# chainsaw setup logical
# - Build the operator docker image
# - Load the operator docker image into the kind cluster. When create
# operator deployment, it will use the image in the kind cluster.
# - Rebuild the bundle. If override VERSION / REGISTRY or other variables,
# we need to rebuild the bundle to use the new image, or other changes.
.PHONY: chainsaw-setup
chainsaw-setup: manifests kustomize ## Run the chainsaw setup
@echo "\nSetup chainsaw test environment"
make docker-build
$(KIND) --name $(KIND_CLUSTER_NAME) load docker-image $(IMG)
KUBECONFIG=$(KIND_KUBECONFIG) make deploy

.PHONY: chainsaw-test
chainsaw-test: chainsaw ## Run the chainsaw test
$(CHAINSAW) test --cluster cluster-1=$(KIND_KUBECONFIG) --test-dir ./test/e2e

.PHONY: chainsaw-cleanup
chainsaw-cleanup: manifests kustomize ## Run the chainsaw cleanup
KUBECONFIG=$(KIND_KUBECONFIG) make undeploy
4 changes: 2 additions & 2 deletions api/v1alpha1/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
)

const (
CpuMin = "1"
CpuMax = "1.5"
CpuMin = "100m"
CpuMax = "500m"
MemoryLimit = "1.5Gi"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app.kubernetes.io/component: kube-rbac-proxy
app.kubernetes.io/created-by: hdfs-operator
app.kubernetes.io/instance: controller-manager-metrics-service
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/name: service
app.kubernetes.io/part-of: hdfs-operator
control-plane: controller-manager
name: hdfs-operator-controller-manager-metrics-service
spec:
ports:
- name: https
port: 8443
protocol: TCP
targetPort: https
selector:
control-plane: controller-manager
status:
loadBalancer: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
labels:
app.kubernetes.io/component: kube-rbac-proxy
app.kubernetes.io/created-by: hdfs-operator
app.kubernetes.io/instance: metrics-reader
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/name: clusterrole
app.kubernetes.io/part-of: hdfs-operator
name: hdfs-operator-metrics-reader
rules:
- nonResourceURLs:
- /metrics
verbs:
- get
Loading
Loading