Skip to content

Commit e77d97f

Browse files
authored
Merge pull request #72 from lmilleri/v0.3.0
operator-sdk upgrade
2 parents 1c2837b + 63e629c commit e77d97f

26 files changed

+368
-273
lines changed

Makefile

Lines changed: 16 additions & 14 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.2.0
6+
VERSION ?= 0.3.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")
@@ -49,7 +49,7 @@ endif
4949
# Image URL to use all building/pushing image targets
5050
IMG ?= controller:latest
5151
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
52-
ENVTEST_K8S_VERSION = 1.29.0
52+
ENVTEST_K8S_VERSION = 1.31.0
5353

5454
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
5555
ifeq (,$(shell go env GOBIN))
@@ -191,17 +191,17 @@ $(LOCALBIN):
191191
mkdir -p $(LOCALBIN)
192192

193193
## Tool Versions
194-
KUSTOMIZE_VERSION ?= v5.3.0
195-
CONTROLLER_TOOLS_VERSION ?= v0.14.0
196-
ENVTEST_VERSION ?= release-0.17
197-
GOLANGCI_LINT_VERSION ?= v1.57.2
194+
KUSTOMIZE_VERSION ?= v5.4.3
195+
CONTROLLER_TOOLS_VERSION ?= v0.16.1
196+
ENVTEST_VERSION ?= release-0.19
197+
GOLANGCI_LINT_VERSION ?= v1.59.1
198198

199199
## Tool Binaries
200200
KUBECTL ?= kubectl
201-
KUSTOMIZE ?= $(LOCALBIN)/kustomize-$(KUSTOMIZE_VERSION)
202-
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
203-
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
204-
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
201+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
202+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
203+
ENVTEST ?= $(LOCALBIN)/setup-envtest
204+
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
205205

206206
.PHONY: kustomize
207207
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -221,20 +221,22 @@ $(ENVTEST): $(LOCALBIN)
221221
.PHONY: golangci-lint
222222
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
223223
$(GOLANGCI_LINT): $(LOCALBIN)
224-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,${GOLANGCI_LINT_VERSION})
224+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
225225

226226
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
227227
# $1 - target path with name of binary (ideally with version)
228228
# $2 - package url which can be installed
229229
# $3 - specific version of package
230230
define go-install-tool
231-
@[ -f $(1) ] || { \
231+
@[ -f "$(1)-$(3)" ] || { \
232232
set -e; \
233233
package=$(2)@$(3) ;\
234234
echo "Downloading $${package}" ;\
235+
rm -f $(1) || true ;\
235236
GOBIN=$(LOCALBIN) go install $${package} ;\
236-
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
237-
}
237+
mv $(1) $(1)-$(3) ;\
238+
} ;\
239+
ln -sf $(1)-$(3) $(1)
238240
endef
239241

240242
.PHONY: bundle

bundle/manifests/trustee-operator.clusterserviceversion.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ metadata:
1111
operators.operatorframework.io/builder: operator-sdk-v1.36.1
1212
operators.operatorframework.io/project_layout: go.kubebuilder.io/v4
1313
support: Confidential Containers Community
14-
name: trustee-operator.v0.2.0
14+
name: trustee-operator.v0.3.0
1515
namespace: placeholder
1616
spec:
1717
apiservicedefinitions: {}
@@ -290,4 +290,4 @@ spec:
290290
provider:
291291
name: Confidential Containers Community
292292
url: https://github.com/confidential-containers
293-
version: 0.2.0
293+
version: 0.3.0

cmd/main.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package main
1818

