Skip to content

Commit 849a903

Browse files
committed
update operator dsk version
Signed-off-by: Jeeva Kandasamy <jkandasa@gmail.com>
1 parent 0906753 commit 849a903

26 files changed

+715
-717
lines changed

.github/workflows/publish_images.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: publish container images
22
on:
33
push:
44
branches: [master]
5+
tags: ["v*"]
56

67
jobs:
78
setup:
@@ -21,11 +22,11 @@ jobs:
2122

2223
- uses: actions/setup-go@v2
2324
with:
24-
go-version: ^1.16
25+
go-version: ^1.18
2526

2627
- uses: jpkrohling/setup-operator-sdk@v1.1.0
2728
with:
28-
operator-sdk-version: v1.11.0
29+
operator-sdk-version: v1.23.0
2930

3031
- name: Build container and push
3132
run: |

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.16 as builder
2+
FROM golang:1.18 as builder
33

44
WORKDIR /workspace
55
# Copy the Go Modules manifests
@@ -19,9 +19,9 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
1919

2020
# Use distroless as minimal base image to package the manager binary
2121
# Refer to https://github.com/GoogleContainerTools/distroless for more details
22-
FROM alpine:latest
22+
FROM gcr.io/distroless/static:nonroot
2323
WORKDIR /
2424
COPY --from=builder /workspace/manager .
25-
# USER 65532:65532
25+
USER 65532:65532
2626

2727
ENTRYPOINT ["/manager"]

Makefile

Lines changed: 66 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# To re-generate a bundle for another specific version without changing the standard setup, you can:
44
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
55
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
6-
VERSION ?= 0.0.1
6+
VERSION ?= 1.0.0
77

88
# CHANNELS define the bundle channels used in the bundle.
99
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
@@ -35,10 +35,20 @@ IMAGE_TAG_BASE ?= quay.io/mycontroller/mycontroller-operator
3535
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
3636
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
3737

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+
3849
# Image URL to use all building/pushing image targets
3950
IMG ?= $(IMAGE_TAG_BASE):$(VERSION)
40-
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
41-
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
51+
4252
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
4353
ENVTEST_K8S_VERSION = 1.21
4454

@@ -50,11 +60,11 @@ GOBIN=$(shell go env GOBIN)
5060
endif
5161

5262
# Setting SHELL to bash allows bash commands to be executed by recipes.
53-
# This is a requirement for 'setup-envtest.sh' in the test target.
5463
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
5564
SHELL = /usr/bin/env bash -o pipefail
5665
.SHELLFLAGS = -ec
5766

67+
.PHONY: all
5868
all: build
5969

6070
##@ General
@@ -70,87 +80,110 @@ all: build
7080
# More info on the awk command:
7181
# http://linuxcommand.org/lc3_adv_awk.php
7282

83+
.PHONY: help
7384
help: ## Display this help.
7485
@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)
7586

7687
##@ Development
7788

89+
.PHONY: manifests
7890
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
79-
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
91+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
8092

93+
.PHONY: generate
8194
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
8295
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
8396

97+
.PHONY: fmt
8498
fmt: ## Run go fmt against code.
8599
go fmt ./...
86100

101+
.PHONY: vet
87102
vet: ## Run go vet against code.
88103
go vet ./...
89104

105+
.PHONY: test
90106
test: manifests generate fmt vet envtest ## Run tests.
91107
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
92108

93109
##@ Build
94110

111+
.PHONY: build
95112
build: generate fmt vet ## Build manager binary.
96113
go build -o bin/manager main.go
97114

115+
.PHONY: run
98116
run: manifests generate fmt vet ## Run a controller from your host.
99117
go run ./main.go
100118

119+
.PHONY: docker-build
101120
docker-build: test ## Build docker image with the manager.
102121
docker build -t ${IMG} .
103122

123+
.PHONY: docker-push
104124
docker-push: ## Push docker image with the manager.
105125
docker push ${IMG}
106126

107127
##@ Deployment
108128

129+
ifndef ignore-not-found
130+
ignore-not-found = false
131+
endif
132+
133+
.PHONY: install
109134
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
110135
$(KUSTOMIZE) build config/crd | kubectl apply -f -
111136

112-
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
113-
$(KUSTOMIZE) build config/crd | kubectl delete -f -
137+
.PHONY: uninstall
138+
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.
139+
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
114140

141+
.PHONY: deploy
115142
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
116143
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
117144
$(KUSTOMIZE) build config/default | kubectl apply -f -
118145

