Skip to content

Commit 4530649

Browse files
committed
Migrate from kubebuilder v2 to v3
1 parent 909a06f commit 4530649

File tree

93 files changed

+42680
-32657
lines changed

Some content is hidden

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

93 files changed

+42680
-32657
lines changed

.dockerignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore build and test binaries.
3+
bin/
4+
testbin/

.github/workflows/go.yml

+7-9
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,20 @@ jobs:
1212
build:
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v3
1616

1717
- name: Set up Go
18-
uses: actions/setup-go@v2
18+
uses: actions/setup-go@v3
1919
with:
20-
go-version: 1.15
20+
go-version: 1.19
2121

2222
- name: Install Kubebuilder
2323
run: |
24-
version=2.3.1
24+
version=3.2.0
2525
os=$(go env GOOS)
2626
arch=$(go env GOARCH)
27-
curl -L -O "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${version}/kubebuilder_${version}_${os}_${arch}.tar.gz"
28-
tar -zxvf kubebuilder_${version}_${os}_${arch}.tar.gz
29-
sudo mv kubebuilder_${version}_${os}_${arch} /usr/local/kubebuilder
30-
rm -f kubebuilder_${version}_${os}_${arch}.tar.gz
31-
sudo find /usr/local/kubebuilder/bin -type f -exec ln -s {} /usr/local/bin \;
27+
curl -L -o kubebuilder "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${version}/kubebuilder_${os}_${arch}"
28+
sudo chmod +x kubebuilder
29+
sudo mv kubebuilder /usr/local/bin/
3230
- name: Test
3331
run: make manifests test

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.13 as builder
2+
FROM golang:1.19 as builder
33

44
# Copy everything in the go src
55
WORKDIR /go/src/cdap.io/cdap-operator

LICENSE.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright © 2019 CDAP Authors.
1+
Copyright © 2019-2022 CDAP Authors.
22

33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.

Makefile

+105-52
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
# Image URL to use all building/pushing image targets
33
IMG ?= controller:latest
4-
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
5-
CRD_OPTIONS ?= "crd:trivialVersions=true"
4+
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5+
ENVTEST_K8S_VERSION = 1.22
66

77
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
88
ifeq (,$(shell go env GOBIN))
@@ -11,70 +11,123 @@ else
1111
GOBIN=$(shell go env GOBIN)
1212
endif
1313

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

16-
# Run tests
17-
test: generate fmt vet manifests
18-
go test ./... -coverprofile cover.out
20+
.PHONY: all
21+
all: build
1922

20-
# Build manager binary
21-
manager: generate fmt vet
22-
go build -o bin/manager main.go
23+
##@ General
2324

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

28-
# Install CRDs into a cluster
29-
install: manifests
30-
kustomize build config/crd | kubectl apply -f -
36+
.PHONY: help
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)
3139

32-
# Uninstall CRDs from a cluster
33-
uninstall: manifests
34-
kustomize build config/crd | kubectl delete -f -
40+
##@ Development
3541

36-
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
37-
deploy: manifests
38-
cd config/manager && kustomize edit set image controller=${IMG}
39-
kustomize build config/default | kubectl apply -f -
42+
.PHONY: manifests
43+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
44+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
4045

41-
# Generate manifests e.g. CRD, RBAC etc.
42-
manifests: controller-gen
43-
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
46+
.PHONY: generate
47+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
48+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
4449

45-
# Run go fmt against code
46-
fmt:
50+
.PHONY: fmt
51+
fmt: ## Run go fmt against code.
4752
go fmt ./...
4853

49-
# Run go vet against code
50-
vet:
54+
.PHONY: vet
55+
vet: ## Run go vet against code.
5156
go vet ./...
5257

53-
# Generate code
54-
generate: controller-gen
55-
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths="./..."
58+
.PHONY: test
59+
test: manifests generate fmt vet envtest ## Run tests.
60+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
61+
62+
##@ Build
5663

57-
# Build the docker image
58-
docker-build: test
59-
docker build . -t ${IMG}
64+
.PHONY: build
65+
build: generate fmt vet ## Build manager binary.
66+
go build -o bin/manager main.go
67+
68+
.PHONY: run
69+
run: manifests generate fmt vet ## Run a controller from your host.
70+
go run ./main.go
6071

61-
# Push the docker image
62-
docker-push:
72+
.PHONY: docker-build
73+
docker-build: test ## Build docker image with the manager.
74+
docker build -t ${IMG} .
75+
76+
.PHONY: docker-push
77+
docker-push: ## Push docker image with the manager.
6378
docker push ${IMG}
6479

