Skip to content

Commit 6e21e53

Browse files
committed
Upgrade to operator-sdk 1.41.1
Rescaffold the glance-operator to operator-sdk 1.41.1, which includes: - Reorganize project structure (pkg/ -> internal/) - Move webhook implementations to internal/webhook/v1beta1/ - Add new cmd/main.go entrypoint with updated controller initialization - Update RBAC, certmanager, and prometheus configurations - Enhance network policies for metrics and webhook traffic - Set glance as defaulting resource in PROJECT file - Remove auto-generated test suite scaffolding - Update build workflow and Dockerfile to version 1.41.1 This upgrade modernizes the operator structure and aligns with the latest operator-sdk best practices. Jira: OSPRH-21932 Depends-On: openstack-k8s-operators/openstack-operator#1683
1 parent 8793a0f commit 6e21e53

File tree

81 files changed

+1324
-563
lines changed

Some content is hidden

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

81 files changed

+1324
-563
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-glance-operator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
with:
1717
operator_name: glance
1818
go_version: 1.24.x
19-
operator_sdk_version: 1.31.0
19+
operator_sdk_version: 1.41.1
2020
secrets:
2121
IMAGENAMESPACE: ${{ secrets.IMAGENAMESPACE }}
2222
QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }}

Dockerfile

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

3030
# Build manager
31-
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
31+
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
3232

3333
RUN cp -r templates ${DEST_ROOT}/templates
3434

Makefile

Lines changed: 4 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/glance-operator:latest
@@ -152,7 +152,7 @@ test: manifests generate fmt vet envtest ginkgo ## Run tests.
152152

153153
.PHONY: build
154154
build: generate fmt vet ## Build manager binary.
155-
go build -o bin/manager main.go
155+
go build -o bin/manager cmd/main.go
156156

157157
.PHONY: run
158158
run: export METRICS_PORT?=8080
@@ -162,7 +162,7 @@ run: export ENABLE_WEBHOOKS?=false
162162
run: export OPERATOR_TEMPLATES=./templates/
163163
run: manifests generate fmt vet ## Run a controller from your host.
164164
/bin/bash hack/clean_local_webhook.sh
165-
go run ./main.go -metrics-bind-address ":$(METRICS_PORT)" -health-probe-bind-address ":$(HEALTH_PORT)" -pprof-bind-address ":$(PPROF_PORT)"
165+
go run ./cmd/main.go -metrics-bind-address ":$(METRICS_PORT)" -health-probe-bind-address ":$(HEALTH_PORT)" -pprof-bind-address ":$(PPROF_PORT)"
166166

167167
.PHONY: docker-build
168168
docker-build: test ## Build docker image with the manager.
@@ -228,7 +228,7 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
228228
ENVTEST ?= $(LOCALBIN)/setup-envtest
229229

230230
## Tool Versions
231-
KUSTOMIZE_VERSION ?= v3.8.7
231+
KUSTOMIZE_VERSION ?= v5.6.0
232232
CONTROLLER_TOOLS_VERSION ?= v0.18.0
233233
GOTOOLCHAIN_VERSION ?= go1.24.0
234234

PROJECT

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
15
domain: openstack.org
26
layout:
3-
- go.kubebuilder.io/v3
7+
- go.kubebuilder.io/v4
48
plugins:
59
manifests.sdk.operatorframework.io/v2: {}
610
scorecard.sdk.operatorframework.io/v2: {}
@@ -30,6 +34,7 @@ resources:
3034
path: github.com/openstack-k8s-operators/glance-operator/api/v1beta1
3135
version: v1beta1
3236
webhooks:
37+
defaulting: true
3338
validation: true
3439
webhookVersion: v1
3540
version: "3"

