go - Forbidden: uniqueItems cannot be set to true since the runtime complexity becomes quadratic - Stack Overflow

admin2025-04-18  3

My Kubernetes CRD:

type FooSpec struct {
    // +kubebuilder:validation:UniqueItems=true
    MyItems []string `json:"myItems"`

Fails:

Forbidden: uniqueItems cannot be set to true since the runtime complexity becomes quadratic

This is documented: kubernetes.io validation docs


How can I ensure that the slice MyItems contains no duplicates without writing a webhook?

My Kubernetes CRD:

type FooSpec struct {
    // +kubebuilder:validation:UniqueItems=true
    MyItems []string `json:"myItems"`

Fails:

Forbidden: uniqueItems cannot be set to true since the runtime complexity becomes quadratic

This is documented: kubernetes.io validation docs


How can I ensure that the slice MyItems contains no duplicates without writing a webhook?

Share edited Jan 30 at 8:51 guettli asked Jan 30 at 8:33 guettliguettli 26.9k105 gold badges414 silver badges761 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

This works: listType=set

type FooSpec struct {
    // +listType=set
    MyItems []string `json:"myItems"`
转载请注明原文地址:http://anycun.com/QandA/1744931247a89654.html