Open
Description
What happened?
Related to:
kubernetes/enhancements#5034 (comment)
In attempting to test an example related to the above DRA question, I seem to be hitting an potential-bug/inconsistency when using +k8s:unionMember with an embedded struct vs using-the-fields-directly:
If you use the below example (snippet below, full file here: https://gist.github.com/aaron-prindle/4cf482dd532ef40562eb5f4dab745237)
...
// DeviceAttribute represents an attribute of a device. It's a union of different value types.
type DeviceAttribute struct {
// +k8s:unionMember
IntegerValue *IntegerValue `json:"integerValue,omitempty"`
// +k8s:unionMember
StringValue *StringValue `json:"stringValue,omitempty"`
}
// NullableDeviceAttribute can be either a concrete DeviceAttribute or explicitly null.
type NullableDeviceAttribute struct {
TypeMeta int
// Embed DeviceAttribute - this will be flattened in OpenAPI
DeviceAttribute `json:",inline"`
// +k8s:unionMember
NullValue *NullValue `json:"nullValue,omitempty"`
}
This causes validation-gen to error:
aprindle@aprindle-ssd ~/kubernetes [nested-union]hack/update-codegen.sh validation
+++ [0130 19:24:07] Generating validation code for 62 targets
F0130 19:24:11.239774 1652081 targets.go:259] failed to generate validations: k8s.io/code-generator/cmd/validation-gen/output_tests/unions/nested_union.NullableDeviceAttribute.DeviceAttribute: variable generation is not supported for field validations
!!! [0130 19:24:11] Call tree:
!!! [0130 19:24:11] 1: hack/update-codegen.sh:965 codegen::validation(...)
But if you were to flatten the fields from the embedded struct, eg:
// NullableDeviceAttribute can be either a concrete DeviceAttribute or explicitly null.
type NullableDeviceAttribute struct {
TypeMeta int
// +k8s:unionMember
IntegerValue *IntegerValue `json:"integerValue,omitempty"`
// +k8s:unionMember
StringValue *StringValue `json:"stringValue,omitempty"`
// +k8s:unionMember
NullValue *NullValue `json:"nullValue,omitempty"`
}
validation-gen succeeds
aprindle@aprindle-ssd ~/kubernetes [nested-union]hack/update-codegen.sh validation
+++ [0130 19:25:08] Generating validation code for 62 targets
Metadata
Metadata
Assignees
Labels
No labels
Activity