65-
# find or download controller-gen
66-
# download controller-gen if necessary
67-
controller-gen:
68-
ifeq (, $(shell which controller-gen))
69-
@{ \
70-
set -e ;\
71-
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
72-
cd $$CONTROLLER_GEN_TMP_DIR ;\
73-
go mod init tmp ;\
74-
go get sigs.k8s.io/controller-tools/cmd/[email protected] ;\
75-
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
76-
}
77-
CONTROLLER_GEN=$(GOBIN)/controller-gen
78-
else
79-
CONTROLLER_GEN=$(shell which controller-gen)
80+
##@ Deployment
81+
82+
ifndef ignore-not-found
83+
ignore-not-found = false
8084
endif
85+
86+
.PHONY: install
87+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
88+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
89+
90+
.PHONY: uninstall
91+
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.
92+
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
93+
94+
.PHONY: deploy
95+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
96+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
97+
$(KUSTOMIZE) build config/default | kubectl apply -f -
98+
99+
.PHONY: undeploy
100+
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.
101+
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
102+
103+
##@ Build Dependencies
104+
## Location to install dependencies to
105+
LOCALBIN ?= $(shell pwd)/bin
106+
$(LOCALBIN):
107+
mkdir -p $(LOCALBIN)
108+
109+
## Tool Binaries
110+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
111+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
112+
ENVTEST ?= $(LOCALBIN)/setup-envtest
113+
114+
## Tool Versions
115+
KUSTOMIZE_VERSION ?= v3.8.7
116+
CONTROLLER_TOOLS_VERSION ?= v0.7.0
117+
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
118+
119+
.PHONY: kustomize
120+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
121+
$(KUSTOMIZE): $(LOCALBIN)
122+
test -s $(LOCALBIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
123+
124+
.PHONY: controller-gen
125+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
126+
$(CONTROLLER_GEN): $(LOCALBIN)
127+
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
128+
129+
.PHONY: envtest
130+
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
131+
$(ENVTEST): $(LOCALBIN)
132+
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
133+

PROJECT

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
domain: cdap.io
2+
layout:
3+
- go.kubebuilder.io/v3
4+
projectName: cdap-operator
25
repo: cdap.io/cdap-operator
36
resources:
4-
- group: cdap
7+
- api:
8+
crdVersion: v1
9+
namespaced: true
10+
controller: true
11+
domain: cdap.io
12+
group: cdap
513
kind: CDAPMaster
14+
path: cdap.io/cdap-operator/api/v1alpha1
615
version: v1alpha1
7-
version: "2"
16+
version: "3"

api/v1alpha1/cdapmaster_types.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
Copyright 2022.
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.
@@ -24,13 +25,13 @@ import (
2425
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
2526
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
2627

27-
// CDAPMasterSpec defines the desired state of CDAPMaster
28-
//
2928
// Important notes:
3029
// * The field name of each service MUST match the constant values of ServiceName in constants.go as reflection
3130
// is used to find field value.
3231
// * For services that are optional (i.e. may or may not be required for CDAP to be operational), their service
3332
// specification fields are pointers. By default, these optional services are disabled. Set to non-nil to enable them.
33+
34+
// CDAPMasterSpec defines the desired state of CDAPMaster
3435
type CDAPMasterSpec struct {
3536
// Image is the docker image name for the CDAP backend.
3637
Image string `json:"image,omitempty"`
@@ -117,7 +118,7 @@ type CDAPMasterSpec struct {
117118
// For information on supported volume types, see https://kubernetes.io/docs/concepts/storage/volumes/.
118119
AdditionalVolumes []corev1.Volume `json:"additionalVolumes,omitempty"`
119120
// AdditionalVolumeMounts defines a list of additional volume mounts for all services.
120-
// For information on suported volume mount types, see https://kubernetes.io/docs/concepts/storage/volumes/.
121+
// For information on supported volume mount types, see https://kubernetes.io/docs/concepts/storage/volumes/.
121122
AdditionalVolumeMounts []corev1.VolumeMount `json:"additionalVolumeMounts,omitempty"`
122123
}
123124

@@ -152,7 +153,7 @@ type CDAPServiceSpec struct {
152153
// For information on supported volume types, see https://kubernetes.io/docs/concepts/storage/volumes/.
153154
AdditionalVolumes []corev1.Volume `json:"additionalVolumes,omitempty"`
154155
// AdditionalVolumeMounts defines a list of additional volume mounts for the service.
155-
// For information on suported volume mount types, see https://kubernetes.io/docs/concepts/storage/volumes/.
156+
// For information on supported volume mount types, see https://kubernetes.io/docs/concepts/storage/volumes/.
156157
AdditionalVolumeMounts []corev1.VolumeMount `json:"additionalVolumeMounts,omitempty"`
157158
// SecurityContext overrides the security context for the service pods.
158159
SecurityContext *SecurityContext `json:"securityContext,omitempty"`
@@ -291,7 +292,7 @@ type CDAPMasterStatus struct {
291292
DowngradeStartTimeMillis int64 `json:"downgradeStartTimeMillis,omitempty"`
292293
}
293294

294-
// +kubebuilder:object:root=true
295+
//+kubebuilder:object:root=true
295296

296297
// CDAPMaster is the Schema for the cdapmasters API
297298
type CDAPMaster struct {
@@ -302,7 +303,7 @@ type CDAPMaster struct {
302303
Status CDAPMasterStatus `json:"status,omitempty"`
303304
}
304305

305-
// +kubebuilder:object:root=true
306+
//+kubebuilder:object:root=true
306307

307308
// CDAPMasterList contains a list of CDAPMaster
308309
type CDAPMasterList struct {

api/v1alpha1/groupversion_info.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
Copyright 2022.
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/v1alpha1/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)