Skip to content

Commit 84c7ea1

Browse files
(fix) Priority field to use pointer type with correct markers
Change ClusterCatalog Priority field from int32 to *int32 to properly represent an optional field with a default value. - Update Priority to *int32 with json:"priority,omitempty" - Fix kubebuilder markers: Minimum/Maximum capitalization - Add Format:=int32 marker for OpenAPI schema - Add GetPriority() helper method for safe nil handling - Update resolver to use GetPriority() instead of direct access - Update tests to use ptr.To[int32]() for pointer values The kubebuilder default marker ensures the API server sets Priority to 0 when omitted, while the pointer type allows proper detection of user-specified vs defaulted values. Assisted-by: CLAUDE
1 parent bd540c9 commit 84c7ea1

File tree

11 files changed

+38
-12
lines changed

11 files changed

+38
-12
lines changed

api/v1/clustercatalog_types.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,11 @@ type ClusterCatalogSpec struct {
125125
// The highest possible value is 2147483647.
126126
//
127127
// +kubebuilder:default:=0
128-
// +kubebuilder:validation:minimum:=-2147483648
129-
// +kubebuilder:validation:maximum:=2147483647
128+
// +kubebuilder:validation:Minimum:=-2147483648
129+
// +kubebuilder:validation:Maximum:=2147483647
130+
// +kubebuilder:validation:Format:=int32
130131
// +optional
131-
Priority int32 `json:"priority"`
132+
Priority *int32 `json:"priority,omitempty"`
132133

133134
// availabilityMode is an optional field that defines how the ClusterCatalog is made available to clients on the cluster.
134135
//
@@ -149,6 +150,14 @@ type ClusterCatalogSpec struct {
149150
AvailabilityMode AvailabilityMode `json:"availabilityMode,omitempty"`
150151
}
151152

153+
// GetPriority returns the priority value, defaulting to 0 if nil.
154+
func (c *ClusterCatalogSpec) GetPriority() int32 {
155+
if c.Priority == nil {
156+
return 0
157+
}
158+
return *c.Priority
159+
}
160+
152161
// ClusterCatalogStatus defines the observed state of ClusterCatalog
153162
type ClusterCatalogStatus struct {
154163
// conditions represents the current state of this ClusterCatalog.

api/v1/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.

docs/api-reference/olmv1-api-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ _Appears in:_
178178
| Field | Description | Default | Validation |
179179
| --- | --- | --- | --- |
180180
| `source` _[CatalogSource](#catalogsource)_ | source is a required field that defines the source of a catalog.<br />A catalog contains information on content that can be installed on a cluster.<br />The catalog source makes catalog contents discoverable and usable by other on-cluster components.<br />These components can present the content in a GUI dashboard or install content from the catalog on the cluster.<br />The catalog source must contain catalog metadata in the File-Based Catalog (FBC) format.<br />For more information on FBC, see https://olm.operatorframework.io/docs/reference/file-based-catalogs/#docs.<br />Below is a minimal example of a ClusterCatalogSpec that sources a catalog from an image:<br /> source:<br /> type: Image<br /> image:<br /> ref: quay.io/operatorhubio/catalog:latest | | Required: \{\} <br /> |
181-
| `priority` _integer_ | priority is an optional field that defines a priority for this ClusterCatalog.<br />Clients use the ClusterCatalog priority as a tie-breaker between ClusterCatalogs that meet their requirements.<br />Higher numbers mean higher priority.<br />Clients decide how to handle scenarios where multiple ClusterCatalogs with the same priority meet their requirements.<br />Clients should prompt users for additional input to break the tie.<br />When omitted, the default priority is 0.<br />Use negative numbers to specify a priority lower than the default.<br />Use positive numbers to specify a priority higher than the default.<br />The lowest possible value is -2147483648.<br />The highest possible value is 2147483647. | 0 | |
181+
| `priority` _integer_ | priority is an optional field that defines a priority for this ClusterCatalog.<br />Clients use the ClusterCatalog priority as a tie-breaker between ClusterCatalogs that meet their requirements.<br />Higher numbers mean higher priority.<br />Clients decide how to handle scenarios where multiple ClusterCatalogs with the same priority meet their requirements.<br />Clients should prompt users for additional input to break the tie.<br />When omitted, the default priority is 0.<br />Use negative numbers to specify a priority lower than the default.<br />Use positive numbers to specify a priority higher than the default.<br />The lowest possible value is -2147483648.<br />The highest possible value is 2147483647. | 0 | Format: int32 <br />Maximum: 2.147483647e+09 <br />Minimum: -2.147483648e+09 <br /> |
182182
| `availabilityMode` _[AvailabilityMode](#availabilitymode)_ | availabilityMode is an optional field that defines how the ClusterCatalog is made available to clients on the cluster.<br />Allowed values are "Available", "Unavailable", or omitted.<br />When omitted, the default value is "Available".<br />When set to "Available", the catalog contents are unpacked and served over the catalog content HTTP server.<br />Clients should consider this ClusterCatalog and its contents as usable.<br />When set to "Unavailable", the catalog contents are no longer served over the catalog content HTTP server.<br />Treat this the same as if the ClusterCatalog does not exist.<br />Use "Unavailable" when you want to keep the ClusterCatalog but treat it as if it doesn't exist. | Available | Enum: [Unavailable Available] <br /> |
183183

184184

helm/olmv1/base/catalogd/crd/experimental/olm.operatorframework.io_clustercatalogs.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ spec:
9292
The lowest possible value is -2147483648.
9393
The highest possible value is 2147483647.
9494
format: int32
95+
maximum: 2147483647
96+
minimum: -2147483648
9597
type: integer
9698
source:
9799
description: |-

helm/olmv1/base/catalogd/crd/standard/olm.operatorframework.io_clustercatalogs.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ spec:
9292
The lowest possible value is -2147483648.
9393
The highest possible value is 2147483647.
9494
format: int32
95+
maximum: 2147483647
96+
minimum: -2147483648
9597
type: integer
9698
source:
9799
description: |-

internal/operator-controller/resolve/catalog.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1.ClusterExtensio
160160
}
161161
// The current bundle shares deprecation status with prior bundles or
162162
// there are no prior bundles. Add it to the list.
163-
resolvedBundles = append(resolvedBundles, foundBundle{&thisBundle, cat.GetName(), cat.Spec.Priority})
163+
resolvedBundles = append(resolvedBundles, foundBundle{&thisBundle, cat.GetName(), cat.Spec.GetPriority()})
164164
priorDeprecation = thisDeprecation
165165
return nil
166166
}, listOptions...); err != nil {

internal/operator-controller/resolve/catalog_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ func TestUnequalPriority(t *testing.T) {
833833
genBundle(pkgName, "1.0.0"),
834834
},
835835
Deprecations: []declcfg.Deprecation{},
836-
}, &ocv1.ClusterCatalogSpec{Priority: 1}, nil
836+
}, &ocv1.ClusterCatalogSpec{Priority: ptr.To[int32](1)}, nil
837837
},
838838
"b": func() (*declcfg.DeclarativeConfig, *ocv1.ClusterCatalogSpec, error) {
839839
return &declcfg.DeclarativeConfig{
@@ -847,7 +847,7 @@ func TestUnequalPriority(t *testing.T) {
847847
genBundle(pkgName, "1.1.0"),
848848
},
849849
Deprecations: []declcfg.Deprecation{},
850-
}, &ocv1.ClusterCatalogSpec{Priority: 0}, nil
850+
}, &ocv1.ClusterCatalogSpec{Priority: ptr.To[int32](0)}, nil
851851
},
852852
}
853853
r := CatalogResolver{WalkCatalogsFunc: w.WalkCatalogs}
@@ -862,13 +862,13 @@ func TestMultiplePriority(t *testing.T) {
862862
pkgName := randPkg()
863863
w := staticCatalogWalker{
864864
"a": func() (*declcfg.DeclarativeConfig, *ocv1.ClusterCatalogSpec, error) {
865-
return genPackage(pkgName), &ocv1.ClusterCatalogSpec{Priority: 1}, nil
865+
return genPackage(pkgName), &ocv1.ClusterCatalogSpec{Priority: ptr.To[int32](1)}, nil
866866
},
867867
"b": func() (*declcfg.DeclarativeConfig, *ocv1.ClusterCatalogSpec, error) {
868-
return genPackage(pkgName), &ocv1.ClusterCatalogSpec{Priority: 0}, nil
868+
return genPackage(pkgName), &ocv1.ClusterCatalogSpec{Priority: ptr.To[int32](0)}, nil
869869
},
870870
"c": func() (*declcfg.DeclarativeConfig, *ocv1.ClusterCatalogSpec, error) {
871-
return genPackage(pkgName), &ocv1.ClusterCatalogSpec{Priority: 1}, nil
871+
return genPackage(pkgName), &ocv1.ClusterCatalogSpec{Priority: ptr.To[int32](1)}, nil
872872
},
873873
}
874874
r := CatalogResolver{WalkCatalogsFunc: w.WalkCatalogs}
@@ -944,7 +944,7 @@ func TestSomeCatalogsDisabled(t *testing.T) {
944944
Name: "enabledCatalog",
945945
},
946946
Spec: ocv1.ClusterCatalogSpec{
947-
Priority: 1, // Higher priority
947+
Priority: ptr.To[int32](1), // Higher priority
948948
AvailabilityMode: ocv1.AvailabilityModeAvailable,
949949
},
950950
},
@@ -953,7 +953,7 @@ func TestSomeCatalogsDisabled(t *testing.T) {
953953
Name: "disabledCatalog",
954954
},
955955
Spec: ocv1.ClusterCatalogSpec{
956-
Priority: 0, // Lower priority (but disabled)
956+
Priority: ptr.To[int32](0), // Lower priority (but disabled)
957957
AvailabilityMode: ocv1.AvailabilityModeUnavailable,
958958
},
959959
},

manifests/experimental-e2e.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ spec:
278278
The lowest possible value is -2147483648.
279279
The highest possible value is 2147483647.
280280
format: int32
281+
maximum: 2147483647
282+
minimum: -2147483648
281283
type: integer
282284
source:
283285
description: |-

manifests/experimental.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ spec:
239239
The lowest possible value is -2147483648.
240240
The highest possible value is 2147483647.
241241
format: int32
242+
maximum: 2147483647
243+
minimum: -2147483648
242244
type: integer
243245
source:
244246
description: |-

manifests/standard-e2e.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ spec:
278278
The lowest possible value is -2147483648.
279279
The highest possible value is 2147483647.
280280
format: int32
281+
maximum: 2147483647
282+
minimum: -2147483648
281283
type: integer
282284
source:
283285
description: |-

0 commit comments

Comments
 (0)