Skip to content

Commit 7e45f5d

Browse files
committed
feat: init by operator-sdk
Signed-off-by: Abirdcfly <[email protected]>
1 parent 0e624d4 commit 7e45f5d

File tree

71 files changed

+4115
-0
lines changed

Some content is hidden

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

71 files changed

+4115
-0
lines changed

.dockerignore

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore build and test binaries.
3+
bin/
4+
testbin/
5+
.vscode/*
6+
!.vscode/settings.json
7+
!.vscode/tasks.json
8+
!.vscode/launch.json
9+
!.vscode/extensions.json
10+
*.code-workspace
11+
.history/
12+
xcuserdata/
13+
*.xcscmblueprint
14+
*.xccheckout
15+
DerivedData/
16+
*.moved-aside
17+
*.pbxuser
18+
!default.pbxuser
19+
*.mode1v3
20+
!default.mode1v3
21+
*.mode2v3
22+
!default.mode2v3
23+
*.perspectivev3
24+
!default.perspectivev3
25+
/*.gcno
26+
.idea
27+
.idea/**/workspace.xml
28+
.idea/**/tasks.xml
29+
.idea/**/usage.statistics.xml
30+
.idea/**/dictionaries
31+
.idea/**/shelf
32+
.idea/**/contentModel.xml
33+
.idea/**/dataSources/
34+
.idea/**/dataSources.ids
35+
.idea/**/dataSources.local.xml
36+
.idea/**/sqlDataSources.xml
37+
.idea/**/dynamic.xml
38+
.idea/**/uiDesigner.xml
39+
.idea/**/dbnavigator.xml
40+
.idea/**/gradle.xml
41+
.idea/**/libraries
42+
cmake-build-*/
43+
.idea/**/mongoSettings.xml
44+
*.iws
45+
out/
46+
.idea_modules/
47+
atlassian-ide-plugin.xml
48+
.idea/replstate.xml
49+
com_crashlytics_export_strings.xml
50+
crashlytics.properties
51+
crashlytics-build.properties
52+
fabric.properties
53+
.idea/httpRequests
54+
.idea/caches/build_file_checksums.ser
55+
.Python
56+
[Bb]in
57+
[Ii]nclude
58+
[Ll]ib64
59+
pyvenv.cfg
60+
.venv
61+
pip-selfcheck.json
62+
*~
63+
.fuse_hidden*
64+
.directory
65+
.Trash-*
66+
.nfs*
67+
*.exe
68+
*.exe~
69+
*.dll
70+
*.so
71+
*.dylib
72+
*.test
73+
*.out
74+
.svn/
75+
[._]*.s[a-v][a-z]
76+
!*.svg # comment out if you don't need vector files
77+
[._]*.sw[a-p]
78+
[._]s[a-rt-v][a-z]
79+
[._]ss[a-gi-z]
80+
[._]sw[a-p]
81+
Session.vim
82+
Sessionx.vim
83+
.netrwhist
84+
tags
85+
[._]*.un~
86+
Thumbs.db
87+
Thumbs.db:encryptable
88+
ehthumbs.db
89+
ehthumbs_vista.db
90+
*.stackdump
91+
[Dd]esktop.ini
92+
$RECYCLE.BIN/
93+
*.cab
94+
*.msi
95+
*.msix
96+
*.msm
97+
*.msp
98+
*.lnk
99+
.DS_Store
100+
.AppleDouble
101+
.LSOverride
102+
Icon
103+
._*
104+
.DocumentRevisions-V100
105+
.fseventsd
106+
.Spotlight-V100
107+
.TemporaryItems
108+
.Trashes
109+
.VolumeIcon.icns
110+
.com.apple.timemachine.donotpresent
111+
.AppleDB
112+
.AppleDesktop
113+
Network Trash Folder
114+
Temporary Items
115+
.apdisk
116+
.vagrant/
117+
_output/

Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Build the manager binary
2+
FROM golang:1.20 as builder
3+
4+
WORKDIR /workspace
5+
# Copy the Go Modules manifests
6+
COPY go.mod go.mod
7+
COPY go.sum go.sum
8+
# cache deps before building and copying source so that we don't need to re-download as much
9+
# and so that source changes don't invalidate our downloaded layer
10+
RUN go mod download
11+
12+
# Copy the go source
13+
COPY main.go main.go
14+
COPY api/ api/
15+
COPY controllers/ controllers/
16+
17+
# Build
18+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
19+
20+
# Use distroless as minimal base image to package the manager binary
21+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
22+
FROM gcr.io/distroless/static:nonroot
23+
WORKDIR /
24+
COPY --from=builder /workspace/manager .
25+
USER 65532:65532
26+
27+
ENTRYPOINT ["/manager"]

