Skip to content

Commit

Permalink
docs: Avoid omitempty with kubebuilder:validation:Required
Browse files Browse the repository at this point in the history
When writing a unionDiscriminator, use of ",omitempty" in the JSON
spec overrides any attempt to require the discriminator via the tag
+kubebuilder:validation:Required.  It is confusing to have the docs
recommend two conflicting pieces of information for the same field,
and it makes more sense for the discriminator to be mandatory (even
though, as correctly pointed out below, all of the other fields of the
union type must be optional).

See also kubernetes-sigs/kubebuilder#3794,
where a debate was held on whether kubebuilder should document the
interplay, which in turn pointed back to controller-tools conventions.

Signed-off-by: Eric Blake <[email protected]>
  • Loading branch information
ebblake committed Oct 7, 2024
1 parent 14fd3d6 commit a7c3f6d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion dev-guide/api-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ type MyPlatformConfig struct {
// +unionDiscriminator
// +kubebuilder:validation:Enum:="AWS";"Azure";"GCP"
// +kubebuilder:validation:Required
PlatformType string `json:"platformType,omitempty"`
PlatformType string `json:"platformType"`

// AWS is the AWS configuration.
// All structures within the union must be optional and pointers.
Expand Down

0 comments on commit a7c3f6d

Please sign in to comment.