Skip to content

Commit a25a9d5

Browse files
committed
Upgrade to operator-sdk 1.41.1
Rescaffold the keystone-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 keystone 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-21924 Depends-On: openstack-k8s-operators/openstack-operator#1683
1 parent 9106e1a commit a25a9d5

File tree

155 files changed

+1236
-691
lines changed

Some content is hidden

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

155 files changed

+1236
-691
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-keystone-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: keystone
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
@@ -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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ endif
4848

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

5353
# Image URL to use all building/pushing image targets
5454
DEFAULT_IMG ?= quay.io/openstack-k8s-operators/keystone-operator:latest
@@ -129,13 +129,13 @@ PROC_CMD = --procs ${PROCS}
129129

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

134134
##@ Build
135135

136136
.PHONY: build
137137
build: generate fmt vet ## Build manager binary.
138-
go build -o bin/manager main.go
138+
go build -o bin/manager cmd/main.go
139139

140140
.PHONY: run
141141
run: export METRICS_PORT?=8080
@@ -144,7 +144,7 @@ run: export PPROF_PORT?=8082
144144
run: export ENABLE_WEBHOOKS?=false
145145
run: manifests generate fmt vet ## Run a controller from your host.
146146
/bin/bash hack/clean_local_webhook.sh
147-
go run ./main.go -metrics-bind-address ":$(METRICS_PORT)" -health-probe-bind-address ":$(HEALTH_PORT)" -pprof-bind-address ":$(PPROF_PORT)"
147+
go run ./cmd/main.go -metrics-bind-address ":$(METRICS_PORT)" -health-probe-bind-address ":$(HEALTH_PORT)" -pprof-bind-address ":$(PPROF_PORT)"
148148

149149
.PHONY: docker-build
150150
docker-build: test ## Build docker image with the manager.
@@ -208,7 +208,7 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest
208208
GINKGO ?= $(LOCALBIN)/ginkgo
209209

210210
## Tool Versions
211-
KUSTOMIZE_VERSION ?= v3.8.7
211+
KUSTOMIZE_VERSION ?= v5.6.0
212212
CONTROLLER_TOOLS_VERSION ?= v0.18.0
213213
GOTOOLCHAIN_VERSION ?= go1.24.0
214214

PROJECT

Lines changed: 5 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: {}

api/bases/keystone.openstack.org_keystoneapis.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ spec:
5050
metadata:
5151
type: object
5252
spec:
53+
description: KeystoneAPISpec defines the desired state of KeystoneAPI
5354
properties:
5455
adminProject:
5556
default: admin
@@ -102,7 +103,7 @@ spec:
102103
description: ExtraMounts containing conf files
103104
items:
104105
description: |-
105-
KeystoneExtraVolMounts exposes additional parameters processed by keystone-operator
106+
KeystoneExtraMounts exposes additional parameters processed by keystone-operator
106107
and defines the common VolMounts structure provided by the main storage module
107108
properties:
108109
extraVol:

api/v1beta1/keystoneapi_types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const (
5353
APIDefaultTimeout = 60
5454
)
5555

56+
// KeystoneAPISpec defines the desired state of KeystoneAPI
5657
type KeystoneAPISpec struct {
5758
KeystoneAPISpecCore `json:",inline"`
5859

@@ -61,7 +62,7 @@ type KeystoneAPISpec struct {
6162
ContainerImage string `json:"containerImage"`
6263
}
6364

64-
// KeystoneAPISpec defines the desired state of KeystoneAPI
65+
// KeystoneAPISpecCore defines the desired state of KeystoneAPI core spec
6566
type KeystoneAPISpecCore struct {
6667
// +kubebuilder:validation:Required
6768
// MariaDB instance name
@@ -348,7 +349,7 @@ func SetupDefaults() {
348349
SetupKeystoneAPIDefaults(keystoneDefaults)
349350
}
350351

351-
// KeystoneExtraVolMounts exposes additional parameters processed by keystone-operator
352+
// KeystoneExtraMounts exposes additional parameters processed by keystone-operator
352353
// and defines the common VolMounts structure provided by the main storage module
353354
type KeystoneExtraMounts struct {
354355
// +kubebuilder:validation:Optional

api/v1beta1/keystoneapi_webhook.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
apierrors "k8s.io/apimachinery/pkg/api/errors"
3030
"k8s.io/apimachinery/pkg/runtime"
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"
@@ -53,15 +52,6 @@ func SetupKeystoneAPIDefaults(defaults KeystoneAPIDefaults) {
5352
keystoneapilog.Info("KeystoneAPI defaults initialized", "defaults", defaults)
5453
}
5554

56-
// SetupWebhookWithManager sets up the webhook with the Manager
57-
func (r *KeystoneAPI) SetupWebhookWithManager(mgr ctrl.Manager) error {
58-
return ctrl.NewWebhookManagedBy(mgr).
59-
For(r).
60-
Complete()
61-
}
62-
63-
//+kubebuilder:webhook:path=/mutate-keystone-openstack-org-v1beta1-keystoneapi,mutating=true,failurePolicy=fail,sideEffects=None,groups=keystone.openstack.org,resources=keystoneapis,verbs=create;update,versions=v1beta1,name=mkeystoneapi.kb.io,admissionReviewVersions=v1
64-
6555
var _ webhook.Defaulter = &KeystoneAPI{}
6656

6757
// Default implements webhook.Defaulter so a webhook will be registered for the type
@@ -88,9 +78,6 @@ func (spec *KeystoneAPISpecCore) Default() {
8878
}
8979
}
9080

91-
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
92-
//+kubebuilder:webhook:path=/validate-keystone-openstack-org-v1beta1-keystoneapi,mutating=false,failurePolicy=fail,sideEffects=None,groups=keystone.openstack.org,resources=keystoneapis,verbs=create;update,versions=v1beta1,name=vkeystoneapi.kb.io,admissionReviewVersions=v1
93-
9481
var _ webhook.Validator = &KeystoneAPI{}
9582

9683
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
@@ -117,6 +104,7 @@ func (spec *KeystoneAPISpec) ValidateCreate(basePath *field.Path, namespace stri
117104
return spec.KeystoneAPISpecCore.ValidateCreate(basePath, namespace)
118105
}
119106

107+
// ValidateCreate validates the KeystoneAPISpecCore spec during creation
120108
func (spec *KeystoneAPISpecCore) ValidateCreate(basePath *field.Path, namespace string) field.ErrorList {
121109
var allErrs field.ErrorList
122110

@@ -159,6 +147,7 @@ func (spec *KeystoneAPISpec) ValidateUpdate(old KeystoneAPISpec, basePath *field
159147
return spec.KeystoneAPISpecCore.ValidateUpdate(old.KeystoneAPISpecCore, basePath, namespace)
160148
}
161149

150+
// ValidateUpdate validates the KeystoneAPISpecCore spec during update
162151
func (spec *KeystoneAPISpecCore) ValidateUpdate(_ KeystoneAPISpecCore, basePath *field.Path, namespace string) field.ErrorList {
163152
var allErrs field.ErrorList
164153

0 commit comments

Comments
 (0)