Skip to content

Commit e447eed

Browse files
abaysComposer AI
andcommitted
[OSPRH-21931] Upgrade to Operator SDK 1.41.1
This commit migrates the openstack-baremetal-operator from Operator SDK 1.31.0 to 1.41.1, following the new project structure and best practices introduced in the newer SDK version. Major Changes: Project Structure Reorganization: - Moved entry point from root main.go to cmd/main.go - Migrated pkg/ directory to internal/ structure - Moved controllers from controllers/ to internal/controller/ - Created internal/webhook/v1beta1/ for webhook registration - Reorganized internal packages: openstackbaremetalset/ and openstackprovisionserver/ Webhook Architecture Updates: - Separated webhook registration (internal/webhook/v1beta1/) from webhook logic (api/v1beta1/*_webhook.go) - Removed kubebuilder:webhook annotations from API webhook files - Updated webhook setup to use internal webhook registration functions - Added SetupWebhookClient() function for proper client initialization - Updated test files to use new webhook structure Configuration Updates: - Cert-Manager: Split certificate.yaml into certificate-webhook.yaml and certificate-metrics.yaml, added issuer.yaml - Metrics: Added metrics_service.yaml, manager_metrics_patch.yaml, and cert_metrics_manager_patch.yaml - RBAC: Added metrics_auth_role.yaml, metrics_auth_role_binding.yaml, metrics_reader_role.yaml, and admin roles for CRs - Network Policies: Added allow-metrics-traffic.yaml and allow-webhook-traffic.yaml - Prometheus: Updated monitor.yaml and added monitor_tls_patch.yaml - Removed deprecated auth proxy configurations - Updated manager.yaml with new labels, security context, and resource limits Build System: - Updated Makefile for new project structure - Updated PROJECT file with new layout and plugin version - Updated Dockerfile to use new cmd/main.go entry point - Updated .ci-operator.yaml Test Updates: - Updated tests/functional/suit_test.go to use internal/webhook/v1beta1 - Updated test imports to use internal/controller instead of controllers Related: https://issues.redhat.com/browse/OSPRH-21931 Co-authored-by: Composer AI <[email protected]>
1 parent f40d7d5 commit e447eed

File tree

86 files changed

+1303
-791
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1303
-791
lines changed

.ci-operator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
build_root_image:
22
name: tools
33
namespace: openstack-k8s-operators
4-
tag: ci-build-root-golang-1.24-sdk-1.31
4+
tag: ci-build-root-golang-1.24-sdk-1.41.1

.github/workflows/build-openstack-baremetal-operator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
with:
2828
operator_name: openstack-baremetal
2929
go_version: 1.24.x
30-
operator_sdk_version: 1.31.0
30+
operator_sdk_version: 1.41.1
3131
secrets:
3232
IMAGENAMESPACE: ${{ secrets.IMAGENAMESPACE }}
3333
QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }}

.github/workflows/force-bump-pr-manual.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ jobs:
99
with:
1010
operator_name: openstack-baremetal
1111
branch_name: ${{ github.ref_name }}
12-
custom_image: quay.io/openstack-k8s-operators/openstack-k8s-operators-ci-build-tools:golang-1.24-sdk-1.31
12+
custom_image: quay.io/openstack-k8s-operators/openstack-k8s-operators-ci-build-tools:golang-1.24-sdk-1.41.1
1313
secrets:
1414
FORCE_BUMP_PULL_REQUEST_PAT: ${{ secrets.FORCE_BUMP_PULL_REQUEST_PAT }}

.github/workflows/force-bump-pr-scheduled.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ jobs:
1010
uses: openstack-k8s-operators/openstack-k8s-operators-ci/.github/workflows/force-bump-branches.yaml@main
1111
with:
1212
operator_name: openstack-baremetal
13-
custom_image: quay.io/openstack-k8s-operators/openstack-k8s-operators-ci-build-tools:golang-1.24-sdk-1.31
13+
custom_image: quay.io/openstack-k8s-operators/openstack-k8s-operators-ci-build-tools:golang-1.24-sdk-1.41.1
1414
secrets:
1515
FORCE_BUMP_PULL_REQUEST_PAT: ${{ secrets.FORCE_BUMP_PULL_REQUEST_PAT }}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ RUN mkdir -p ${DEST_ROOT}/usr/local/bin/
2626
RUN if [ ! -f $CACHITO_ENV_FILE ]; then go mod download ; fi
2727

2828
# Build manager
29-
RUN if [ -f $CACHITO_ENV_FILE ] ; then source $CACHITO_ENV_FILE ; fi ; env ${GO_BUILD_EXTRA_ENV_ARGS} go build ${GO_BUILD_EXTRA_ARGS} -a -o ${DEST_ROOT}/manager main.go
29+
RUN if [ -f $CACHITO_ENV_FILE ] ; then source $CACHITO_ENV_FILE ; fi ; env ${GO_BUILD_EXTRA_ENV_ARGS} go build ${GO_BUILD_EXTRA_ARGS} -a -o ${DEST_ROOT}/manager cmd/main.go
3030

3131
RUN cp -r templates ${DEST_ROOT}/templates
3232

Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ endif
5050

5151
# Set the Operator SDK version to use. By default, what is installed on the system is used.
5252
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
53-
OPERATOR_SDK_VERSION ?= v1.31.0
53+
OPERATOR_SDK_VERSION ?= v1.41.1
5454

5555
# Image URL to use all building/pushing image targets
5656
DEFAULT_IMG ?= quay.io/openstack-k8s-operators/openstack-baremetal-operator:latest
@@ -137,7 +137,7 @@ PROC_CMD = --procs $(PROCS)
137137

138138
.PHONY: test
139139
test: manifests generate fmt vet envtest ginkgo ## Run tests.
140-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" $(GINKGO) --trace --cover --coverpkg=../../pkg/...,../../controllers,../../api/v1beta1 --coverprofile cover.out --covermode=atomic ${PROC_CMD} $(GINKGO_ARGS) ./tests/...
140+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" $(GINKGO) --trace --cover --coverpkg=../../internal/...,../../api/v1beta1 --coverprofile cover.out --covermode=atomic ${PROC_CMD} $(GINKGO_ARGS) ./tests/...
141141

142142
.PHONY: cover
143143
cover: test ## Run tests and display functional test coverage
@@ -148,14 +148,14 @@ cover: test ## Run tests and display functional test coverage
148148

149149
.PHONY: build
150150
build: generate fmt vet ## Build manager binary.
151-
go build -o bin/manager main.go
151+
go build -o bin/manager cmd/main.go
152152

153153
.PHONY: run
154154
run: export METRICS_PORT?=8080
155155
run: export HEALTH_PORT?=8081
156156
run: export PPROF_PORT?=8082
157157
run: manifests generate fmt vet ## Run a controller from your host.
158-
go run ./main.go -metrics-bind-address ":$(METRICS_PORT)" -health-probe-bind-address ":$(HEALTH_PORT)" -pprof-bind-address ":$(PPROF_PORT)"
158+
go run ./cmd/main.go -metrics-bind-address ":$(METRICS_PORT)" -health-probe-bind-address ":$(HEALTH_PORT)" -pprof-bind-address ":$(PPROF_PORT)"
159159

160160
# If you wish built the manager image targeting other platforms you can use the --platform flag.
161161
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
@@ -225,7 +225,7 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest
225225
GINKGO ?= $(LOCALBIN)/ginkgo
226226

227227
## Tool Versions
228-
KUSTOMIZE_VERSION ?= v3.8.7
228+
KUSTOMIZE_VERSION ?= v5.6.0
229229
CONTROLLER_TOOLS_VERSION ?= v0.18.0
230230

231231
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
@@ -375,6 +375,7 @@ gowork: ## Generate go.work file to support our multi module repository
375375
test -f go.work || GOTOOLCHAIN=$(GOTOOLCHAIN_VERSION) go work init
376376
go work use .
377377
go work use ./api
378+
go work sync
378379

379380
.PHONY: tidy
380381
tidy: ## Run go mod tidy on every mod file in the repo

PROJECT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
domain: openstack.org
22
layout:
3-
- go.kubebuilder.io/v3
3+
- go.kubebuilder.io/v4
44
plugins:
55
manifests.sdk.operatorframework.io/v2: {}
66
scorecard.sdk.operatorframework.io/v2: {}

api/go.mod

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.24.4
55
require (
66
github.com/go-logr/logr v1.4.3
77
github.com/go-playground/validator/v10 v10.28.0
8-
github.com/metal3-io/baremetal-operator/apis v0.6.3
8+
github.com/metal3-io/baremetal-operator/apis v0.9.3
99
github.com/onsi/ginkgo/v2 v2.27.1
1010
github.com/onsi/gomega v1.38.2
1111
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251027074416-ab5c045dbe00
@@ -31,14 +31,12 @@ require (
3131
github.com/go-playground/universal-translator v0.18.1 // indirect
3232
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
3333
github.com/gogo/protobuf v1.3.2 // indirect
34-
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3534
github.com/golang/protobuf v1.5.4 // indirect
3635
github.com/google/gnostic-models v0.6.8 // indirect
3736
github.com/google/go-cmp v0.7.0 // indirect
3837
github.com/google/gofuzz v1.2.0 // indirect
3938
github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 // indirect
4039
github.com/google/uuid v1.6.0 // indirect
41-
github.com/imdario/mergo v0.3.16 // indirect
4240
github.com/josharian/intern v1.0.0 // indirect
4341
github.com/json-iterator/go v1.1.12 // indirect
4442
github.com/klauspost/compress v1.17.9 // indirect
@@ -53,15 +51,14 @@ require (
5351
github.com/prometheus/client_model v0.6.1 // indirect
5452
github.com/prometheus/common v0.55.0 // indirect
5553
github.com/prometheus/procfs v0.15.1 // indirect
56-
github.com/spf13/pflag v1.0.5 // indirect
54+
github.com/spf13/pflag v1.0.9 // indirect
5755
github.com/x448/float16 v0.8.4 // indirect
5856
go.uber.org/automaxprocs v1.6.0 // indirect
5957
go.yaml.in/yaml/v3 v3.0.4 // indirect
6058
golang.org/x/crypto v0.42.0 // indirect
61-
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
6259
golang.org/x/mod v0.27.0 // indirect
6360
golang.org/x/net v0.43.0 // indirect
64-
golang.org/x/oauth2 v0.23.0 // indirect
61+
golang.org/x/oauth2 v0.27.0 // indirect
6562
golang.org/x/sync v0.17.0 // indirect
6663
golang.org/x/sys v0.36.0 // indirect
6764
golang.org/x/term v0.35.0 // indirect
@@ -73,7 +70,6 @@ require (
7370
gopkg.in/inf.v0 v0.9.1 // indirect
7471
gopkg.in/yaml.v2 v2.4.0 // indirect
7572
gopkg.in/yaml.v3 v3.0.1 // indirect
76-
k8s.io/apiextensions-apiserver v0.31.13 // indirect
7773
k8s.io/client-go v0.31.13 // indirect
7874
k8s.io/klog/v2 v2.130.1 // indirect
7975
k8s.io/kube-openapi v0.0.0-20240903163716-9e1beecbcb38 // indirect

api/go.sum

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
9090
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
9191
github.com/maruel/natural v1.1.1 h1:Hja7XhhmvEFhcByqDoHz9QZbkWey+COd9xWfCfn1ioo=
9292
github.com/maruel/natural v1.1.1/go.mod h1:v+Rfd79xlw1AgVBjbO0BEQmptqb5HvL/k9GRHB7ZKEg=
93-
github.com/metal3-io/baremetal-operator/apis v0.6.3 h1:0HB0Nkz3PZFf1An9MxqyOfjgBztzihTSb4j3EPt8j88=
94-
github.com/metal3-io/baremetal-operator/apis v0.6.3/go.mod h1:G7ZbZqrASbIDpHXB2Zu3KaCNaRasnB/sOt6ewgDSrMA=
93+
github.com/metal3-io/baremetal-operator/apis v0.9.3 h1:4y2jg8r3JSaHYjPkf4KSrJSTxqAkv1ulkEtx5dJ0mGI=
94+
github.com/metal3-io/baremetal-operator/apis v0.9.3/go.mod h1:IPQkSeeggkANzF7jyTK3UDuPY+MubE8JbID5v4RVrT4=
9595
github.com/metal3-io/baremetal-operator/pkg/hardwareutils v0.5.1 h1:X0+MWsJ+Gj/TAkmhGybvesvxk6zQKu3NQXzvC6l0iJs=
9696
github.com/metal3-io/baremetal-operator/pkg/hardwareutils v0.5.1/go.mod h1:399nvdaqoU9rTI25UdFw2EWcVjmJPpeZPIhfDAIx/XU=
9797
github.com/mfridman/tparse v0.18.0 h1:wh6dzOKaIwkUGyKgOntDW4liXSo37qg5AXbIhkMV3vE=
@@ -126,8 +126,8 @@ github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0leargg
126126
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
127127
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
128128
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
129-
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
130-
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
129+
github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
130+
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
131131
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
132132
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
133133
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
@@ -146,8 +146,6 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
146146
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
147147
go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs=
148148
go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwEFJ8r8=
149-
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
150-
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
151149
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
152150
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
153151
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
@@ -171,8 +169,8 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL
171169
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
172170
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
173171
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
174-
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
175-
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
172+
golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M=
173+
golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
176174
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
177175
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
178176
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

api/v1beta1/openstackbaremetalset_webhook.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
"k8s.io/apimachinery/pkg/runtime"
3434
"k8s.io/apimachinery/pkg/runtime/schema"
3535
"k8s.io/apimachinery/pkg/util/validation/field"
36-
ctrl "sigs.k8s.io/controller-runtime"
3736
goClient "sigs.k8s.io/controller-runtime/pkg/client"
3837
logf "sigs.k8s.io/controller-runtime/pkg/log"
3938
"sigs.k8s.io/controller-runtime/pkg/webhook"
@@ -44,21 +43,14 @@ import (
4443
// to any particular webhook)
4544
var webhookClient goClient.Client
4645

47-
// log is for logging in this package.
48-
var openstackbaremetalsetlog = logf.Log.WithName("openstackbaremetalset-resource")
49-
50-
// SetupWebhookWithManager - register this webhook with the controller manager
51-
func (r *OpenStackBaremetalSet) SetupWebhookWithManager(mgr ctrl.Manager) error {
52-
if webhookClient == nil {
53-
webhookClient = mgr.GetClient()
54-
}
55-
56-
return ctrl.NewWebhookManagedBy(mgr).
57-
For(r).
58-
Complete()
46+
// SetupWebhookClient sets the webhook client for API webhook functions.
47+
// This allows internal webhooks to initialize the client before calling validation/default functions.
48+
func SetupWebhookClient(client goClient.Client) {
49+
webhookClient = client
5950
}
6051

61-
// +kubebuilder:webhook:verbs=create;update;delete,path=/validate-baremetal-openstack-org-v1beta1-openstackbaremetalset,mutating=false,failurePolicy=fail,sideEffects=None,groups=baremetal.openstack.org,resources=openstackbaremetalsets,versions=v1beta1,name=vopenstackbaremetalset.kb.io,admissionReviewVersions=v1
52+
// log is for logging in this package.
53+
var openstackbaremetalsetlog = logf.Log.WithName("openstackbaremetalset-resource")
6254

6355
var _ webhook.Validator = &OpenStackBaremetalSet{}
6456

0 commit comments

Comments
 (0)