Skip to content

Commit 0441960

Browse files
authoredApr 9, 2024··
build: add ci script (#3)
* feat: add ci script * feat: add e2e instruction * chore: add markdown lint
1 parent 786b3ec commit 0441960

10 files changed

+372
-1
lines changed
 

‎.chainsaw.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: chainsaw.kyverno.io/v1alpha1
2+
kind: Configuration
3+
metadata:
4+
name: custom-config
5+
spec:
6+
timeouts:
7+
apply: 120s
8+
assert: 120s
9+
cleanup: 120s
10+
delete: 120s
11+
error: 120s
12+
exec: 45s
13+
skipDelete: false
14+
failFast: true

‎.editorconfig

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
max_line_length = 120
6+
7+
[*.proto]
8+
indent_size = 2
9+
tab_width = 2
10+
11+
[{*.bash,*.sh,*.zsh}]
12+
indent_size = 2
13+
tab_width = 2
14+
15+
[{*.go,*.go2}]
16+
indent_style = tab
17+
18+
[{*.har,*.jsb2,*.jsb3,*.json,.babelrc,.eslintrc,.prettierrc,.stylelintrc,bowerrc,jest.config}]
19+
indent_size = 2
20+
21+
[{*.hcl,*.nomad}]
22+
indent_size = 2
23+
24+
[{*.http,*.rest}]
25+
indent_size = 0
26+
27+
[{*.pb,*.textproto}]
28+
indent_size = 2
29+
tab_width = 2
30+
31+
[{*.tf,*.tfvars}]
32+
indent_size = 2
33+
34+
[{*.yaml,*.yml}]
35+
indent_size = 2

‎.github/dependabot.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "gomod"
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "weekly"
12+
13+
- package-ecosystem: "docker"
14+
directory: "/" # Location of package manifests
15+
schedule:
16+
interval: "weekly"

‎.github/workflows/ci.yml

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: CI
2+
3+
on: ['push', 'pull_request']
4+
5+
jobs:
6+
7+
golang-test:
8+
name: Golang Test
9+
runs-on: ubuntu-22.04
10+
strategy:
11+
matrix:
12+
go-version: ['1.21.x']
13+
steps:
14+
- uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 1
17+
- uses: actions/checkout@v4
18+
- name: Setup Go ${{ matrix.go-version }}
19+
uses: actions/setup-go@v4
20+
with:
21+
go-version: ${{ matrix.go-version }}
22+
- name: Display Go version
23+
run: go version
24+
- name: Install dependencies
25+
run: go get ./...
26+
- name: Test with Go
27+
run: make test
28+
29+
golang-lint:
30+
name: Golang Lint
31+
runs-on: ubuntu-22.04
32+
steps:
33+
- uses: actions/checkout@v3
34+
- uses: actions/setup-go@v4
35+
with:
36+
go-version: '1.21'
37+
cache: false
38+
- name: golangci-lint
39+
uses: golangci/golangci-lint-action@v3
40+
with:
41+
# Require: The version of golangci-lint to use.
42+
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
43+
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
44+
version: v1.54
45+
46+
# Optional: working directory, useful for monorepos
47+
# working-directory: somedir
48+
49+
# Optional: golangci-lint command line arguments.
50+
#
51+
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
52+
# The location of the configuration file can be changed by using `--config=`
53+
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0
54+
args: --timeout=30m
55+
56+
# Optional: show only new issues if it's a pull request. The default value is `false`.
57+
# only-new-issues: true
58+
59+
# Optional: if set to true, then all caching functionality will be completely disabled,
60+
# takes precedence over all other caching options.
61+
# skip-cache: true
62+
63+
# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
64+
# skip-pkg-cache: true
65+
66+
# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
67+
# skip-build-cache: true
68+
69+
# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
70+
# install-mode: "goinstall"
71+
72+
markdown-lint:
73+
name: Markdown Lint
74+
runs-on: ubuntu-22.04
75+
steps:
76+
- name: Checkout Code
77+
uses: actions/checkout@v3
78+
with:
79+
fetch-depth: 0
80+
- name: Lint Code Base
81+
uses: github/super-linter@v4
82+
env:
83+
VALIDATE_MARKDOWN: true
84+
VALIDATE_ALL_CODEBASE: false
85+
DEFAULT_BRANCH: main
86+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
87+
LINTER_RULES_PATH: /
88+
MARKDOWN_CONFIG_FILE: .markdownlint.yml
89+
90+
deploy-operator:
91+
name: Deploy operator
92+
if: github.event_name == 'push' && github.ref_type == 'tag' && github.repository_owner == 'zncdata-labs'
93+
runs-on: ubuntu-22.04
94+
needs:
95+
- golang-test
96+
- markdown-lint
97+
- golang-lint
98+
steps:
99+
- uses: actions/checkout@v3
100+
with:
101+
fetch-depth: 1
102+
- name: Set up QEMU
103+
uses: docker/setup-qemu-action@v3
104+
- name: Set up Docker Buildx
105+
uses: docker/setup-buildx-action@v3
106+
with:
107+
platforms: linux/amd64,linux/arm64
108+
- name: Login to quay.io
109+
uses: docker/login-action@v2
110+
with:
111+
registry: quay.io
112+
username: ${{ secrets.QUAY_USERNAME }}
113+
password: ${{ secrets.QUAY_PASSWORD }}
114+
115+
- name: Build and push operator
116+
run: |
117+
make docker-buildx
118+
119+
- name: Build and push operator bundle
120+
run: |
121+
make bundle
122+
make bundle-buildx
123+

‎.github/workflows/e2e.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# e2e test
2+
3+
name: e2e-test
4+
5+
on: ['push', 'pull_request']
6+
7+
jobs:
8+
chainsaw-test:
9+
name: Chainsaw Test
10+
runs-on: ubuntu-22.04
11+
strategy:
12+
matrix:
13+
k8s-version: ['1.26.14', '1.27.11']
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: actions/setup-go@v4
17+
with:
18+
go-version: '1.21'
19+
cache: false
20+
21+
- name: Create KinD cluster
22+
env:
23+
KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }}
24+
KIND_KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }}
25+
ENVTEST_K8S_VERSION: ${{ matrix.k8s-version}}
26+
run: make kind-create
27+
- name: Chainsaw test setup
28+
env:
29+
KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }}
30+
KIND_KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }}
31+
run: make chainsaw-setup
32+
- name: Test with Chainsaw
33+
env:
34+
KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }}
35+
KIND_KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }}
36+
run: make chainsaw-test

