Skip to content

Commit d31b32b

Browse files
Fix kubebuilder optional/required markers for API fields
Add missing optional/required markers to resolve kube-api-linter errors while preserving correct API semantics and discriminated union patterns. Detailed Change Explanations: 1. api/v1/clustercatalog_types.go Change: Added // +optional marker to ResolvedCatalogSource.Image field Reason: - This is a discriminated union field controlled by the Type field - XValidation enforces: when Type == "Image", Image is required; otherwise forbidden - Field is conditionally required, not always required - Field may be nil during initial reconciliation - Allows future extensibility - Fixes kube-api-linter optionalorrequired error 2. api/v1/clusterextension_types.go Change: Added // +optional marker and omitempty to PreflightConfig.CRDUpgradeSafety Reason: - Production code checks for nil - Field is optional at the Go level - omitempty follows Kubernetes conventions - Fixes kube-api-linter optionalorrequired error 3. api/v1/clusterextensionrevision_types.go Change: Added // +required marker to ClusterExtensionRevisionPhase.Objects Reason: - Field is a slice and must always be present - Tests show empty slice is valid - No omitempty by design - Godoc confirms it is required - Fixes kube-api-linter optionalorrequired error
1 parent b0e0d65 commit d31b32b

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

api/v1/clustercatalog_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ type ResolvedCatalogSource struct {
246246
Type SourceType `json:"type"`
247247
// image contains resolution information for a catalog sourced from an image.
248248
// It must be set when type is Image, and forbidden otherwise.
249+
// +optional
249250
Image *ResolvedImageSource `json:"image"`
250251
}
251252

api/v1/clusterextension_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ type PreflightConfig struct {
405405
//
406406
// The CRD Upgrade Safety pre-flight check safeguards from unintended consequences of upgrading a CRD,
407407
// such as data loss.
408-
CRDUpgradeSafety *CRDUpgradeSafetyPreflightConfig `json:"crdUpgradeSafety"`
408+
// +optional
409+
CRDUpgradeSafety *CRDUpgradeSafetyPreflightConfig `json:"crdUpgradeSafety,omitempty"`
409410
}
410411

411412
// CRDUpgradeSafetyPreflightConfig is the configuration for CRD upgrade safety preflight check.

api/v1/clusterextensionrevision_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ type ClusterExtensionRevisionPhase struct {
123123
// objects is a required list of all Kubernetes objects that belong to this phase.
124124
//
125125
// All objects in this list are applied to the cluster in no particular order.
126+
// +required
126127
Objects []ClusterExtensionRevisionObject `json:"objects"`
127128
}
128129

0 commit comments

Comments
 (0)