1919
import (
2020
"context"
21+
"crypto/tls"
2122
"flag"
2223
"os"
2324

@@ -34,6 +35,7 @@ import (
3435
"sigs.k8s.io/controller-runtime/pkg/client"
3536
"sigs.k8s.io/controller-runtime/pkg/healthz"
3637
"sigs.k8s.io/controller-runtime/pkg/log/zap"
38+
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
3739
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3840

3941
confidentialcontainersorgv1alpha1 "github.com/confidential-containers/trustee-operator/api/v1alpha1"
@@ -56,13 +58,18 @@ func init() {
5658

5759
func main() {
5860
var metricsAddr string
61+
var secureMetrics bool
5962
var enableLeaderElection bool
6063
var probeAddr string
61-
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
64+
var tlsOpts []func(*tls.Config)
65+
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
66+
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
6267
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
6368
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
6469
"Enable leader election for controller manager. "+
6570
"Enabling this will ensure there is only one active controller manager.")
71+
flag.BoolVar(&secureMetrics, "metrics-secure", true,
72+
"If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead.")
6673
opts := zap.Options{
6774
Development: true,
6875
}
@@ -71,9 +78,33 @@ func main() {
7178

7279
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
7380

81+
// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
82+
// More info:
83+
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/metrics/server
84+
// - https://book.kubebuilder.io/reference/metrics.html
85+
metricsServerOptions := metricsserver.Options{
86+
BindAddress: metricsAddr,
87+
SecureServing: secureMetrics,
88+
// TODO(user): TLSOpts is used to allow configuring the TLS config used for the server. If certificates are
89+
// not provided, self-signed certificates will be generated by default. This option is not recommended for
90+
// production environments as self-signed certificates do not offer the same level of trust and security
91+
// as certificates issued by a trusted Certificate Authority (CA). The primary risk is potentially allowing
92+
// unauthorized access to sensitive metrics data. Consider replacing with CertDir, CertName, and KeyName
93+
// to provide certificates, ensuring the server communicates using trusted and secure certificates.
94+
TLSOpts: tlsOpts,
95+
}
96+
97+
if secureMetrics {
98+
// FilterProvider is used to protect the metrics endpoint with authn/authz.
99+
// These configurations ensure that only authorized users and service accounts
100+
// can access the metrics endpoint. The RBAC are configured in 'config/rbac/kustomization.yaml'. More info:
101+
// https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/metrics/filters#WithAuthenticationAndAuthorization
102+
metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization
103+
}
104+
74105
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
75106
Scheme: scheme,
76-
Metrics: metricsserver.Options{BindAddress: metricsAddr},
107+
Metrics: metricsServerOptions,
77108
HealthProbeBindAddress: probeAddr,
78109
LeaderElection: enableLeaderElection,
79110
LeaderElectionID: "178dc119.confidentialcontainers.org",

config/crd/bases/confidentialcontainers.org_kbsconfigs.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.16.1
77
name: kbsconfigs.confidentialcontainers.org
88
spec:
99
group: confidentialcontainers.org

config/default/kustomization.yaml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ bases:
2323
#- ../certmanager
2424
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
2525
#- ../prometheus
26+
# [METRICS] Expose the controller manager metrics service.
2627

27-
patchesStrategicMerge:
28-
# Protect the /metrics endpoint by putting it behind auth.
29-
# If you want your controller-manager to expose the /metrics
30-
# endpoint w/o any authn/z, please comment the following line.
31-
- manager_auth_proxy_patch.yaml
32-
28+
patches:
29+
# [METRICS] The following patch will enable the metrics endpoint using HTTPS and the port :8443.
30+
# More info: https://book.kubebuilder.io/reference/metrics
31+
- path: manager_metrics_patch.yaml
32+
target:
33+
kind: Deployment
3334

3435

3536
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
@@ -70,3 +71,9 @@ vars:
7071
# kind: Service
7172
# version: v1
7273
# name: webhook-service
74+
75+
# [NETWORK POLICY] Protect the /metrics endpoint and Webhook Server with NetworkPolicy.
76+
# Only Pod(s) running a namespace labeled with 'metrics: enabled' will be able to gather the metrics.
77+
# Only CR(s) which requires webhooks and are applied on namespaces labeled with 'webhooks: enabled' will
78+
# be able to communicate with the Webhook Server.
79+
#- ../network-policy

config/default/manager_auth_proxy_patch.yaml

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

config/default/manager_config_patch.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This patch adds the args to allow exposing the metrics endpoint using HTTPS
2+
- op: add
3+
path: /spec/template/spec/containers/0/args/0
4+
value: --metrics-bind-address=:8443
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
labels:
5+
control-plane: controller-manager
6+
app.kubernetes.io/name: trustee-operator
7+
app.kubernetes.io/managed-by: kustomize
8+
name: controller-manager-metrics-service
9+
namespace: system
10+
spec:
11+
ports:
12+
- name: https
13+
port: 8443
14+
protocol: TCP
15+
targetPort: 8443
16+
selector:
17+
control-plane: controller-manager

config/manager/manager.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ spec:
7373
- /manager
7474
args:
7575
- --leader-elect
76+
- --health-probe-bind-address=:8081
7677
image: controller:latest
7778
name: manager
7879
# Add the following environment variables to the manager container

0 commit comments

Comments
 (0)