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

Set OpenAPI maxLength on enum fields #4048

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ get-pgmonitor:
cp -r '$(PGMONITOR_DIR)/postgres_exporter/common/.' '${QUERIES_CONFIG_DIR}'
cp '$(PGMONITOR_DIR)/postgres_exporter/linux/queries_backrest.yml' '${QUERIES_CONFIG_DIR}'

.PHONY: notes
notes: ## List known issues and future considerations
command -v rg > /dev/null && rg '(BUGS|FIXME|NOTE|TODO)[(][^)]+[)]' || grep -Ern '(BUGS|FIXME|NOTE|TODO)[(][^)]+[)]' *

.PHONY: clean
clean: ## Clean resources
clean: clean-deprecated
Expand Down
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
tjmoore4 marked this conversation as resolved.
Show resolved Hide resolved
//
// +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