Skip to content

Commit

Permalink
Set OpenAPI maxLength on enum fields
Browse files Browse the repository at this point in the history
This helps old Kubernetes estimate reasonable costs for CEL validation
rules.

See: https://issue.k8s.io/119511
  • Loading branch information
cbandy committed Dec 20, 2024
1 parent 612a8b0 commit 6468cc5
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ spec:
- aws
- azure
- gcp
maxLength: 10
type: string
x-kubernetes-validations:
- message: immutable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,7 @@ spec:
- Always
- Never
- IfNotPresent
maxLength: 15
type: string
imagePullSecrets:
description: |-
Expand Down Expand Up @@ -1827,6 +1828,7 @@ spec:
enum:
- Administrator
- User
maxLength: 15
type: string
username:
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,7 @@ spec:
- Always
- Never
- IfNotPresent
maxLength: 15
type: string
imagePullSecrets:
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7690,6 +7690,7 @@ spec:
- Always
- Never
- IfNotPresent
maxLength: 15
type: string
imagePullSecrets:
description: |-
Expand Down Expand Up @@ -11637,23 +11638,24 @@ spec:
default: INFO
description: |-
The Patroni log level.
https://docs.python.org/3.6/library/logging.html#levels
More info: https://docs.python.org/3/library/logging.html#levels
enum:
- CRITICAL
- ERROR
- WARNING
- INFO
- DEBUG
- NOTSET
maxLength: 10
type: string
storageLimit:
anyOf:
- type: integer
- type: string
description: |-
Limits the total amount of space taken by Patroni Log files.
Limits the total amount of space taken by Patroni log files.
Minimum value is 25MB.
https://pkg.go.dev/k8s.io/apimachinery/pkg/api/resource#Quantity
More info: https://kubernetes.io/docs/reference/kubernetes-api/common-definitions/quantity
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
required:
Expand Down Expand Up @@ -11692,6 +11694,7 @@ spec:
enum:
- Switchover
- Failover
maxLength: 15
type: string
required:
- enabled
Expand Down Expand Up @@ -14651,12 +14654,14 @@ spec:
enum:
- Cluster
- Local
maxLength: 10
type: string
internalTrafficPolicy:
description: 'More info: https://kubernetes.io/docs/concepts/services-networking/service/#traffic-policies'
enum:
- Cluster
- Local
maxLength: 10
type: string
metadata:
description: Metadata contains metadata for custom resources
Expand Down Expand Up @@ -14685,6 +14690,7 @@ spec:
- ClusterIP
- NodePort
- LoadBalancer
maxLength: 15
type: string
type: object
sidecars:
Expand Down Expand Up @@ -14990,12 +14996,14 @@ spec:
enum:
- Cluster
- Local
maxLength: 10
type: string
internalTrafficPolicy:
description: 'More info: https://kubernetes.io/docs/concepts/services-networking/service/#traffic-policies'
enum:
- Cluster
- Local
maxLength: 10
type: string
metadata:
description: Metadata contains metadata for custom resources
Expand Down Expand Up @@ -15024,6 +15032,7 @@ spec:
- ClusterIP
- NodePort
- LoadBalancer
maxLength: 15
type: string
type: object
service:
Expand All @@ -15035,12 +15044,14 @@ spec:
enum:
- Cluster
- Local
maxLength: 10
type: string
internalTrafficPolicy:
description: 'More info: https://kubernetes.io/docs/concepts/services-networking/service/#traffic-policies'
enum:
- Cluster
- Local
maxLength: 10
type: string
metadata:
description: Metadata contains metadata for custom resources
Expand Down Expand Up @@ -15069,6 +15080,7 @@ spec:
- ClusterIP
- NodePort
- LoadBalancer
maxLength: 15
type: string
type: object
shutdown:
Expand Down Expand Up @@ -16728,12 +16740,14 @@ spec:
enum:
- Cluster
- Local
maxLength: 10
type: string
internalTrafficPolicy:
description: 'More info: https://kubernetes.io/docs/concepts/services-networking/service/#traffic-policies'
enum:
- Cluster
- Local
maxLength: 10
type: string
metadata:
description: Metadata contains metadata for custom resources
Expand Down Expand Up @@ -16762,6 +16776,7 @@ spec:
- ClusterIP
- NodePort
- LoadBalancer
maxLength: 15
type: string
type: object
tolerations:
Expand Down Expand Up @@ -17046,6 +17061,7 @@ spec:
enum:
- ASCII
- AlphaNumeric
maxLength: 15
type: string
required:
- type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ type CrunchyBridgeClusterSpec struct {

// The cloud provider where the cluster is located.
// Currently Bridge offers aws, azure, and gcp only
// ---
// Kubernetes assumes the evaluation cost of an enum value is very large.
// TODO(k8s-1.29): Drop MaxLength after Kubernetes 1.29; https://issue.k8s.io/119511
// +kubebuilder:validation:MaxLength=10
//
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum={aws,azure,gcp}
// +kubebuilder:validation:XValidation:rule=`self == oldSelf`,message="immutable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,24 @@ type PatroniSpec struct {

type PatroniLogConfig struct {

// Limits the total amount of space taken by Patroni Log files.
// Limits the total amount of space taken by Patroni log files.
// Minimum value is 25MB.
// https://pkg.go.dev/k8s.io/apimachinery/pkg/api/resource#Quantity
// More info: https://kubernetes.io/docs/reference/kubernetes-api/common-definitions/quantity
// ---
// TODO(validation) TODO(k8s-1.29): Validate the minimum using CEL libraries.
//
// +required
StorageLimit *resource.Quantity `json:"storageLimit"`

// The Patroni log level.
// https://docs.python.org/3.6/library/logging.html#levels
// More info: https://docs.python.org/3/library/logging.html#levels
// ---
// Kubernetes assumes the evaluation cost of an enum value is very large.
// TODO(k8s-1.29): Drop MaxLength after Kubernetes 1.29; https://issue.k8s.io/119511
// +kubebuilder:validation:MaxLength=10
//
// +default="INFO"
// +kubebuilder:validation:Enum={CRITICAL,ERROR,WARNING,INFO,DEBUG,NOTSET}
// +kubebuilder:default:=INFO
// +optional
Level *string `json:"level,omitempty"`
}
Expand All @@ -87,6 +95,11 @@ type PatroniSwitchover struct {
// "Failover" forces a particular instance to be primary, regardless of other
// factors. A TargetInstance must be specified to failover.
// NOTE: The Failover type is reserved as the "last resort" case.
// ---
// Kubernetes assumes the evaluation cost of an enum value is very large.
// TODO(k8s-1.29): Drop MaxLength after Kubernetes 1.29; https://issue.k8s.io/119511
// +kubebuilder:validation:MaxLength=15
//
// +kubebuilder:validation:Enum={Switchover,Failover}
// +kubebuilder:default:=Switchover
// +optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ type PGUpgradeSpec struct {
// ImagePullPolicy is used to determine when Kubernetes will attempt to
// pull (download) container images.
// More info: https://kubernetes.io/docs/concepts/containers/images/#image-pull-policy
// ---
// Kubernetes assumes the evaluation cost of an enum value is very large.
// TODO(k8s-1.29): Drop MaxLength after Kubernetes 1.29; https://issue.k8s.io/119511
// +kubebuilder:validation:MaxLength=15
// +kubebuilder:validation:Type=string
//
// +kubebuilder:validation:Enum={Always,Never,IfNotPresent}
// +optional
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ type PostgresPasswordSpec struct {
// and AlphaNumeric.
// "ASCII" passwords contain letters, numbers, and symbols from the US-ASCII character set.
// "AlphaNumeric" passwords contain letters and numbers from the US-ASCII character set.
// ---
// Kubernetes assumes the evaluation cost of an enum value is very large.
// TODO(k8s-1.29): Drop MaxLength after Kubernetes 1.29; https://issue.k8s.io/119511
// +kubebuilder:validation:MaxLength=15
//
// +kubebuilder:default=ASCII
// +kubebuilder:validation:Enum={ASCII,AlphaNumeric}
Type string `json:"type"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ type PostgresClusterSpec struct {
// ImagePullPolicy is used to determine when Kubernetes will attempt to
// pull (download) container images.
// More info: https://kubernetes.io/docs/concepts/containers/images/#image-pull-policy
// ---
// Kubernetes assumes the evaluation cost of an enum value is very large.
// TODO(k8s-1.29): Drop MaxLength after Kubernetes 1.29; https://issue.k8s.io/119511
// +kubebuilder:validation:MaxLength=15
// +kubebuilder:validation:Type=string
//
// +kubebuilder:validation:Enum={Always,Never,IfNotPresent}
// +optional
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
Expand Down
14 changes: 14 additions & 0 deletions pkg/apis/postgres-operator.crunchydata.com/v1beta1/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,33 @@ type ServiceSpec struct {
NodePort *int32 `json:"nodePort,omitempty"`

// More info: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types
// ---
// Kubernetes assumes the evaluation cost of an enum value is very large.
// TODO(k8s-1.29): Drop MaxLength after Kubernetes 1.29; https://issue.k8s.io/119511
// +kubebuilder:validation:MaxLength=15
//
// +optional
// +kubebuilder:default=ClusterIP
// +kubebuilder:validation:Enum={ClusterIP,NodePort,LoadBalancer}
Type string `json:"type"`

// More info: https://kubernetes.io/docs/concepts/services-networking/service/#traffic-policies
// ---
// Kubernetes assumes the evaluation cost of an enum value is very large.
// TODO(k8s-1.29): Drop MaxLength after Kubernetes 1.29; https://issue.k8s.io/119511
// +kubebuilder:validation:MaxLength=10
// +kubebuilder:validation:Type=string
//
// +optional
// +kubebuilder:validation:Enum={Cluster,Local}
InternalTrafficPolicy *corev1.ServiceInternalTrafficPolicyType `json:"internalTrafficPolicy,omitempty"`

// More info: https://kubernetes.io/docs/concepts/services-networking/service/#traffic-policies
// ---
// Kubernetes assumes the evaluation cost of an enum value is very large.
// TODO(k8s-1.29): Drop MaxLength after Kubernetes 1.29; https://issue.k8s.io/119511
// +kubebuilder:validation:MaxLength=10
// +kubebuilder:validation:Type=string
//
// +optional
// +kubebuilder:validation:Enum={Cluster,Local}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ type PGAdminSpec struct {
// ImagePullPolicy is used to determine when Kubernetes will attempt to
// pull (download) container images.
// More info: https://kubernetes.io/docs/concepts/containers/images/#image-pull-policy
// ---
// Kubernetes assumes the evaluation cost of an enum value is very large.
// TODO(k8s-1.29): Drop MaxLength after Kubernetes 1.29; https://issue.k8s.io/119511
// +kubebuilder:validation:MaxLength=15
// +kubebuilder:validation:Type=string
//
// +kubebuilder:validation:Enum={Always,Never,IfNotPresent}
// +optional
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
Expand Down Expand Up @@ -146,6 +152,11 @@ type PGAdminUser struct {

// Role determines whether the user has admin privileges or not.
// Defaults to User. Valid options are Administrator and User.
// ---
// Kubernetes assumes the evaluation cost of an enum value is very large.
// TODO(k8s-1.29): Drop MaxLength after Kubernetes 1.29; https://issue.k8s.io/119511
// +kubebuilder:validation:MaxLength=15
//
// +kubebuilder:validation:Enum={Administrator,User}
// +optional
Role string `json:"role,omitempty"`
Expand Down

0 comments on commit 6468cc5

Please sign in to comment.