Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dedicated alias type for CRD array item enums #1779

Closed
1 of 3 tasks
rainest opened this issue Aug 27, 2021 · 0 comments · Fixed by #1971
Closed
1 of 3 tasks

Add dedicated alias type for CRD array item enums #1779

rainest opened this issue Aug 27, 2021 · 0 comments · Fixed by #1971

Comments

@rainest
Copy link
Contributor

rainest commented Aug 27, 2021

Is there an existing issue for this?

  • I have searched the existing issues

Problem Statement

Follow-up from #1757 (comment)

Per kubernetes-sigs/controller-tools#342 our tooling does not support automated validation generation for arrays of standard types where we wish to apply validation rules to the items within the array. For example, if you wish to enforce that every string item in the protocols array is one of http, https, udp, or tcp, you cannot.

Proposed Solution

Absent functionality in controller-tools (which is unlikely to arrive any time soon), the prescribed solution is to create a dedicated alias type. You can write something like:

//+kubebuilder:validation:Enum=http;https;grpc;grpcs;tcp;tls;udp
type KongPluginProtocol string

Protocols []KongPluginProtocol `json:"protocols,omitempty"`

where we've currently tried

//+kubebuilder:validation:Enum=http;https;grpc;grpcs;tcp;tls;udp
Protocols []string `json:"protocols,omitempty"`

and Kubebuilder will build the correct validation rule.

Additional information

No response

Acceptance Criteria

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants