Skip to content

Commit 6f50217

Browse files
Merge pull request #8 from acornett21/update_latest_deps
updating to latest go and k8s dependencies
2 parents 4c98590 + 6c6f588 commit 6f50217

File tree

12 files changed

+319
-702
lines changed

12 files changed

+319
-702
lines changed

Dockerfile

Lines changed: 2 additions & 2 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.21 as builder
33

44
WORKDIR /workspace
55
# Copy the Go Modules manifests
@@ -17,7 +17,7 @@ COPY controllers/ controllers/
1717
# Build
1818
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
1919

20-
FROM registry.access.redhat.com/ubi8/ubi-micro
20+
FROM registry.access.redhat.com/ubi9/ubi-micro
2121
WORKDIR /
2222
COPY --from=builder /workspace/manager .
2323
COPY LICENSE /licenses/LICENSE

Makefile

Lines changed: 80 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
IMAGE_BUILDER ?= podman
2+
13
# VERSION defines the project version for the bundle.
24
# Update this value when you upgrade the version of your project.
35
# To re-generate a bundle for another specific version without changing the standard setup, you can:
@@ -37,13 +39,23 @@ IMAGE_TAG_BASE ?= quay.io/opdev/simple-demo-operator
3739
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
3840
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
3941

42+
# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
43+
BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
44+
45+
# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
46+
# You can enable this value if you would like to use SHA Based Digests
47+
# To enable set flag to true
48+
USE_IMAGE_DIGESTS ?= true
49+
ifeq ($(USE_IMAGE_DIGESTS), true)
50+
BUNDLE_GEN_FLAGS += --use-image-digests
51+
endif
52+
4053
# Image URL to use all building/pushing image targets
4154
IMG ?= $(IMAGE_TAG_BASE):$(VERSION)
4255
IMGLATEST = $(IMAGE_TAG_BASE):latest
43-
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
44-
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
56+
4557
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
46-
ENVTEST_K8S_VERSION = 1.21
58+
ENVTEST_K8S_VERSION = 1.26.0
4759

4860
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
4961
ifeq (,$(shell go env GOBIN))
@@ -79,7 +91,7 @@ help: ## Display this help.
7991
##@ Development
8092

8193
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
82-
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
94+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
8395

8496
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
8597
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
@@ -102,13 +114,13 @@ run: manifests generate fmt vet ## Run a controller from your host.
102114
go run ./main.go
103115

104116
docker-build: ## Build docker image with the manager.
105-
docker build -t ${IMG} .
117+
$(IMAGE_BUILDER) build -t ${IMG} .
106118

107119
docker-push: ## Push docker image with the manager.
108-
docker push ${IMG}
120+
$(IMAGE_BUILDER) push ${IMG}
109121

110122
docker-tag-latest: ## tag as latest
111-
docker tag ${IMG} $(IMGLATEST)
123+
$(IMAGE_BUILDER) tag ${IMG} $(IMGLATEST)
112124

113125
docker-push-tag-latest: ## tag as latest
114126
$(MAKE) docker-push IMG=$(IMGLATEST)
@@ -129,52 +141,77 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi
129141
$(KUSTOMIZE) build config/default | kubectl delete -f -
130142

131143

