Skip to content

Commit a2c00b8

Browse files
enabled getting service account token via TokenRequest API (#44)
* enabled getting service account token via TokenRequest API Signed-off-by: raffaelespazzoli <[email protected]> * bumped to go 1.17 Signed-off-by: raffaelespazzoli <[email protected]> * upgrade to go 1.17 Signed-off-by: raffaelespazzoli <[email protected]> * updated to osdk 1.23 and golang 1.18 Signed-off-by: raffaelespazzoli <[email protected]> * added operator_sdk _version parameter to build Signed-off-by: raffaelespazzoli <[email protected]> Signed-off-by: raffaelespazzoli <[email protected]>
1 parent 7359429 commit a2c00b8

File tree

14 files changed

+503
-234
lines changed

14 files changed

+503
-234
lines changed

.github/workflows/pr.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ jobs:
1313
RUN_UNIT_TESTS: true
1414
RUN_INTEGRATION_TESTS: false
1515
RUN_HELMCHART_TEST: true
16+
GO_VERSION: ~1.18
17+
OPERATOR_SDK_VERSION: v1.23.0

.github/workflows/push.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ jobs:
2020
RUN_UNIT_TESTS: true
2121
RUN_INTEGRATION_TESTS: false
2222
RUN_HELMCHART_TEST: true
23+
GO_VERSION: ~1.18
24+
OPERATOR_SDK_VERSION: v1.23.0

Dockerfile

Lines changed: 1 addition & 1 deletion
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

Makefile

Lines changed: 66 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
3939
# redhat.io/patch-operator-bundle:$VERSION and redhat.io/patch-operator-catalog:$VERSION.
4040
IMAGE_TAG_BASE ?= quay.io/redhat-cop/$(OPERATOR_NAME)
4141

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 ?= false
49+
ifeq ($(USE_IMAGE_DIGESTS), true)
50+
BUNDLE_GEN_FLAGS += --use-image-digests
51+
endif
52+
4253
# BUNDLE_IMG defines the image:tag used for the bundle.
4354
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
4455
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
@@ -48,7 +59,7 @@ IMG ?= controller:latest
4859
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
4960
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
5061
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
51-
ENVTEST_K8S_VERSION = 1.21
62+
ENVTEST_K8S_VERSION = 1.24.1
5263

5364
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
5465
ifeq (,$(shell go env GOBIN))
@@ -63,6 +74,7 @@ endif
6374
SHELL = /usr/bin/env bash -o pipefail
6475
.SHELLFLAGS = -ec
6576

77+
.PHONY: all
6678
all: build
6779

6880
##@ General
@@ -78,23 +90,29 @@ all: build
7890
# More info on the awk command:
7991
# http://linuxcommand.org/lc3_adv_awk.php
8092

93+
.PHONY: help
8194
help: ## Display this help.
8295
@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)
8396

8497
##@ Development
8598

99+
.PHONY: manifests
86100
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
87-
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
101+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
88102

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

107+
.PHONY: fmt
92108
fmt: ## Run go fmt against code.
93109
go fmt ./...
94110

111+
.PHONY: vet
95112
vet: ## Run go vet against code.
96113
go vet ./...
97114

115+
.PHONY: test
98116
test: manifests generate fmt vet envtest ## Run tests.
99117
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
100118

@@ -107,65 +125,79 @@ kind-setup: kind kubectl helm
107125

108126
##@ Build
109127

128+
.PHONY: build
110129
build: generate fmt vet ## Build manager binary.
111130
go build -o bin/manager main.go
112131

132+
.PHONY: run
113133
run: manifests generate fmt vet ## Run a controller from your host.
114134
go run ./main.go
115135

136+
.PHONY: docker-build
116137
docker-build: test ## Build docker image with the manager.
117138
docker build -t ${IMG} .
118139

140+
.PHONY: docker-push
119141
docker-push: ## Push docker image with the manager.
120142
docker push ${IMG}
121143

122144
##@ Deployment
123145

146+
ifndef ignore-not-found
147+
ignore-not-found = false
148+
endif
149+
150+
.PHONY: install
124151
install: manifests kustomize kubectl ## Install CRDs into the K8s cluster specified in ~/.kube/config.
125152
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
126153

127-
uninstall: manifests kustomize kubectl ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
128-
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete -f -
154+
.PHONY: uninstall
155+
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.
156+
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
129157

158+
.PHONY: deploy
130159
deploy: manifests kustomize kubectl ## Deploy controller to the K8s cluster specified in ~/.kube/config.
131160
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
132161
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
133162