Makefile

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
# VERSION defines the project version for the bundle.
2+
# Update this value when you upgrade the version of your project.
3+
# To re-generate a bundle for another specific version without changing the standard setup, you can:
4+
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
5+
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
6+
VERSION ?= 0.0.1
7+
8+
# CHANNELS define the bundle channels used in the bundle.
9+
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
10+
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
11+
# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable)
12+
# - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable")
13+
ifneq ($(origin CHANNELS), undefined)
14+
BUNDLE_CHANNELS := --channels=$(CHANNELS)
15+
endif
16+
17+
# DEFAULT_CHANNEL defines the default channel used in the bundle.
18+
# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable")
19+
# To re-generate a bundle for any other default channel without changing the default setup, you can:
20+
# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
21+
# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
22+
ifneq ($(origin DEFAULT_CHANNEL), undefined)
23+
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
24+
endif
25+
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
26+
27+
# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
28+
# This variable is used to construct full image tags for bundle and catalog images.
29+
#
30+
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
31+
# kubebb.k8s.com.cn/core-bundle:$VERSION and kubebb.k8s.com.cn/core-catalog:$VERSION.
32+
IMAGE_TAG_BASE ?= kubebb.k8s.com.cn/core
33+
34+
# BUNDLE_IMG defines the image:tag used for the bundle.
35+
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
36+
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
37+
38+
# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
39+
BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
40+
41+
# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
42+
# You can enable this value if you would like to use SHA Based Digests
43+
# To enable set flag to true
44+
USE_IMAGE_DIGESTS ?= false
45+
ifeq ($(USE_IMAGE_DIGESTS), true)
46+
BUNDLE_GEN_FLAGS += --use-image-digests
47+
endif
48+
49+
# Image URL to use all building/pushing image targets
50+
IMG ?= controller:latest
51+
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
52+
ENVTEST_K8S_VERSION = 1.24.2
53+
54+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
55+
ifeq (,$(shell go env GOBIN))
56+
GOBIN=$(shell go env GOPATH)/bin
57+
else
58+
GOBIN=$(shell go env GOBIN)
59+
endif
60+
61+
# Setting SHELL to bash allows bash commands to be executed by recipes.
62+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
63+
SHELL = /usr/bin/env bash -o pipefail
64+
.SHELLFLAGS = -ec
65+
66+
.PHONY: all
67+
all: build
68+
69+
##@ General
70+
71+
# The help target prints out all targets with their descriptions organized
72+
# beneath their categories. The categories are represented by '##@' and the
73+
# target descriptions by '##'. The awk commands is responsible for reading the
74+
# entire set of makefiles included in this invocation, looking for lines of the
75+
# file as xyz: ## something, and then pretty-format the target and help. Then,
76+
# if there's a line with ##@ something, that gets pretty-printed as a category.
77+
# More info on the usage of ANSI control characters for terminal formatting:
78+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
79+
# More info on the awk command:
80+
# http://linuxcommand.org/lc3_adv_awk.php
81+
82+
.PHONY: help
83+
help: ## Display this help.
84+
@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)
85+
86+
##@ Development
87+
88+
.PHONY: manifests
89+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
90+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
91+
92+
.PHONY: generate
93+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
94+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
95+
96+
.PHONY: fmt
97+
fmt: ## Run go fmt against code.
98+
go fmt ./...
99+
100+
.PHONY: vet
101+
vet: ## Run go vet against code.
102+
go vet ./...
103+
104+
.PHONY: test
105+
test: manifests generate fmt vet envtest ## Run tests.
106+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
107+
108+
##@ Build
109+
110+
.PHONY: build
111+
build: generate fmt vet ## Build manager binary.
112+
go build -o bin/manager main.go
113+
114+
.PHONY: run
115+
run: manifests generate fmt vet ## Run a controller from your host.
116+
go run ./main.go
117+
118+
.PHONY: docker-build
119+
docker-build: test ## Build docker image with the manager.
120+
docker build -t ${IMG} .
121+
122+
.PHONY: docker-push
123+
docker-push: ## Push docker image with the manager.
124+
docker push ${IMG}
125+
126+
##@ Deployment
127+
128+
ifndef ignore-not-found
129+
ignore-not-found = false
130+
endif
131+
132+
.PHONY: install
133+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
134+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
135+
136+
.PHONY: uninstall
137+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
138+
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
139+
140+
.PHONY: deploy
141+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
142+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
143+
$(KUSTOMIZE) build config/default | kubectl apply -f -
144+
145+
.PHONY: undeploy
146+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
147+
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
148+
149+
##@ Build Dependencies
150+
151+
## Location to install dependencies to
152+
LOCALBIN ?= $(shell pwd)/bin
153+
$(LOCALBIN):
154+
mkdir -p $(LOCALBIN)
155+
156+
## Tool Binaries
157+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
158+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
159+
ENVTEST ?= $(LOCALBIN)/setup-envtest
160+
161+
## Tool Versions
162+
KUSTOMIZE_VERSION ?= v3.8.7
163+
CONTROLLER_TOOLS_VERSION ?= v0.9.2
164+
165+
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
166+
.PHONY: kustomize
167+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
168+
$(KUSTOMIZE): $(LOCALBIN)
169+
test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
170+
171+
.PHONY: controller-gen
172+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
173+
$(CONTROLLER_GEN): $(LOCALBIN)
174+
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
175+
176+
.PHONY: envtest
177+
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
178+
$(ENVTEST): $(LOCALBIN)
179+
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
180+
181+
.PHONY: bundle
182+
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
183+
operator-sdk generate kustomize manifests -q
184+
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
185+
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS)
186+
operator-sdk bundle validate ./bundle
187+
188+
.PHONY: bundle-build
189+
bundle-build: ## Build the bundle image.
190+
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
191+
192+
.PHONY: bundle-push
193+
bundle-push: ## Push the bundle image.
194+
$(MAKE) docker-push IMG=$(BUNDLE_IMG)
195+
196+
.PHONY: opm
197+
OPM = ./bin/opm
198+
opm: ## Download opm locally if necessary.
199+
ifeq (,$(wildcard $(OPM)))
200+
ifeq (,$(shell which opm 2>/dev/null))
201+
@{ \
202+
set -e ;\
203+
mkdir -p $(dir $(OPM)) ;\
204+
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
205+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\
206+
chmod +x $(OPM) ;\
207+
}
208+
else
209+
OPM = $(shell which opm)
210+
endif
211+
endif
212+
213+
# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0).
214+
# These images MUST exist in a registry and be pull-able.
215+
BUNDLE_IMGS ?= $(BUNDLE_IMG)
216+
217+
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
218+
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION)
219+
220+
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
221+
ifneq ($(origin CATALOG_BASE_IMG), undefined)
222+
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
223+
endif
224+
225+
# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
226+
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
227+
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
228+
.PHONY: catalog-build
229+
catalog-build: opm ## Build a catalog image.
230+
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
231+
232+
# Push the catalog image.
233+
.PHONY: catalog-push
234+
catalog-push: ## Push a catalog image.
235+
$(MAKE) docker-push IMG=$(CATALOG_IMG)

0 commit comments

Comments
 (0)