api/v1beta1/glance_webhook.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"k8s.io/apimachinery/pkg/runtime"
2727
"k8s.io/apimachinery/pkg/runtime/schema"
2828
"k8s.io/apimachinery/pkg/util/validation/field"
29-
ctrl "sigs.k8s.io/controller-runtime"
3029
logf "sigs.k8s.io/controller-runtime/pkg/log"
3130
"sigs.k8s.io/controller-runtime/pkg/webhook"
3231
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
@@ -56,15 +55,11 @@ func SetupGlanceDefaults(defaults GlanceDefaults) {
5655
glancelog.Info("Glance defaults initialized", "defaults", defaults)
5756
}
5857

59-
// SetupWebhookWithManager sets up the webhook with the Manager
60-
func (r *Glance) SetupWebhookWithManager(mgr ctrl.Manager) error {
61-
return ctrl.NewWebhookManagedBy(mgr).
62-
For(r).
63-
Complete()
58+
// GetGlanceDefaults -
59+
func GetGlanceDefaults() GlanceDefaults {
60+
return glanceDefaults
6461
}
6562

66-
//+kubebuilder:webhook:path=/mutate-glance-openstack-org-v1beta1-glance,mutating=true,failurePolicy=fail,sideEffects=None,groups=glance.openstack.org,resources=glances,verbs=create;update,versions=v1beta1,name=mglance.kb.io,admissionReviewVersions=v1
67-
6863
var _ webhook.Defaulter = &Glance{}
6964

7065
// Default implements webhook.Defaulter so a webhook will be registered for the type
@@ -164,7 +159,6 @@ func (r *GlanceSpecCore) Default() {
164159
}
165160
}
166161

167-
//+kubebuilder:webhook:path=/validate-glance-openstack-org-v1beta1-glance,mutating=false,failurePolicy=fail,sideEffects=None,groups=glance.openstack.org,resources=glances,verbs=create;update,versions=v1beta1,name=vglance.kb.io,admissionReviewVersions=v1
168162

169163
// Check if File is used as a backend for Glance
170164
func isFileBackend(customServiceConfig string, topLevel bool) bool {

api/v1beta1/glanceapi_webhook.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package v1beta1
1818

1919
import (
2020
"k8s.io/apimachinery/pkg/runtime"
21-
ctrl "sigs.k8s.io/controller-runtime"
2221
logf "sigs.k8s.io/controller-runtime/pkg/log"
2322
"sigs.k8s.io/controller-runtime/pkg/webhook"
2423
"fmt"
@@ -43,15 +42,6 @@ func SetupGlanceAPIDefaults(defaults GlanceAPIDefaults) {
4342
glanceapilog.Info("Glance defaults initialized", "defaults", defaults)
4443
}
4544

46-
// SetupWebhookWithManager sets up the webhook with the Manager
47-
func (r *GlanceAPI) SetupWebhookWithManager(mgr ctrl.Manager) error {
48-
return ctrl.NewWebhookManagedBy(mgr).
49-
For(r).
50-
Complete()
51-
}
52-
53-
//+kubebuilder:webhook:path=/mutate-glance-openstack-org-v1beta1-glanceapi,mutating=true,failurePolicy=fail,sideEffects=None,groups=glance.openstack.org,resources=glanceapis,verbs=create;update,versions=v1beta1,name=mglanceapi.kb.io,admissionReviewVersions=v1
54-
5545
var _ webhook.Defaulter = &GlanceAPI{}
5646

5747
// Default implements webhook.Defaulter so a webhook will be registered for the type
@@ -68,8 +58,6 @@ func (spec *GlanceAPISpec) Default() {
6858
}
6959
}
7060

71-
//+kubebuilder:webhook:path=/validate-glance-openstack-org-v1beta1-glanceapi,mutating=false,failurePolicy=fail,sideEffects=None,groups=glance.openstack.org,resources=glanceapis,verbs=create;update,versions=v1beta1,name=vglanceapi.kb.io,admissionReviewVersions=v1
72-
7361
var _ webhook.Validator = &GlanceAPI{}
7462

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

0 commit comments

Comments
 (0)