Skip to content

Commit

Permalink
Migrate to kubebuilder v4 (konpyutaika#366)
Browse files Browse the repository at this point in the history
* update go.mod

migrate to kubebuilder go/v4

* update generated code

* Update go.mod

Co-authored-by: Juldrixx <[email protected]>

---------

Co-authored-by: Juldrixx <[email protected]>
  • Loading branch information
mh013370 and juldrixx authored Feb 9, 2024
1 parent 7607c9e commit cb89242
Show file tree
Hide file tree
Showing 79 changed files with 1,468 additions and 858 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
!**/*.go
!**/*.mod
!**/*.sum
bin/
4 changes: 2 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ issues:
- goheader
# Exclude gci check for //+kubebuilder:scaffold:imports comments. Waiting to
# resolve https://github.com/daixiang0/gci/issues/135
- path: main.go
- path: cmd/main.go
linters:
- gci
- path: cmd/kubectl-nifikop/main.go
linters:
- gci
- path: controllers/suite_test.go
- path: internal/controller/suite_test.go
linters:
- gci
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [PR #378](https://github.com/konpyutaika/nifikop/pull/378) - **[Operator]** Tweak NiFi pod startup script to more gracefully handle pod IP resolution.
- [PR #382](https://github.com/konpyutaika/nifikop/pull/382) - **[Operator/NifiCluster]** Changed `nifi.content.viewer.url` property default value.
- [PR #387](https://github.com/konpyutaika/nifikop/pull/387) - **[Operator]** Upgrade golang to 1.21.7.
- [PR #366](https://github.com/konpyutaika/nifikop/pull/366) - **[Operator]** Migrated nifikop to KubeBuilder go/v4 and operator-sdk to v1.33.0.

### Fixed Bugs

Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ COPY go.sum go.sum
RUN go mod download

# Copy the go source
COPY main.go main.go
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY controllers/ controllers/
COPY internal/controller/ internal/controller/
COPY pkg/ pkg/
COPY version/ version/

Expand All @@ -22,7 +22,7 @@ COPY version/ version/
# see: https://sdk.operatorframework.io/docs/advanced-topics/multi-arch/#manifest-lists
# see: https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/
ARG TARGETOS TARGETARCH
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -a -o manager main.go
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -a -o manager cmd/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
72 changes: 47 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ WORKDIR := /go/nifikop
# Debug variables
TELEPRESENCE_REGISTRY ?= datawire

# CONTAINER_TOOL defines the container tool to be used for building images.
# Be aware that the target commands are only tested with Docker which is
# scaffolded by default. However, you might want to replace it to use other
# tools. (i.e. podman)
CONTAINER_TOOL ?= docker

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
Expand All @@ -27,9 +33,9 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint

## Tool Versions
KUSTOMIZE_VERSION ?= v4.5.5
CONTROLLER_TOOLS_VERSION ?= v0.9.2
ENVTEST_K8S_VERSION = 1.26
KUSTOMIZE_VERSION ?= v5.2.1
CONTROLLER_TOOLS_VERSION ?= v0.13.0
ENVTEST_K8S_VERSION = 1.28.0
GOLANGCI_VERSION = 1.55.2

# controls the exit code of linter in case of linting issues
Expand Down Expand Up @@ -123,7 +129,7 @@ SHELL = /usr/bin/env bash -o pipefail
# Build manager binary
.PHONY: manager
manager: manifests generate fmt
go build -o bin/manager main.go
go build -o bin/manager cmd/main.go

# Generate code
.PHONY: generate
Expand All @@ -140,15 +146,16 @@ manifests: controller-gen
# Build the docker image
.PHONY: docker-build
docker-build:
docker build -t $(REPOSITORY):$(VERSION) .
${CONTAINER_TOOL} build -t $(REPOSITORY):$(VERSION) .

.PHONY: build
build: manager manifests

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

.PHONY: lint
lint: golangci-lint
Expand Down Expand Up @@ -179,7 +186,7 @@ test-with-vendor: manifests generate fmt lint helm-chart-version-match govuln en
# Run against the configured Kubernetes cluster in ~/.kube/config
.PHONY: run
run: generate fmt manifests
go run ./main.go
go run ./cmd/main.go

ifndef ignore-not-found
ignore-not-found = false
Expand Down Expand Up @@ -210,7 +217,11 @@ KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/k
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
$(KUSTOMIZE): $(LOCALBIN)
test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
rm -rf $(LOCALBIN)/kustomize; \
fi
test -s $(LOCALBIN)/kustomize || GOBIN=$(LOCALBIN) GO111MODULE=on go install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION)

.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
Expand All @@ -229,7 +240,7 @@ bundle: manifests kustomize
# Build the bundle image.
.PHONY: bundle-build
bundle-build:
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
${CONTAINER_TOOL} build -f bundle.Dockerfile -t $(BUNDLE_IMG) .

.PHONY: helm-dep-update $(HELM_CHARTS_DIRS)
helm-dep-update: $(HELM_CHARTS_DIRS)
Expand All @@ -240,8 +251,7 @@ $(HELM_CHARTS_DIRS):
.PHONY: helm-gen-docs
helm-gen-docs:
# only generate docs for nifi-cluster to avoid stomping on the existing nifikop chart docs
docker run --rm --volume "$(shell pwd)/helm/nifi-cluster/:/helm-docs" -u $(shell id -u) jnorwood/helm-docs:latest

${CONTAINER_TOOL} run --rm --volume "$(shell pwd)/helm/nifi-cluster/:/helm-docs" -u $(shell id -u) jnorwood/helm-docs:latest

.PHONY: helm-chart-version-match
helm-chart-version-match:
Expand Down Expand Up @@ -280,10 +290,10 @@ endif
# Push the docker image
.PHONY: docker-push
docker-push:
docker push $(REPOSITORY):$(VERSION)
${CONTAINER_TOOL} push $(REPOSITORY):$(VERSION)
ifdef PUSHLATEST
docker tag $(REPOSITORY):$(VERSION) $(REPOSITORY):latest
docker push $(REPOSITORY):latest
${CONTAINER_TOOL} tag $(REPOSITORY):$(VERSION) $(REPOSITORY):latest
${CONTAINER_TOOL} push $(REPOSITORY):latest
endif
# ----

Expand All @@ -298,20 +308,32 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
- docker buildx create --name project-v3-builder
docker buildx use project-v3-builder
- ${CONTAINER_TOOL} buildx create --name project-v3-builder
${CONTAINER_TOOL} buildx use project-v3-builder
ifdef PUSHLATEST
- docker buildx build --push --platform=$(PLATFORMS) --tag $(REPOSITORY):$(VERSION) --tag $(REPOSITORY):latest -f Dockerfile.cross .
- ${CONTAINER_TOOL} buildx build --push --platform=$(PLATFORMS) --tag $(REPOSITORY):$(VERSION) --tag $(REPOSITORY):latest -f Dockerfile.cross .
else
- docker buildx build --push --platform=$(PLATFORMS) --tag $(REPOSITORY):$(VERSION) -f Dockerfile.cross .
- ${CONTAINER_TOOL} buildx build --push --platform=$(PLATFORMS) --tag $(REPOSITORY):$(VERSION) -f Dockerfile.cross .
endif
- docker buildx rm project-v3-builder
- ${CONTAINER_TOOL} buildx rm project-v3-builder
rm Dockerfile.cross

.DEFAULT_GOAL := help

# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk command is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

.PHONY: help
help:
@grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

.PHONY: get-version
get-version:
Expand Down Expand Up @@ -363,7 +385,7 @@ debug-telepresence-with-alias:
# Build the docker development environment
.PHONY: build-ci-image
build-ci-image:
docker build --cache-from $(BUILD_IMAGE):latest \
${CONTAINER_TOOL} build --cache-from $(BUILD_IMAGE):latest \
--build-arg GOLANG_VERSION=$(GOLANG_VERSION) \
--build-arg GOLANGCI_VERSION=$(GOLANGCI_VERSION) \
-t $(BUILD_IMAGE):latest \
Expand All @@ -373,9 +395,9 @@ build-ci-image:

.PHONY: push-ci-image
push-ci-image:
docker push $(BUILD_IMAGE):$(GOLANG_VERSION)
${CONTAINER_TOOL} push $(BUILD_IMAGE):$(GOLANG_VERSION)
ifdef PUSHLATEST
docker push $(BUILD_IMAGE):latest
${CONTAINER_TOOL} push $(BUILD_IMAGE):latest
endif

## Test if the dependencies we need to run this Makefile are installed
Expand Down
97 changes: 48 additions & 49 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,112 +1,111 @@
# Code generated by tool. DO NOT EDIT.
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: konpyutaika.com
layout:
- go.kubebuilder.io/v3
plugins:
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
- go.kubebuilder.io/v4
projectName: nifikop
repo: github.com/konpyutaika/nifikop
resources:
- api:
crdVersion: v1
namespaced: true
domain: konpyutaika.com
group: nifi
kind: NifiCluster
path: github.com/konpyutaika/nifikop/api/v1alpha1
version: v1alpha1
webhooks:
conversion: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
domain: konpyutaika.com
group: nifi
kind: NifiCluster
path: github.com/konpyutaika/nifikop/api/v1
version: v1
kind: NifiConnection
path: github.com/konpyutaika/nifikop/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: konpyutaika.com
group: nifi
kind: NifiUserGroup
kind: NifiDataflow
path: github.com/konpyutaika/nifikop/api/v1alpha1
version: v1alpha1
webhooks:
conversion: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
domain: konpyutaika.com
group: nifi
kind: NifiUserGroup
path: github.com/konpyutaika/nifikop/api/v1
version: v1
kind: NifiNodeGroupAutoscaler
path: github.com/konpyutaika/nifikop/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: konpyutaika.com
group: nifi
kind: NifiUser
kind: NifiParameterContext
path: github.com/konpyutaika/nifikop/api/v1alpha1
version: v1alpha1
webhooks:
conversion: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
domain: konpyutaika.com
group: nifi
kind: NifiUser
path: github.com/konpyutaika/nifikop/api/v1
version: v1
kind: NifiRegistryClient
path: github.com/konpyutaika/nifikop/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: konpyutaika.com
group: nifi
kind: NifiRegistryClient
kind: NifiUser
path: github.com/konpyutaika/nifikop/api/v1alpha1
version: v1alpha1
webhooks:
conversion: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
domain: konpyutaika.com
group: nifi
kind: NifiRegistryClient
path: github.com/konpyutaika/nifikop/api/v1
version: v1
kind: NifiUserGroup
path: github.com/konpyutaika/nifikop/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: konpyutaika.com
group: nifi
kind: NifiDataflow
path: github.com/konpyutaika/nifikop/api/v1alpha1
version: v1alpha1
webhooks:
conversion: true
webhookVersion: v1
kind: NifiCluster
path: github.com/konpyutaika/nifikop/api/v1
version: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: konpyutaika.com
group: nifi
kind: NifiDataflow
path: github.com/konpyutaika/nifikop/api/v1
version: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: konpyutaika.com
group: nifi
kind: NifiParameterContext
path: github.com/konpyutaika/nifikop/api/v1alpha1
version: v1alpha1
webhooks:
conversion: true
webhookVersion: v1
path: github.com/konpyutaika/nifikop/api/v1
version: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: konpyutaika.com
group: nifi
kind: NifiParameterContext
kind: NifiRegistryClient
path: github.com/konpyutaika/nifikop/api/v1
version: v1
- api:
Expand All @@ -115,16 +114,16 @@ resources:
controller: true
domain: konpyutaika.com
group: nifi
kind: NifiNodeGroupAutoscaler
path: github.com/konpyutaika/nifikop/api/v1alpha1
version: v1alpha1
kind: NifiUser
path: github.com/konpyutaika/nifikop/api/v1
version: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: konpyutaika.com
group: nifi
kind: NifiConnection
path: github.com/konpyutaika/nifikop/api/v1alpha1
version: v1alpha1
kind: NifiUserGroup
path: github.com/konpyutaika/nifikop/api/v1
version: v1
version: "3"
Loading

0 comments on commit cb89242

Please sign in to comment.