Skip to content

Commit

Permalink
refactor: refactor with operator-go 0.10.0 (#131)
Browse files Browse the repository at this point in the history
* refactor: refactor with operator-go 0.10.0

* fix: fix config mount err

* fix: fix vector error and test pass
  • Loading branch information
whg517 authored Sep 27, 2024
1 parent e713f7a commit 4c33759
Show file tree
Hide file tree
Showing 47 changed files with 2,528 additions and 21,098 deletions.
3 changes: 2 additions & 1 deletion .chainsaw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ kind: Configuration
metadata:
name: custom-config
spec:
# namespace: chainsaw
timeouts:
apply: 120s
assert: 120s
cleanup: 240s
delete: 240s
error: 10s
exec: 45s
skipDelete: false
# skipDelete: true
failFast: true
69 changes: 19 additions & 50 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,56 +22,12 @@ jobs:
MARKDOWN_CONFIG_FILE: .markdownlint.yml


golang-lint:
name: Golang Lint
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.22'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: latest

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
#
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=`
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0
args: --timeout=30m

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true, then all caching functionality will be completely disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
# skip-build-cache: true

# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
# install-mode: "goinstall"


golang-test:
name: Golang Test
runs-on: ubuntu-22.04
strategy:
matrix:
go-version: ['1.22']
go-version: ['1.23']
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -89,6 +45,19 @@ jobs:
run: make test


golang-lint:
name: golang-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.23'
cache: false
- name: golangci-lint
run: |
make lint
chainsaw-test:
name: Chainsaw Test
Expand All @@ -100,9 +69,9 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.22'
go-version: '1.23'
cache: false
- name: Create KinD cluster
- name: Create KinD clustet
env:
KINDTEST_K8S_VERSION: ${{ matrix.k8s-version}}
KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }}
Expand All @@ -127,9 +96,9 @@ jobs:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository_owner == 'zncdatadev' }}
runs-on: ubuntu-22.04
needs:
- golang-lint
- golang-test
- chainsaw-test
- golang-lint
- golang-test
- chainsaw-test
steps:
- uses: actions/checkout@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.22 as builder
FROM golang:1.23 as builder
ARG TARGETOS
ARG TARGETARCH

Expand Down
57 changes: 35 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ endif

# Set the Operator SDK version to use. By default, what is installed on the system is used.
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
OPERATOR_SDK_VERSION ?= v1.35.0
OPERATOR_SDK_VERSION ?= v1.37.0

# Image URL to use all building/pushing image targets
IMG ?= $(REGISTRY)/$(PROJECT_NAME):$(VERSION)
Expand Down Expand Up @@ -117,8 +117,20 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
GOLANGCI_LINT_VERSION ?= v1.60.3
golangci-lint:
@[ -f $(GOLANGCI_LINT) ] || { \
set -e ;\
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) $(GOLANGCI_LINT_VERSION) ;\
}

.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter & yamllint
$(GOLANGCI_LINT) run --timeout 5m

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
test: manifests generate fmt vet envtest lint ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out

##@ Build
Expand Down Expand Up @@ -200,7 +212,7 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest

## Tool Versions
KUSTOMIZE_VERSION ?= v5.4.2
CONTROLLER_TOOLS_VERSION ?= v0.15.0
CONTROLLER_TOOLS_VERSION ?= v0.16.2

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
Expand Down Expand Up @@ -372,29 +384,30 @@ kind-delete: kind ## Delete a kind cluster.

# chainsaw

CHAINSAW_VERSION ?= v0.1.8
CHAINSAW_VERSION ?= v0.2.10
CHAINSAW = $(LOCALBIN)/chainsaw

.PHONY: chainsaw
CHAINSAW = $(LOCALBIN)/chainsaw
chainsaw: ## Download chainsaw locally if necessary.
ifeq (,$(shell which $(CHAINSAW)))
ifeq (,$(shell which chainsaw 2>/dev/null))
chainsaw: $(CHAINSAW) ## Download chainsaw locally if necessary.
$(CHAINSAW): $(LOCALBIN)
@{ \
set -e ;\
go install github.com/kyverno/chainsaw@$(CHAINSAW_VERSION) ;\
set -xe ;\
if test -x $(LOCALBIN)/chainsaw && ! $(LOCALBIN)/chainsaw version | grep $(CHAINSAW_VERSION:v%=%) > /dev/null; then \
echo "$(LOCALBIN)/chainsaw version is not expected $(CHAINSAW_VERSION). Removing it before installing."; \
rm -rf $(LOCALBIN)/chainsaw; \
fi; \
if test ! -s $(LOCALBIN)/chainsaw; then \
mkdir -p $(dir $(CHAINSAW)) ;\
TMP=$(shell mktemp -d) ;\
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSL https://github.com/kyverno/chainsaw/releases/download/$(CHAINSAW_VERSION)/chainsaw_$${OS}_$${ARCH}.tar.gz | tar -xz -C $$TMP ;\
mv $$TMP/chainsaw $(CHAINSAW) ;\
rm -rf $$TMP ;\
chmod +x $(CHAINSAW) ;\
touch $(CHAINSAW) ;\
fi; \
}
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"
Expand All @@ -404,7 +417,7 @@ chainsaw-setup: manifests kustomize ## Run the chainsaw setup

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


.PHONY: chainsaw-cleanup
Expand Down
16 changes: 0 additions & 16 deletions api/v1alpha1/conditions.go

This file was deleted.

Loading

0 comments on commit 4c33759

Please sign in to comment.