119-
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
120-
$(KUSTOMIZE) build config/default | kubectl delete -f -
146+
.PHONY: undeploy
147+
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.
148+
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
149+
150+
##@ Build Dependencies
151+
152+
## Location to install dependencies to
153+
LOCALBIN ?= $(shell pwd)/bin
154+
$(LOCALBIN):
155+
mkdir -p $(LOCALBIN)
121156

157+
## Tool Binaries
158+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
159+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
160+
ENVTEST ?= $(LOCALBIN)/setup-envtest
122161

123-
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
124-
controller-gen: ## Download controller-gen locally if necessary.
125-
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.1)
162+
## Tool Versions
163+
KUSTOMIZE_VERSION ?= v3.8.7
164+
CONTROLLER_TOOLS_VERSION ?= v0.9.2
126165

127-
KUSTOMIZE = $(shell pwd)/bin/kustomize
128-
kustomize: ## Download kustomize locally if necessary.
129-
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)
166+
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
167+
.PHONY: kustomize
168+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
169+
$(KUSTOMIZE): $(LOCALBIN)
170+
test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
130171

131-
ENVTEST = $(shell pwd)/bin/setup-envtest
132-
envtest: ## Download envtest-setup locally if necessary.
133-
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
172+
.PHONY: controller-gen
173+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
174+
$(CONTROLLER_GEN): $(LOCALBIN)
175+
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
134176

135-
# go-get-tool will 'go get' any package $2 and install it to $1.
136-
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
137-
define go-get-tool
138-
@[ -f $(1) ] || { \
139-
set -e ;\
140-
TMP_DIR=$$(mktemp -d) ;\
141-
cd $$TMP_DIR ;\
142-
go mod init tmp ;\
143-
echo "Downloading $(2)" ;\
144-
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
145-
rm -rf $$TMP_DIR ;\
146-
}
147-
endef
177+
.PHONY: envtest
178+
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
179+
$(ENVTEST): $(LOCALBIN)
180+
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
148181

149182
.PHONY: bundle
150183
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
151184
operator-sdk generate kustomize manifests -q
152185
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
153-
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
186+
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS)
154187
operator-sdk bundle validate ./bundle
155188

156189
.PHONY: bundle-build
@@ -170,7 +203,7 @@ ifeq (,$(shell which opm 2>/dev/null))
170203
set -e ;\
171204
mkdir -p $(dir $(OPM)) ;\
172205
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
173-
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$${OS}-$${ARCH}-opm ;\
206+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\
174207
chmod +x $(OPM) ;\
175208
}
176209
else

PROJECT

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ plugins:
55
manifests.sdk.operatorframework.io/v2: {}
66
scorecard.sdk.operatorframework.io/v2: {}
77
projectName: mycontroller-operator
8-
repo: github.com/jkandasa/mycontroller-operator
8+
repo: github.com/mycontroller-org/mycontroller-operator
99
resources:
1010
- api:
1111
crdVersion: v1
1212
namespaced: true
1313
controller: true
1414
domain: mycontroller.org
1515
kind: MyController
16-
path: github.com/jkandasa/mycontroller-operator/api/v1
16+
path: github.com/mycontroller-org/mycontroller-operator/api/v1
1717
version: v1
1818
version: "3"

api/v1/groupversion_info.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ limitations under the License.
1515
*/
1616

1717
// Package v1 contains API Schema definitions for the v1 API group
18-
//+kubebuilder:object:generate=true
19-
//+groupName=mycontroller.org
18+
// +kubebuilder:object:generate=true
19+
// +groupName=mycontroller.org
2020
package v1
2121

2222
import (

api/v1/zz_generated.deepcopy.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
66
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
77
LABEL operators.operatorframework.io.bundle.package.v1=mycontroller-operator
88
LABEL operators.operatorframework.io.bundle.channels.v1=alpha
9-
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.10.0+git
9+
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.23.0
1010
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
1111
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3
1212

bundle/manifests/mycontroller-operator-manager-config_v1_configmap.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ data:
1212
leaderElection:
1313
leaderElect: true
1414
resourceName: 240f72f7.mycontroller.org
15+
# leaderElectionReleaseOnCancel defines if the leader should step down volume
16+
# when the Manager ends. This requires the binary to immediately end when the
17+
# Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
18+
# speeds up voluntary leader transitions as the new leader don't have to wait
19+
# LeaseDuration time first.
20+
# In the default scaffold provided, the program ends immediately after
21+
# the manager stops, so would be fine to enable this option. However,
22+
# if you are doing or is intended to do any operation such as perform cleanups
23+
# after the manager stops then its usage might be unsafe.
24+
# leaderElectionReleaseOnCancel: true
1525
kind: ConfigMap
1626
metadata:
1727
name: mycontroller-operator-manager-config

0 commit comments

Comments
 (0)