Skip to content

Commit 01499a9

Browse files
committed
Bump operator-sdk for metalk8s-operator to v1.38.0
1 parent ab9284b commit 01499a9

23 files changed

+292
-177
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
[1.17.1](https://github.com/cert-manager/cert-manager/releases/tag/v1.17.1)
4343
(PR[#4579](https://github.com/scality/metalk8s/pull/4579))
4444

45+
- Bump Operator-SDK used by `metalk8s-operator` to
46+
[1.38.0](https://github.com/operator-framework/operator-sdk/releases/tag/v1.38.0)
47+
The Go version has been bumped accordingly to
48+
[1.22](https://golang.org/doc/devel/release.html#go1.22.minor)
49+
(PR[#4581](https://github.com/scality/metalk8s/pull/4581))
50+
4551
## Release 129.0.3 (in development)
4652

4753
### Enhancements

operator/.golangci.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ linters:
2121
enable:
2222
- dupl
2323
- errcheck
24-
- exportloopref
24+
- ginkgolinter
2525
- goconst
2626
- gocyclo
2727
- gofmt
@@ -33,8 +33,14 @@ linters:
3333
- misspell
3434
- nakedret
3535
- prealloc
36+
- revive
3637
- staticcheck
3738
- typecheck
3839
- unconvert
3940
- unparam
4041
- unused
42+
43+
linters-settings:
44+
revive:
45+
rules:
46+
- name: comment-spacings

operator/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.21 as builder
2+
FROM golang:1.22 as builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

operator/Makefile

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ OPERATOR_SDK_VERSION ?= v1.37.0
5353
# Image URL to use all building/pushing image targets
5454
IMG ?= controller:latest
5555
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
56-
ENVTEST_K8S_VERSION = 1.29.0
56+
ENVTEST_K8S_VERSION = 1.30.0
5757

5858
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
5959
ifeq (,$(shell go env GOBIN))
@@ -203,16 +203,16 @@ $(LOCALBIN):
203203

204204
## Tool Binaries
205205
KUBECTL ?= kubectl
206-
KUSTOMIZE ?= $(LOCALBIN)/kustomize-$(KUSTOMIZE_VERSION)
207-
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
208-
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
209-
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
206+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
207+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
208+
ENVTEST ?= $(LOCALBIN)/setup-envtest
209+
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
210210

211211
## Tool Versions
212-
KUSTOMIZE_VERSION ?= v5.3.0
213-
CONTROLLER_TOOLS_VERSION ?= v0.14.0
214-
ENVTEST_VERSION ?= release-0.17
215-
GOLANGCI_LINT_VERSION ?= v1.57.2
212+
KUSTOMIZE_VERSION ?= v5.4.2
213+
CONTROLLER_TOOLS_VERSION ?= v0.15.0
214+
ENVTEST_VERSION ?= release-0.18
215+
GOLANGCI_LINT_VERSION ?= v1.59.1
216216

217217
.PHONY: kustomize
218218
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -232,20 +232,22 @@ $(ENVTEST): $(LOCALBIN)
232232
.PHONY: golangci-lint
233233
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
234234
$(GOLANGCI_LINT): $(LOCALBIN)
235-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,${GOLANGCI_LINT_VERSION})
235+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
236236

237237
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
238238
# $1 - target path with name of binary (ideally with version)
239239
# $2 - package url which can be installed
240240
# $3 - specific version of package
241241
define go-install-tool
242-
@[ -f $(1) ] || { \
242+
@[ -f "$(1)-$(3)" ] || { \
243243
set -e; \
244244
package=$(2)@$(3) ;\
245245
echo "Downloading $${package}" ;\
246+
rm -f $(1) || true ;\
246247
GOBIN=$(LOCALBIN) go install $${package} ;\
247-
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
248-
}
248+
mv $(1) $(1)-$(3) ;\
249+
} ;\
250+
ln -sf $(1)-$(3) $(1)
249251
endef
250252

251253
.PHONY: operator-sdk

operator/cmd/main.go

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
ctrl "sigs.k8s.io/controller-runtime"
3232
"sigs.k8s.io/controller-runtime/pkg/healthz"
3333
"sigs.k8s.io/controller-runtime/pkg/log/zap"
34+
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
3435
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3536

3637
metalk8sscalitycomv1alpha1 "github.com/scality/metalk8s/operator/api/v1alpha1"
@@ -56,13 +57,15 @@ func main() {
5657
var probeAddr string
5758
var secureMetrics bool
5859
var enableHTTP2 bool
59-
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
60+
var tlsOpts []func(*tls.Config)
61+
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metric endpoint binds to. "+
62+
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
6063
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
6164
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
6265
"Enable leader election for controller manager. "+
6366
"Enabling this will ensure there is only one active controller manager.")
64-
flag.BoolVar(&secureMetrics, "metrics-secure", false,
65-
"If set the metrics endpoint is served securely")
67+
flag.BoolVar(&secureMetrics, "metrics-secure", true,
68+
"If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead.")
6669
flag.BoolVar(&enableHTTP2, "enable-http2", false,
6770
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
6871
opts := zap.Options{
@@ -84,18 +87,37 @@ func main() {
8487
c.NextProtos = []string{"http/1.1"}
8588
}
8689

87-
tlsOpts := []func(*tls.Config){}
8890
if !enableHTTP2 {
8991
tlsOpts = append(tlsOpts, disableHTTP2)
9092
}
9193

94+
// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
95+
// More info:
96+
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.18.4/pkg/metrics/server
97+
// - https://book.kubebuilder.io/reference/metrics.html
98+
metricsServerOptions := metricsserver.Options{
99+
BindAddress: metricsAddr,
100+
SecureServing: secureMetrics,
101+
// TODO(user): TLSOpts is used to allow configuring the TLS config used for the server. If certificates are
102+
// not provided, self-signed certificates will be generated by default. This option is not recommended for
103+
// production environments as self-signed certificates do not offer the same level of trust and security
104+
// as certificates issued by a trusted Certificate Authority (CA). The primary risk is potentially allowing
105+
// unauthorized access to sensitive metrics data. Consider replacing with CertDir, CertName, and KeyName
106+
// to provide certificates, ensuring the server communicates using trusted and secure certificates.
107+
TLSOpts: tlsOpts,
108+
}
109+
110+
if secureMetrics {
111+
// FilterProvider is used to protect the metrics endpoint with authn/authz.
112+
// These configurations ensure that only authorized users and service accounts
113+
// can access the metrics endpoint. The RBAC are configured in 'config/rbac/kustomization.yaml'. More info:
114+
// https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.18.4/pkg/metrics/filters#WithAuthenticationAndAuthorization
115+
metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization
116+
}
117+
92118
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
93-
Scheme: scheme,
94-
Metrics: metricsserver.Options{
95-
BindAddress: metricsAddr,
96-
SecureServing: secureMetrics,
97-
TLSOpts: tlsOpts,
98-
},
119+
Scheme: scheme,
120+
Metrics: metricsServerOptions,
99121
HealthProbeBindAddress: probeAddr,
100122
LeaderElection: enableLeaderElection,
101123
LeaderElectionID: "02367e3e.metalk8s.scality.com",

operator/config/crd/bases/metalk8s.scality.com_clusterconfigs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.14.0
6+
controller-gen.kubebuilder.io/version: v0.15.0
77
name: clusterconfigs.metalk8s.scality.com
88
spec:
99
group: metalk8s.scality.com

operator/config/crd/bases/metalk8s.scality.com_virtualippools.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.14.0
6+
controller-gen.kubebuilder.io/version: v0.15.0
77
name: virtualippools.metalk8s.scality.com
88
spec:
99
group: metalk8s.scality.com

operator/config/default/kustomization.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ resources:
2525
#- ../certmanager
2626
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
2727
#- ../prometheus
28+
# [METRICS] Expose the controller manager metrics service.
29+
- metrics_service.yaml
2830

31+
# Uncomment the patches line if you enable Metrics, and/or are using webhooks and
2932
patches:
30-
# Protect the /metrics endpoint by putting it behind auth.
31-
# If you want your controller-manager to expose the /metrics
32-
# endpoint w/o any authn/z, please comment the following line.
33-
- path: manager_auth_proxy_patch.yaml
33+
# [METRICS] The following patch will enable the metrics endpoint using HTTPS and the port :8443.
34+
# More info: https://book.kubebuilder.io/reference/metrics
35+
- path: manager_metrics_patch.yaml
36+
target:
37+
kind: Deployment
3438

3539
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
3640
# crd/kustomization.yaml

operator/config/default/manager_auth_proxy_patch.yaml

Lines changed: 0 additions & 39 deletions
This file was deleted.

operator/config/default/manager_config_patch.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)