Skip to content

Commit b9a662b

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 5029e38 commit b9a662b

File tree

82 files changed

+1295
-693
lines changed

Some content is hidden

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

82 files changed

+1295
-693
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

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: 5 additions & 4 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
@@ -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 & 3 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
@@ -53,15 +53,15 @@ require (
5353
github.com/prometheus/client_model v0.6.1 // indirect
5454
github.com/prometheus/common v0.55.0 // indirect
5555
github.com/prometheus/procfs v0.15.1 // indirect
56-
github.com/spf13/pflag v1.0.5 // indirect
56+
github.com/spf13/pflag v1.0.9 // indirect
5757
github.com/x448/float16 v0.8.4 // indirect
5858
go.uber.org/automaxprocs v1.6.0 // indirect
5959
go.yaml.in/yaml/v3 v3.0.4 // indirect
6060
golang.org/x/crypto v0.42.0 // indirect
6161
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
6262
golang.org/x/mod v0.27.0 // indirect
6363
golang.org/x/net v0.43.0 // indirect
64-
golang.org/x/oauth2 v0.23.0 // indirect
64+
golang.org/x/oauth2 v0.27.0 // indirect
6565
golang.org/x/sync v0.17.0 // indirect
6666
golang.org/x/sys v0.36.0 // indirect
6767
golang.org/x/term v0.35.0 // indirect

api/go.sum

Lines changed: 6 additions & 6 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=
@@ -171,8 +171,8 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL
171171
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
172172
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
173173
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=
174+
golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M=
175+
golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
176176
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
177177
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
178178
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

api/v1beta1/openstackbaremetalset_webhook.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ import (
4444
// to any particular webhook)
4545
var webhookClient goClient.Client
4646

47+
// SetupWebhookClient sets the webhook client for API webhook functions.
48+
// This allows internal webhooks to initialize the client before calling validation/default functions.
49+
func SetupWebhookClient(client goClient.Client) {
50+
webhookClient = client
51+
}
52+
4753
// log is for logging in this package.
4854
var openstackbaremetalsetlog = logf.Log.WithName("openstackbaremetalset-resource")
4955

@@ -58,8 +64,6 @@ func (r *OpenStackBaremetalSet) SetupWebhookWithManager(mgr ctrl.Manager) error
5864
Complete()
5965
}
6066

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
62-
6367
var _ webhook.Validator = &OpenStackBaremetalSet{}
6468

6569
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type

api/v1beta1/openstackprovisionserver_webhook.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"k8s.io/apimachinery/pkg/runtime"
3030
"k8s.io/apimachinery/pkg/types"
3131
"k8s.io/apimachinery/pkg/util/validation/field"
32-
ctrl "sigs.k8s.io/controller-runtime"
3332
logf "sigs.k8s.io/controller-runtime/pkg/log"
3433
"sigs.k8s.io/controller-runtime/pkg/webhook"
3534
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
@@ -46,19 +45,6 @@ func SetupOpenStackProvisionServerDefaults(defaults OpenStackProvisionServerDefa
4645
openstackprovisionserverlog.Info("OpenStackProvisionServer defaults initialized", "defaults", defaults)
4746
}
4847

49-
// SetupWebhookWithManager - register this webhook with the controller manager
50-
func (r *OpenStackProvisionServer) SetupWebhookWithManager(mgr ctrl.Manager) error {
51-
if webhookClient == nil {
52-
webhookClient = mgr.GetClient()
53-
}
54-
55-
return ctrl.NewWebhookManagedBy(mgr).
56-
For(r).
57-
Complete()
58-
}
59-
60-
//+kubebuilder:webhook:path=/validate-baremetal-openstack-org-v1beta1-openstackprovisionserver,mutating=false,failurePolicy=fail,sideEffects=None,groups=baremetal.openstack.org,resources=openstackprovisionservers,verbs=create;update,versions=v1beta1,name=vopenstackprovisionserver.kb.io,admissionReviewVersions=v1
61-
6248
var _ webhook.Validator = &OpenStackProvisionServer{}
6349

6450
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
@@ -109,8 +95,6 @@ func (r *OpenStackProvisionServer) ValidateDelete() (admission.Warnings, error)
10995
return nil, nil
11096
}
11197

112-
//+kubebuilder:webhook:path=/mutate-baremetal-openstack-org-v1beta1-openstackprovisionserver,mutating=true,failurePolicy=fail,sideEffects=None,groups=baremetal.openstack.org,resources=openstackprovisionservers,verbs=create;update,versions=v1beta1,name=mopenstackprovisionserver.kb.io,admissionReviewVersions=v1
113-
11498
var _ webhook.Defaulter = &OpenStackProvisionServer{}
11599

116100
// Default implements webhook.Defaulter so a webhook will be registered for the type

0 commit comments

Comments
 (0)