‎.markdownlint.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
MD007:
2+
indent: 4
3+
start_indented: false
4+
5+
MD013:
6+
line_length: 200
7+
heading_line_length: 80
8+
code_block_line_length: 200
9+
code_blocks: true
10+
tables: true
11+
headings: true
12+
headers: true
13+
strict: false
14+
stern: false
15+
16+
MD012:
17+
maximum: 20
18+
19+
MD046: false
20+
MD051: false

‎Makefile

+84-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ OPERATOR_SDK_VERSION ?= v1.33.0
5757
# Image URL to use all building/pushing image targets
5858
IMG ?= $(REGISTRY)/$(PROJECT_NAME):v$(VERSION)
5959
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
60-
ENVTEST_K8S_VERSION = 1.26.1
60+
ENVTEST_K8S_VERSION = 1.26.14
6161

6262
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
6363
ifeq (,$(shell go env GOBIN))
@@ -293,3 +293,86 @@ catalog-build: opm ## Build a catalog image.
293293
.PHONY: catalog-push
294294
catalog-push: ## Push a catalog image.
295295
$(MAKE) docker-push IMG=$(CATALOG_IMG)
296+
297+
##@ E2E
298+
299+
# kind
300+
KIND_VERSION ?= v0.22.0
301+
302+
KIND_KUBECONFIG ?= ./kind-kubeconfig
303+
KIND_CLUSTER_NAME ?= ${PROJECT_NAME}
304+
305+
.PHONY: kind
306+
KIND = $(LOCALBIN)/kind
307+
kind: ## Download kind locally if necessary.
308+
ifeq (,$(shell which $(KIND)))
309+
ifeq (,$(shell which kind 2>/dev/null))
310+
@{ \
311+
set -e ;\
312+
go install sigs.k8s.io/kind@$(KIND_VERSION) ;\
313+
}
314+
KIND = $(GOBIN)/bin/kind
315+
else
316+
KIND = $(shell which kind)
317+
endif
318+
endif
319+
320+
OLM_VERSION ?= v0.27.0
321+
322+
# Create a kind cluster, install ingress-nginx, and wait for it to be available.
323+
.PHONY: kind-create
324+
kind-create: kind ## Create a kind cluster.
325+
$(KIND) create cluster --config test/e2e/kind-$(ENVTEST_K8S_VERSION).yaml --name $(KIND_CLUSTER_NAME) --kubeconfig $(KIND_KUBECONFIG) --wait 120s
326+
make kind-setup KUBECONFIG=$(KIND_KUBECONFIG)
327+
328+
.PHONY: kind-setup
329+
kind-setup: kind ## setup kind cluster base environment
330+
@echo "\nSetup kind cluster base environment, install ingress-nginx and OLM"
331+
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
332+
kubectl -n ingress-nginx wait deployment ingress-nginx-controller --for=condition=available --timeout=300s
333+
curl -sSL https://github.com/operator-framework/operator-lifecycle-manager/releases/download/$(OLM_VERSION)/install.sh | bash -s $(OLM_VERSION)
334+
335+
.PHONY: kind-delete
336+
kind-delete: kind ## Delete a kind cluster.
337+
$(KIND) delete cluster --name $(KIND_CLUSTER_NAME)
338+
339+
# chainsaw
340+
341+
CHAINSAW_VERSION ?= v0.1.8
342+
343+
.PHONY: chainsaw
344+
CHAINSAW = $(LOCALBIN)/chainsaw
345+
chainsaw: ## Download chainsaw locally if necessary.
346+
ifeq (,$(shell which $(CHAINSAW)))
347+
ifeq (,$(shell which chainsaw 2>/dev/null))
348+
@{ \
349+
set -e ;\
350+
go install github.com/kyverno/chainsaw@$(CHAINSAW_VERSION) ;\
351+
}
352+
CHAINSAW = $(GOBIN)/chainsaw
353+
else
354+
CHAINSAW = $(shell which chainsaw)
355+
endif
356+
endif
357+
358+
# chainsaw setup logical
359+
# - Build the operator docker image
360+
# - Load the operator docker image into the kind cluster. When create
361+
# operator deployment, it will use the image in the kind cluster.
362+
# - Rebuild the bundle. If override VERSION / REGISTRY or other variables,
363+
# we need to rebuild the bundle to use the new image, or other changes.
364+
.PHONY: chainsaw-setup
365+
chainsaw-setup: manifests kustomize ## Run the chainsaw setup
366+
@echo "\nSetup chainsaw test environment"
367+
make docker-build
368+
$(KIND) --name $(KIND_CLUSTER_NAME) load docker-image $(IMG)
369+
make deploy KUBECONFIG=$(KIND_KUBECONFIG)
370+
371+
.PHONY: chainsaw-test
372+
chainsaw-test: chainsaw ## Run the chainsaw test
373+
$(CHAINSAW) test --cluster cluster-1=$(KIND_KUBECONFIG) --test-dir ./test/e2e
374+
375+
376+
.PHONY: chainsaw-cleanup
377+
chainsaw-cleanup: manifests kustomize ## Run the chainsaw cleanup
378+
make undeploy KUBECONFIG=$(KIND_KUBECONFIG)

