Skip to content

Commit

Permalink
feat: add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
lwpk110 committed Jun 24, 2024
1 parent e77e7fd commit 08a1d2f
Show file tree
Hide file tree
Showing 26 changed files with 11,143 additions and 70 deletions.
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: 3600s
cleanup: 120s
delete: 120s
error: 300s
exec: 200s
skipDelete: true
failFast: true
51 changes: 51 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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
- uses: docker-practice/actions-setup-docker@master
timeout-minutes: 12
- run: |
set -x
docker version
docker run --rm hello-world
docker pull quay.io/zncdatadev/hadoop:3.3.4
name: Test docker
- 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: ssh
uses: ryanchapman/gha-ssh@v1
timeout-minutes: 10
with:
authorized_github_users: 'lwpk110'
debug: true
# - 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
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

0 comments on commit 08a1d2f

Please sign in to comment.