Skip to content

Commit bfe1101

Browse files
author
Elon Cheng
authored
Upgrade layout from Kubebuilder v2 to Kubebuilder v3.1 (fluent#147)
* Upgrade layout from Kubebuilder v2 to Kubebuilder v3.1 Signed-off-by: chengdehao <[email protected]> * update and Resolve the conflict Signed-off-by: chengdehao <[email protected]>
1 parent 9cba513 commit bfe1101

File tree

103 files changed

+611
-1255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+611
-1255
lines changed

.dockerignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore all files which are not go type
3+
!**/*.go
4+
!**/*.mod
5+
!**/*.sum

.github/workflows/main.yaml

+8-8
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ jobs:
2525
with:
2626
go-version: 1.16.x
2727

28-
- name: Checkout code
29-
uses: actions/checkout@v2
30-
with:
31-
fetch-depth: 0
32-
3328
- uses: actions/cache@v2
3429
with:
3530
path: ~/go/pkg/mod
3631
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
3732

38-
- name: Install kubebuilder-2.3.2
33+
- name: Checkout code
34+
uses: actions/checkout@v2
35+
with:
36+
fetch-depth: 0
37+
38+
- name: Install kubebuilder-3.1.0
3939
run: |
40-
curl -L "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v2.3.2/kubebuilder_2.3.2_linux_amd64.tar.gz" | tar -xz -C /tmp/
41-
sudo mv /tmp/kubebuilder_2.3.2_linux_amd64 /usr/local/kubebuilder
40+
curl -L -o kubebuilder "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v3.1.0/kubebuilder_linux_amd64"
41+
chmod +x kubebuilder && mv kubebuilder /usr/local/bin/
4242
4343
- name: Run basic test
4444
run: make test

Makefile

+88-61
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FB_IMG ?= kubesphere/fluent-bit:v1.8.3
44
OP_IMG ?= kubesphere/fluentbit-operator:$(VERSION)
55
AMD64 ?= -amd64
66
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
7-
CRD_OPTIONS ?= "crd:trivialVersions=true"
7+
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
88

99
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
1010
ifeq (,$(shell go env GOBIN))
@@ -13,70 +13,76 @@ else
1313
GOBIN=$(shell go env GOBIN)
1414
endif
1515

16-
all: manager
16+
# Setting SHELL to bash allows bash commands to be executed by recipes.
17+
# This is a requirement for 'setup-envtest.sh' in the test target.
18+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
19+
SHELL = /usr/bin/env bash -o pipefail
20+
.SHELLFLAGS = -ec
1721

18-
# Run tests
19-
test: generate fmt vet manifests
20-
go test ./... -coverprofile cover.out
22+
all: build
2123

22-
# Build manager binary
23-
manager: generate fmt vet
24-
go build -o bin/manager cmd/manager/main.go
25-
26-
binary:
27-
go build -o bin/manager cmd/manager/main.go
28-
go build -o bin/watcher cmd/fluent-bit-watcher/main.go
29-
30-
verify: verify-crds
31-
32-
verify-crds:
33-
sudo chmod a+x ./hack/verify-crds.sh && ./hack/verify-crds.sh
24+
##@ General
3425

35-
# Run against the configured Kubernetes cluster in ~/.kube/config
36-
run: generate fmt vet manifests
37-
go run cmd/manager/main.go
38-
39-
# Install CRDs into a cluster
40-
install: manifests
41-
kustomize build config/crd | kubectl apply -f -
26+
# The help target prints out all targets with their descriptions organized
27+
# beneath their categories. The categories are represented by '##@' and the
28+
# target descriptions by '##'. The awk commands is responsible for reading the
29+
# entire set of makefiles included in this invocation, looking for lines of the
30+
# file as xyz: ## something, and then pretty-format the target and help. Then,
31+
# if there's a line with ##@ something, that gets pretty-printed as a category.
32+
# More info on the usage of ANSI control characters for terminal formatting:
33+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
34+
# More info on the awk command:
35+
# http://linuxcommand.org/lc3_adv_awk.php
4236

43-
# Uninstall CRDs from a cluster
44-
uninstall: manifests
45-
kustomize build config/crd | kubectl delete -f -
37+
help: ## Display this help.
38+
@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)
4639

47-
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
48-
deploy: manifests
49-
cd config/manager && kustomize edit set image controller=${IMG}
50-
kustomize build config/default | kubectl apply -f -
40+
##@ Development
5141

52-
# Generate manifests e.g. CRD, RBAC etc.
53-
manifests: controller-gen
42+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
5443
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
5544
kubectl kustomize config/crd | sed -e '/creationTimestamp/d' > manifests/setup/fluentbit-operator-crd.yaml
5645
kubectl kustomize manifests/setup | sed -e '/creationTimestamp/d' > manifests/setup/setup.yaml
5746

58-
# Run go fmt against code
59-
fmt:
47+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
48+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
49+
./hack/update-codegen.sh
50+
51+
fmt: ## Run go fmt against code.
6052
go fmt ./...
6153

62-
# Run go vet against code
63-
vet:
54+
vet: ## Run go vet against code.
6455
go vet ./...
6556

66-
# Generate code
67-
generate: controller-gen
68-
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths="./..."
69-
./hack/update-codegen.sh
57+
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
58+
test: manifests generate fmt vet ## Run tests.
59+
mkdir -p ${ENVTEST_ASSETS_DIR}
60+
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh
61+
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
62+
63+
##@ Build
64+
65+
binary:
66+
go build -o bin/manager cmd/manager/main.go
67+
go build -o bin/watcher cmd/fluent-bit-watcher/main.go
7068

71-
# Build all amd64/arm64 docker images
72-
build: test build-op
69+
verify: verify-crds
70+
71+
verify-crds:
72+
sudo chmod a+x ./hack/verify-crds.sh && ./hack/verify-crds.sh
73+
74+
build: generate fmt vet ## Build manager binary.
75+
go build -o bin/manager cmd/manager/main.go
76+
77+
run: manifests generate fmt vet ## Run a controller from your host.
78+
go run cmd/manager/main.go
7379

7480
# Build amd64/arm64 Fluent Bit container image
7581
build-fb:
7682
docker buildx build --push --platform linux/amd64,linux/arm64 -f cmd/fluent-bit-watcher/Dockerfile . -t ${FB_IMG}
7783

7884
# Build amd64/arm64 Fluent Bit Operator container image
79-
build-op:
85+
build-op:
8086
docker buildx build --push --platform linux/amd64,linux/arm64 -f cmd/manager/Dockerfile . -t ${OP_IMG}
8187

8288
# Build all amd64 docker images
@@ -87,26 +93,47 @@ build-fb-amd64:
8793
docker build -f cmd/fluent-bit-watcher/Dockerfile . -t ${FB_IMG}${AMD64}
8894

8995
# Build amd64 Fluent Bit Operator container image
90-
build-op-amd64:
96+
build-op-amd64:
9197
docker build -f cmd/manager/Dockerfile . -t ${OP_IMG}${AMD64}
9298

9399
# Push the amd64 docker image
94100
push-amd64:
95101
docker push ${OP_IMG}${AMD64}
96102

97-
# find or download controller-gen
98-
# download controller-gen if necessary
99-
controller-gen:
100-
ifeq (, $(shell which controller-gen))
101-
@{ \
102-
set -e ;\
103-
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
104-
cd $$CONTROLLER_GEN_TMP_DIR ;\
105-
go mod init tmp ;\
106-
go install -v sigs.k8s.io/controller-tools/cmd/[email protected] ;\
107-
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
108-
}
109-
CONTROLLER_GEN=$(GOBIN)/controller-gen
110-
else
111-
CONTROLLER_GEN=$(shell which controller-gen)
112-
endif
103+
##@ Deployment
104+
105+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
106+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
107+
108+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
109+
$(KUSTOMIZE) build config/crd | kubectl delete -f -
110+
111+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
112+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
113+
$(KUSTOMIZE) build config/default | kubectl apply -f -
114+
115+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
116+
$(KUSTOMIZE) build config/default | kubectl delete -f -
117+
118+
119+
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
120+
controller-gen: ## Download controller-gen locally if necessary.
121+
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
122+
123+
KUSTOMIZE = $(shell pwd)/bin/kustomize
124+
kustomize: ## Download kustomize locally if necessary.
125+
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
126+
127+
# go-get-tool will 'go get' any package $2 and install it to $1.
128+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
129+
define go-get-tool
130+
@[ -f $(1) ] || { \
131+
set -e ;\
132+
TMP_DIR=$$(mktemp -d) ;\
133+
cd $$TMP_DIR ;\
134+
go mod init tmp ;\
135+
echo "Downloading $(2)" ;\
136+
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
137+
rm -rf $$TMP_DIR ;\
138+
}
139+
endef

PROJECT

+41-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,56 @@
11
domain: kubesphere.io
2+
layout:
3+
- go.kubebuilder.io/v3
4+
projectName: fluentbit-operator
25
repo: kubesphere.io/fluentbit-operator
36
resources:
4-
- group: logging
7+
- api:
8+
crdVersion: v1
9+
namespaced: true
10+
controller: true
11+
domain: kubesphere.io
12+
group: logging
513
kind: FluentBitConfig
14+
path: kubesphere.io/fluentbit-operator/api/v1alpha2
615
version: v1alpha2
7-
- group: logging
16+
- api:
17+
crdVersion: v1
18+
namespaced: true
19+
domain: kubesphere.io
20+
group: logging
821
kind: FluentBit
22+
path: kubesphere.io/fluentbit-operator/api/v1alpha2
923
version: v1alpha2
10-
- group: logging
24+
- api:
25+
crdVersion: v1
26+
namespaced: true
27+
domain: kubesphere.io
28+
group: logging
1129
kind: Input
30+
path: kubesphere.io/fluentbit-operator/api/v1alpha2
1231
version: v1alpha2
13-
- group: logging
32+
- api:
33+
crdVersion: v1
34+
namespaced: true
35+
domain: kubesphere.io
36+
group: logging
1437
kind: Filter
38+
path: kubesphere.io/fluentbit-operator/api/v1alpha2
1539
version: v1alpha2
16-
- group: logging
40+
- api:
41+
crdVersion: v1
42+
namespaced: true
43+
domain: kubesphere.io
44+
group: logging
1745
kind: Output
46+
path: kubesphere.io/fluentbit-operator/api/v1alpha2
1847
version: v1alpha2
19-
- group: logging
48+
- api:
49+
crdVersion: v1
50+
namespaced: true
51+
domain: kubesphere.io
52+
group: logging
2053
kind: Parser
54+
path: kubesphere.io/fluentbit-operator/api/v1alpha2
2155
version: v1alpha2
22-
version: "2"
56+
version: "3"

api/fluentbitoperator/v1alpha2/filter_types.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
Copyright 2021.
23
34
Licensed under the Apache License, Version 2.0 (the "License");
45
you may not use this file except in compliance with the License.

api/fluentbitoperator/v1alpha2/fluentbit_types.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
Copyright 2021.
23
34
Licensed under the Apache License, Version 2.0 (the "License");
45
you may not use this file except in compliance with the License.

api/fluentbitoperator/v1alpha2/fluentbitconfig_types.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
Copyright 2021.
23
34
Licensed under the Apache License, Version 2.0 (the "License");
45
you may not use this file except in compliance with the License.

api/fluentbitoperator/v1alpha2/groupversion_info.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
Copyright 2021.
23
34
Licensed under the Apache License, Version 2.0 (the "License");
45
you may not use this file except in compliance with the License.
@@ -14,8 +15,8 @@ limitations under the License.
1415
*/
1516

1617
// Package v1alpha2 contains API Schema definitions for the logging v1alpha2 API group
17-
// +kubebuilder:object:generate=true
18-
// +groupName=logging.kubesphere.io
18+
//+kubebuilder:object:generate=true
19+
//+groupName=logging.kubesphere.io
1920
package v1alpha2
2021

2122
import (

api/fluentbitoperator/v1alpha2/input_types.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
Copyright 2021.
23
34
Licensed under the Apache License, Version 2.0 (the "License");
45
you may not use this file except in compliance with the License.

api/fluentbitoperator/v1alpha2/output_types.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
Copyright 2021.
23
34
Licensed under the Apache License, Version 2.0 (the "License");
45
you may not use this file except in compliance with the License.

api/fluentbitoperator/v1alpha2/parser_types.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
Copyright 2021.
23
34
Licensed under the Apache License, Version 2.0 (the "License");
45
you may not use this file except in compliance with the License.

api/fluentbitoperator/v1alpha2/plugins/filter/zz_generated.deepcopy.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/fluentbitoperator/v1alpha2/plugins/input/zz_generated.deepcopy.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/fluentbitoperator/v1alpha2/plugins/output/zz_generated.deepcopy.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/fluentbitoperator/v1alpha2/plugins/parser/zz_generated.deepcopy.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/fluentbitoperator/v1alpha2/plugins/zz_generated.deepcopy.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/fluentbitoperator/v1alpha2/zz_generated.deepcopy.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)