Skip to content

Commit d5e4520

Browse files
stuggiclaude
andcommitted
[b/r] Use pointer for BackupLabelingPolicy to fix CRD defaulting
Change Labeling field from BackupLabelingPolicy to *BackupLabelingPolicy with omitempty. This fixes OpenStackBackupConfig creation failing with "Unsupported value" because the Go zero value "" was serialized and rejected by the enum validation. With a pointer: - Go zero value is nil, omitted from JSON via omitempty - CRD parent struct defaults apply server-side (labeling: enabled) - Controller treats nil as enabled (only explicit "disabled" disables) - Removes field-level +kubebuilder:default to satisfy operator-lint C003 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2bb639e commit d5e4520

7 files changed

Lines changed: 16 additions & 20 deletions

File tree

api/backup/v1beta1/openstackbackupconfig_types.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ type OpenStackBackupConfigSpec struct {
7070
type ResourceBackupConfig struct {
7171
// Labeling controls whether to label this resource type for backup
7272
// +kubebuilder:validation:Optional
73-
// +kubebuilder:default=enabled
74-
Labeling BackupLabelingPolicy `json:"labeling"`
73+
Labeling *BackupLabelingPolicy `json:"labeling,omitempty"`
7574

7675
// RestoreOrder overrides the default restore order for this resource type.
7776
// If empty, the global DefaultRestoreOrder is used.

api/backup/v1beta1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/bases/backup.openstack.org_openstackbackupconfigs.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ spec:
9696
Only resources matching this selector will be labeled (in addition to ownerRef check)
9797
type: object
9898
labeling:
99-
default: enabled
10099
description: Labeling controls whether to label this resource
101100
type for backup
102101
enum:
@@ -148,7 +147,6 @@ spec:
148147
Only resources matching this selector will be labeled (in addition to ownerRef check)
149148
type: object
150149
labeling:
151-
default: enabled
152150
description: Labeling controls whether to label this resource
153151
type for backup
154152
enum:
@@ -189,7 +187,6 @@ spec:
189187
Only resources matching this selector will be labeled (in addition to ownerRef check)
190188
type: object
191189
labeling:
192-
default: enabled
193190
description: Labeling controls whether to label this resource
194191
type for backup
195192
enum:
@@ -229,7 +226,6 @@ spec:
229226
Only resources matching this selector will be labeled (in addition to ownerRef check)
230227
type: object
231228
labeling:
232-
default: enabled
233229
description: Labeling controls whether to label this resource
234230
type for backup
235231
enum:

bindata/crds/crds.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ spec:
9595
Only resources matching this selector will be labeled (in addition to ownerRef check)
9696
type: object
9797
labeling:
98-
default: enabled
9998
description: Labeling controls whether to label this resource
10099
type for backup
101100
enum:
@@ -147,7 +146,6 @@ spec:
147146
Only resources matching this selector will be labeled (in addition to ownerRef check)
148147
type: object
149148
labeling:
150-
default: enabled
151149
description: Labeling controls whether to label this resource
152150
type for backup
153151
enum:
@@ -188,7 +186,6 @@ spec:
188186
Only resources matching this selector will be labeled (in addition to ownerRef check)
189187
type: object
190188
labeling:
191-
default: enabled
192189
description: Labeling controls whether to label this resource
193190
type for backup
194191
enum:
@@ -228,7 +225,6 @@ spec:
228225
Only resources matching this selector will be labeled (in addition to ownerRef check)
229226
type: object
230227
labeling:
231-
default: enabled
232228
description: Labeling controls whether to label this resource
233229
type for backup
234230
enum:

config/crd/bases/backup.openstack.org_openstackbackupconfigs.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ spec:
9696
Only resources matching this selector will be labeled (in addition to ownerRef check)
9797
type: object
9898
labeling:
99-
default: enabled
10099
description: Labeling controls whether to label this resource
101100
type for backup
102101
enum:
@@ -148,7 +147,6 @@ spec:
148147
Only resources matching this selector will be labeled (in addition to ownerRef check)
149148
type: object
150149
labeling:
151-
default: enabled
152150
description: Labeling controls whether to label this resource
153151
type for backup
154152
enum:
@@ -189,7 +187,6 @@ spec:
189187
Only resources matching this selector will be labeled (in addition to ownerRef check)
190188
type: object
191189
labeling:
192-
default: enabled
193190
description: Labeling controls whether to label this resource
194191
type for backup
195192
enum:
@@ -229,7 +226,6 @@ spec:
229226
Only resources matching this selector will be labeled (in addition to ownerRef check)
230227
type: object
231228
labeling:
232-
default: enabled
233229
description: Labeling controls whether to label this resource
234230
type for backup
235231
enum:

internal/controller/backup/openstackbackupconfig_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ func (r *OpenStackBackupConfigReconciler) getGVKFromCRD(ctx context.Context, crd
8888

8989
// shouldLabelResource checks if a resource should be labeled based on ownerReferences and config
9090
func shouldLabelResource(obj client.Object, config backupv1beta1.ResourceBackupConfig) bool {
91-
// Check if labeling is enabled (empty string treated as enabled for backward compatibility)
92-
if config.Labeling == backupv1beta1.BackupLabelingDisabled {
91+
// Check if labeling is enabled (nil treated as enabled for backward compatibility)
92+
if config.Labeling != nil && *config.Labeling == backupv1beta1.BackupLabelingDisabled {
9393
return false
9494
}
9595

test/functional/ctlplane/openstackbackupconfig_controller_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ func OpenStackBackupConfigConditionGetter(name types.NamespacedName) condition.C
4646
return instance.Status.Conditions
4747
}
4848

49+
func backupLabelingPtr(p backupv1.BackupLabelingPolicy) *backupv1.BackupLabelingPolicy {
50+
return &p
51+
}
52+
4953
func CreateBackupConfig(name types.NamespacedName) *backupv1.OpenStackBackupConfig {
5054
backupConfig := &backupv1.OpenStackBackupConfig{
5155
ObjectMeta: metav1.ObjectMeta{
@@ -56,18 +60,18 @@ func CreateBackupConfig(name types.NamespacedName) *backupv1.OpenStackBackupConf
5660
// Kubebuilder defaults are only applied via webhooks.
5761
// Set them explicitly for envtest.
5862
Secrets: backupv1.ResourceBackupConfig{
59-
Labeling: backupv1.BackupLabelingEnabled,
63+
Labeling: backupLabelingPtr(backupv1.BackupLabelingEnabled),
6064
},
6165
ConfigMaps: backupv1.ResourceBackupConfig{
62-
Labeling: backupv1.BackupLabelingEnabled,
66+
Labeling: backupLabelingPtr(backupv1.BackupLabelingEnabled),
6367
ExcludeNames: []string{"kube-root-ca.crt", "openshift-service-ca.crt"},
6468
},
6569
Issuers: backupv1.ResourceBackupConfig{
66-
Labeling: backupv1.BackupLabelingEnabled,
70+
Labeling: backupLabelingPtr(backupv1.BackupLabelingEnabled),
6771
RestoreOrder: "20",
6872
},
6973
NetworkAttachmentDefinitions: backupv1.ResourceBackupConfig{
70-
Labeling: backupv1.BackupLabelingEnabled,
74+
Labeling: backupLabelingPtr(backupv1.BackupLabelingEnabled),
7175
},
7276
},
7377
}

0 commit comments

Comments
 (0)