Description
I encountered validation error when applying the generated CRD containing PodSpec which has new ResourceClaim in https://pkg.go.dev/k8s.io/api@v0.26.0/core/v1#ResourceRequirements added in k8s v1.26.
It sets +listType=set
.
When applying generated CRD, I got the following error:
... .properties[spec].properties[initContainers].items.properties[resources].properties[claims].items.x-kubernetes-map-type: Invalid value: "null": must be atomic as item of a list with x-kubernetes-list-type=set
This validation seems to be happened at https://github.com/kubernetes/apiextensions-apiserver/blob/9746985976f9fee21736250e3afb0eae27026633/pkg/apis/apiextensions/validation/validation.go#L945
Adding x-kubernetes-map-type=atomic
under items fixes this issue.
I'm wondering whether this is a lack of x-kubernetes-map-type=atomic
in ResourceClaim, or something that CRD generator must deal with.
The following patch automatically adds x-kubernetes-map-type=atomic
to items when x-kubernetes-list-type=set
is seen, but I feel this is hacky and probably not a correct way:
--- a/pkg/crd/markers/topology.go
+++ b/pkg/crd/markers/topology.go
@@ -116,6 +116,14 @@ func (l ListType) ApplyToSchema(schema *apiext.JSONSchemaProps) error {
}
p := string(l)
schema.XListType = &p
+
+ if l == "set" {
+ if itemSchema := schema.Items.Schema; itemSchema != nil {
+ v := "atomic"
+ itemSchema.XMapType = &v
+ }
+ }
+
return nil
}