132-
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
133-
controller-gen: ## Download controller-gen locally if necessary.
134-
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
135-
136-
KUSTOMIZE = $(shell pwd)/bin/kustomize
137-
kustomize: ## Download kustomize locally if necessary.
138-
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
139-
140-
ENVTEST = $(shell pwd)/bin/setup-envtest
141-
envtest: ## Download envtest-setup locally if necessary.
142-
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
143-
144-
DIGESTPINTOOL = $(shell pwd)/bin/pin-deploy-imgs-in-csv
145-
digestpintool: ## Download envtest-setup locally if necessary.
146-
$(call go-get-tool,$(DIGESTPINTOOL),github.com/opdev/[email protected])
144+
## Location to install dependencies to
145+
LOCALBIN ?= $(shell pwd)/bin
146+
$(LOCALBIN):
147+
mkdir -p $(LOCALBIN)
148+
149+
## Tool Binaries
150+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
151+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
152+
ENVTEST ?= $(LOCALBIN)/setup-envtest
153+
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
154+
155+
## Tool Versions
156+
KUSTOMIZE_VERSION ?= v4.5.7
157+
CONTROLLER_TOOLS_VERSION ?= v0.11.1
158+
OPERATOR_SDK_VERSION ?= "v1.32.0"
159+
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
160+
.PHONY: kustomize
161+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
162+
$(KUSTOMIZE): $(LOCALBIN)
163+
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
164+
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
165+
rm -rf $(LOCALBIN)/kustomize; \
166+
fi
167+
test -s $(LOCALBIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
168+
169+
.PHONY: controller-gen
170+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
171+
$(CONTROLLER_GEN): $(LOCALBIN)
172+
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
173+
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
174+
175+
.PHONY: envtest
176+
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
177+
$(ENVTEST): $(LOCALBIN)
178+
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
179+
180+
.PHONY: operator-sdk
181+
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
182+
operator-sdk: ## Download operator-sdk locally if necessary.
183+
ifeq (,$(wildcard $(OPERATOR_SDK)))
184+
ifeq (, $(shell which operator-sdk 2>/dev/null))
185+
@{ \
186+
set -e ;\
187+
mkdir -p $(dir $(OPERATOR_SDK)) ;\
188+
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
189+
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
190+
chmod +x $(OPERATOR_SDK) ;\
191+
}
192+
else
193+
OPERATOR_SDK = $(shell which operator-sdk)
194+
endif
195+
endif
147196

148-
# go-get-tool will 'go get' any package $2 and install it to $1.
197+
# go-install-tool will 'go get' any package $2 and install it to $1.
149198
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
150-
define go-get-tool
199+
define go-install-tool
151200
@[ -f $(1) ] || { \
152-
set -e ;\
153-
TMP_DIR=$$(mktemp -d) ;\
154-
cd $$TMP_DIR ;\
155-
go mod init tmp ;\
156-
echo "Downloading $(2)" ;\
157-
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
158-
rm -rf $$TMP_DIR ;\
201+
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
159202
}
160203
endef
161204

162-
.PHONY: pin-ctrlr-digest
163-
pin-controller-digest: digestpintool
164-
$(DIGESTPINTOOL) ./bundle/manifests/simple-demo-operator.clusterserviceversion.yaml
165-
166-
167205
.PHONY: bundle
168-
bundle: manifests kustomize digestpintool ## Generate bundle manifests and metadata, then validate generated files.
206+
bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
169207
operator-sdk generate kustomize manifests -q
170208
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
171-
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
172-
173-
operator-sdk bundle validate ./bundle
209+
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
210+
$(OPERATOR_SDK) bundle validate ./bundle
174211

175212
.PHONY: bundle-build
176213
bundle-build: ## Build the bundle image.
177-
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
214+
$(IMAGE_BUILDER) build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
178215

179216
.PHONY: bundle-push
180217
bundle-push: ## Push the bundle image.
@@ -189,7 +226,7 @@ ifeq (,$(shell which opm 2>/dev/null))
189226
set -e ;\
190227
mkdir -p $(dir $(OPM)) ;\
191228
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
192-
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$${OS}-$${ARCH}-opm ;\
229+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\
193230
chmod +x $(OPM) ;\
194231
}
195232
else
@@ -214,7 +251,7 @@ endif
214251
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
215252
.PHONY: catalog-build
216253
catalog-build: opm ## Build a catalog image.
217-
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
254+
$(OPM) index add --container-tool $(IMAGE_BUILDER) --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
218255