134-
undeploy: kustomize kubectl ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
135-
$(KUSTOMIZE) build config/default | $(KUBECTL) delete -f -
163+
.PHONY: undeploy
164+
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.
165+
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
166+
167+
LOCALBIN ?= $(shell pwd)/bin
168+
$(LOCALBIN):
169+
mkdir -p $(LOCALBIN)
170+
171+
## Tool Binaries
172+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
173+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
174+
ENVTEST ?= $(LOCALBIN)/setup-envtest
136175

176+
KUSTOMIZE_VERSION ?= v3.8.7
177+
CONTROLLER_TOOLS_VERSION ?= v0.9.0
137178

138-
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
139-
controller-gen: ## Download controller-gen locally if necessary.
140-
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
141179

142-
KUSTOMIZE = $(shell pwd)/bin/kustomize
143-
kustomize: ## Download kustomize locally if necessary.
144-
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
180+
.PHONY: controller-gen
181+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
182+
$(CONTROLLER_GEN): $(LOCALBIN)
183+
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
145184

146-
ENVTEST = $(shell pwd)/bin/setup-envtest
147-
envtest: ## Download envtest-setup locally if necessary.
148-
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
185+
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
186+
.PHONY: kustomize
187+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
188+
$(KUSTOMIZE): $(LOCALBIN)
189+
curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN)
149190

150-
# go-get-tool will 'go get' any package $2 and install it to $1.
151-
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
152-
define go-get-tool
153-
@[ -f $(1) ] || { \
154-
set -e ;\
155-
TMP_DIR=$$(mktemp -d) ;\
156-
cd $$TMP_DIR ;\
157-
go mod init tmp ;\
158-
echo "Downloading $(2)" ;\
159-
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
160-
rm -rf $$TMP_DIR ;\
161-
}
162-
endef
191+
.PHONY: envtest
192+
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
193+
$(ENVTEST): $(LOCALBIN)
194+
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
163195

164196
.PHONY: bundle
165197
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
166-
operator-sdk generate kustomize manifests -q
198+
operator-sdk generate kustomize manifests --interactive=false -q
167199
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
168-
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
200+
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS)
169201
operator-sdk bundle validate ./bundle
170202

171203
.PHONY: bundle-build
@@ -185,7 +217,7 @@ ifeq (,$(shell which opm 2>/dev/null))
185217
set -e ;\
186218
mkdir -p $(dir $(OPM)) ;\
187219
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
188-
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$${OS}-$${ARCH}-opm ;\
220+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\
189221
chmod +x $(OPM) ;\
190222
}
191223
else
@@ -218,6 +250,7 @@ catalog-push: ## Push a catalog image.
218250
$(MAKE) docker-push IMG=$(CATALOG_IMG)
219251

220252
# Generate helm chart
253+
.PHONY: helmchart
221254
helmchart: kustomize helm
222255
mkdir -p ./charts/${OPERATOR_NAME}/templates
223256
mkdir -p ./charts/${OPERATOR_NAME}/crds
@@ -233,11 +266,12 @@ helmchart: kustomize helm
233266
echo {{ end }} >> ./charts/${OPERATOR_NAME}/templates/monitoring.coreos.com_v1_servicemonitor_${OPERATOR_NAME}-controller-manager-metrics-monitor.yaml
234267
$(HELM) lint ./charts/${OPERATOR_NAME}
235268

236-
helmchart-repo: helmchart
269+
.PHONY: helmchart-repo
237270
mkdir -p ${HELM_REPO_DEST}/${OPERATOR_NAME}
238271
$(HELM) package -d ${HELM_REPO_DEST}/${OPERATOR_NAME} ./charts/${OPERATOR_NAME}
239272
$(HELM) repo index --url ${CHART_REPO_URL} ${HELM_REPO_DEST}
240273

274+
.PHONY: helmchart-repo-push
241275
helmchart-repo-push: helmchart-repo
242276
git -C ${HELM_REPO_DEST} add .
243277
git -C ${HELM_REPO_DEST} status

config/crd/bases/redhatcop.redhat.io_patches.yaml