‎chainsaw.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: chainsaw.kyverno.io/v1alpha1
2+
kind: Configuration
3+
metadata:
4+
name: e2e
5+
spec:
6+
skipDelete: false
7+
failFast: true
8+
parallel: 4

‎test/e2e/kind-1.26.14.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
nodes:
4+
- role: control-plane
5+
image: kindest/node:v1.26.14@sha256:5d548739ddef37b9318c70cb977f57bf3e5015e4552be4e27e57280a8cbb8e4f
6+
kubeadmConfigPatches:
7+
- |
8+
kind: InitConfiguration
9+
nodeRegistration:
10+
kubeletExtraArgs:
11+
node-labels: "ingress-ready=true"
12+
extraPortMappings:
13+
- containerPort: 80
14+
hostPort: 18080
15+
protocol: TCP
16+
- containerPort: 443
17+
hostPort: 18443
18+
protocol: TCP

‎test/e2e/kind-1.27.11.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
nodes:
4+
- role: control-plane
5+
image: kindest/node:v1.27.11@sha256:681253009e68069b8e01aad36a1e0fa8cf18bb0ab3e5c4069b2e65cafdd70843
6+
kubeadmConfigPatches:
7+
- |
8+
kind: InitConfiguration
9+
nodeRegistration:
10+
kubeletExtraArgs:
11+
node-labels: "ingress-ready=true"
12+
extraPortMappings:
13+
- containerPort: 80
14+
hostPort: 18080
15+
protocol: TCP
16+
- containerPort: 443
17+
hostPort: 18443
18+
protocol: TCP

0 commit comments

Comments
 (0)
Please sign in to comment.