219256
# Push the catalog image.
220257
.PHONY: catalog-push

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 tools v1 API group
18-
//+kubebuilder:object:generate=true
19-
//+groupName=tools.opdev.io
18+
// +kubebuilder:object:generate=true
19+
// +groupName=tools.opdev.io
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
@@ -7,7 +7,7 @@ LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
77
LABEL operators.operatorframework.io.bundle.package.v1=simple-demo-operator
88
LABEL operators.operatorframework.io.bundle.channels.v1=stable
99
LABEL operators.operatorframework.io.bundle.channel.default.v1=stable
10-
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.18.0+git
10+
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.32.0
1111
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
1212
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3
1313

config/crd/bases/tools.opdev.io_demoresources.yaml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
21
---
32
apiVersion: apiextensions.k8s.io/v1
43
kind: CustomResourceDefinition
54
metadata:
65
annotations:
7-
controller-gen.kubebuilder.io/version: v0.6.1
6+
controller-gen.kubebuilder.io/version: v0.11.1
87
creationTimestamp: null
98
name: demoresources.tools.opdev.io
109
spec:
@@ -59,9 +58,3 @@ spec:
5958
storage: true
6059
subresources:
6160
status: {}
62-
status:
63-
acceptedNames:
64-
kind: ""
65-
plural: ""
66-
conditions: []
67-
storedVersions: []

config/default/manager_auth_proxy_patch.yaml

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,26 @@ spec:
99
template:
1010
spec:
1111
containers:
12-
- name: kube-rbac-proxy
13-
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0
14-
args:
15-
- "--secure-listen-address=0.0.0.0:8443"
16-
- "--upstream=http://127.0.0.1:8080/"
17-
- "--logtostderr=true"
18-
- "--v=10"
19-
ports:
20-
- containerPort: 8443
21-
protocol: TCP
22-
name: https
23-
- name: manager
24-
args:
25-
- "--health-probe-bind-address=:8081"
26-
- "--metrics-bind-address=127.0.0.1:8080"
27-
- "--leader-elect"
12+
- name: kube-rbac-proxy
13+
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.13.1
14+
args:
15+
- "--secure-listen-address=0.0.0.0:8443"
16+
- "--upstream=http://127.0.0.1:8080/"
17+
- "--logtostderr=true"
18+
- "--v=0"
19+
ports:
20+
- containerPort: 8443
21+
protocol: TCP
22+
name: https
23+
resources:
24+
limits:
25+
cpu: 500m
26+
memory: 128Mi
27+
requests:
28+
cpu: 5m
29+
memory: 64Mi
30+
- name: manager
31+
args:
32+
- "--health-probe-bind-address=:8081"
33+
- "--metrics-bind-address=127.0.0.1:8080"
34+
- "--leader-elect"

config/rbac/role.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
---
32
apiVersion: rbac.authorization.k8s.io/v1
43
kind: ClusterRole

controllers/demoresource_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (r *DemoResourceReconciler) Reconcile(ctx context.Context, req ctrl.Request
5858

5959
rsrc.Status.SpecMessage = rsrc.Spec.Message
6060
l.Info("Let's update the status with the message from the spec!")
61-
if err := r.Status().Update(ctx, &rsrc, &client.UpdateOptions{}); err != nil {
61+
if err := r.Status().Update(ctx, &rsrc); err != nil {
6262
l.Info("Uh oh! I ran into something unexpected.")
6363
return ctrl.Result{}, err
6464
}

controllers/suite_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"k8s.io/client-go/rest"
2727
"sigs.k8s.io/controller-runtime/pkg/client"
2828
"sigs.k8s.io/controller-runtime/pkg/envtest"
29-
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
3029
logf "sigs.k8s.io/controller-runtime/pkg/log"
3130
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3231

@@ -44,9 +43,7 @@ var testEnv *envtest.Environment
4443
func TestAPIs(t *testing.T) {
4544
RegisterFailHandler(Fail)
4645

47-
RunSpecsWithDefaultAndCustomReporters(t,
48-
"Controller Suite",
49-
[]Reporter{printer.NewlineReporter{}})
46+
RunSpecs(t, "Controller Suite")
5047
}
5148

5249
var _ = BeforeSuite(func() {

0 commit comments

Comments
 (0)