Hey Patrik,
What you want to achieve is possible, but you have to approach it in a slightly different way.
Kube API conventions recommend against using `map` types within APIs, instead you use a list and set some special keys on it, that make it behave like a map.
So the API type that you’d want for this would look something like:
// +kubebuilder:validation:Enum:=Apple;Pear;Banana
type FruitType string
type FruitSpec struct {
Fruit FruitType `json:"fruit”`
// Add other fields as required
}
type Parent struct {
// +listType=map
// +listMapKey=fruit
Fruits []FruitSpec
}
Then, when you try to create items in the Fruits list, the listType will validate that each combination of `listMapKey` is unique within the list, and that your `Fruit` values match only those within your enumerated list.
Hope that helps,
Joel
Joel Speed
He/Him/His
Principal Software Engineer, OpenShift
Red Hat