Lines changed: 14 additions & 23 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.9.0
87
creationTimestamp: null
98
name: patches.redhatcop.redhat.io
109
spec:
@@ -242,13 +241,12 @@ spec:
242241
description: "Condition contains details for one aspect of the current
243242
state of this API Resource. --- This struct is intended for direct
244243
use as an array at the field path .status.conditions. For example,
245-
type FooStatus struct{ // Represents the observations of a
246-
foo's current state. // Known .status.conditions.type are:
247-
\"Available\", \"Progressing\", and \"Degraded\" // +patchMergeKey=type
248-
\ // +patchStrategy=merge // +listType=map // +listMapKey=type
249-
\ Conditions []metav1.Condition `json:\"conditions,omitempty\"
250-
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`
251-
\n // other fields }"
244+
type FooStatus struct{ // Represents the observations of a foo's
245+
current state. // Known .status.conditions.type are: \"Available\",
246+
\"Progressing\", and \"Degraded\" // +patchMergeKey=type // +patchStrategy=merge
247+
// +listType=map // +listMapKey=type Conditions []metav1.Condition
248+
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
249+
protobuf:\"bytes,1,rep,name=conditions\"` \n // other fields }"
252250
properties:
253251
lastTransitionTime:
254252
description: lastTransitionTime is the last time the condition
@@ -316,14 +314,13 @@ spec:
316314
description: "Condition contains details for one aspect of the
317315
current state of this API Resource. --- This struct is intended
318316
for direct use as an array at the field path .status.conditions.
319-
\ For example, type FooStatus struct{ // Represents the
320-
observations of a foo's current state. // Known .status.conditions.type
321-
are: \"Available\", \"Progressing\", and \"Degraded\" //
322-
+patchMergeKey=type // +patchStrategy=merge // +listType=map
323-
\ // +listMapKey=type Conditions []metav1.Condition
324-
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
325-
protobuf:\"bytes,1,rep,name=conditions\"` \n // other
326-
fields }"
317+
\ For example, type FooStatus struct{ // Represents the observations
318+
of a foo's current state. // Known .status.conditions.type
319+
are: \"Available\", \"Progressing\", and \"Degraded\" // +patchMergeKey=type
320+
// +patchStrategy=merge // +listType=map // +listMapKey=type
321+
Conditions []metav1.Condition `json:\"conditions,omitempty\"
322+
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`
323+
\n // other fields }"
327324
properties:
328325
lastTransitionTime:
329326
description: lastTransitionTime is the last time the condition
@@ -393,9 +390,3 @@ spec:
393390
storage: true
394391
subresources:
395392
status: {}
396-
status:
397-
acceptedNames:
398-
kind: ""
399-
plural: ""
400-
conditions: []
401-
storedVersions: []

config/default/manager_auth_proxy_patch.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,19 @@ spec:
1515
- "--secure-listen-address=0.0.0.0:8443"
1616
- "--upstream=http://127.0.0.1:8080/"
1717
- "--logtostderr=true"
18-
- "--v=10"
18+
- "--v=0"
1919
- "--tls-cert-file=/etc/certs/tls/tls.crt"
2020
- "--tls-private-key-file=/etc/certs/tls/tls.key"
2121
volumeMounts:
2222
- mountPath: /etc/certs/tls
23-
name: tls-cert
23+
name: tls-cert
24+
resources:
25+
limits:
26+
cpu: 500m
27+
memory: 128Mi
28+
requests:
29+
cpu: 5m
30+
memory: 64Mi
2431
ports:
2532
- containerPort: 8443
2633
name: https

config/helmchart/templates/manager.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ spec:
3232
- --logtostderr=true
3333
- --tls-cert-file=/etc/certs/tls/tls.crt
3434
- --tls-private-key-file=/etc/certs/tls/tls.key
35-
- --v=10
35+
- --v=0
3636
image: "{{ .Values.kube_rbac_proxy.image.repository }}:{{ .Values.kube_rbac_proxy.image.tag }}"
3737
name: kube-rbac-proxy
3838
ports:

config/helmchart/values.yaml.tpl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ kube_rbac_proxy:
3333
pullPolicy: IfNotPresent
3434
tag: v0.11.0
3535
resources:
36+
limits:
37+
cpu: 500m
38+
memory: 128Mi
3639
requests:
37-
cpu: 100m
38-
memory: 20Mi
40+
cpu: 5m
41+
memory: 64Mi
3942

4043
enableMonitoring: true
4144
enableCertManager: false

config/rbac/role.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
---
32
apiVersion: rbac.authorization.k8s.io/v1
43
kind: ClusterRole
@@ -27,12 +26,9 @@ rules:
2726
- apiGroups:
2827
- ""
2928
resources:
30-
- secrets
31-
- serviceaccounts
29+
- serviceaccounts/token
3230
verbs:
33-
- get
34-
- list
35-
- watch
31+
- create
3632
- apiGroups:
3733
- '*'
3834
resources:

config/webhook/manifests.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
---
32
apiVersion: admissionregistration.k8s.io/v1
43
kind: MutatingWebhookConfiguration
@@ -25,7 +24,6 @@ webhooks:
2524
resources:
2625
- patches
2726
sideEffects: None
28-
2927
---
3028
apiVersion: admissionregistration.k8s.io/v1
3129
kind: ValidatingWebhookConfiguration

0 commit comments

Comments
 (0)