Skip to content

Commit 6b01868

Browse files
cbandybenjaminjb
andcommitted
Make each PostgresCluster..volumes.additional atomic
This limits each volume to a single manager and allows us to express that container names are a unique set. Co-authored-by: Ben Blattberg <[email protected]>
1 parent 1971629 commit 6b01868

File tree

4 files changed

+57
-35
lines changed

4 files changed

+57
-35
lines changed

config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11033,39 +11033,42 @@ spec:
1103311033
items:
1103411034
properties:
1103511035
claimName:
11036-
description: A reference to a preexisting PVC.
11036+
description: Name of an existing PersistentVolumeClaim.
1103711037
maxLength: 253
1103811038
minLength: 1
1103911039
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?([.][a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
1104011040
type: string
1104111041
containers:
1104211042
description: |-
11043-
The containers to attach this volume to.
11044-
An omitted `Containers` field matches all containers.
11045-
An empty `Containers` field matches no containers.
11043+
The names of containers in which to mount this volume.
11044+
The default mounts the volume in *all* containers. An empty list does not mount the volume to any containers.
1104611045
items:
11046+
maxLength: 63
11047+
minLength: 1
11048+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
1104711049
type: string
1104811050
maxItems: 10
1104911051
type: array
11050-
x-kubernetes-list-type: atomic
11052+
x-kubernetes-list-type: set
1105111053
name:
1105211054
allOf:
1105311055
- maxLength: 63
1105411056
- maxLength: 55
1105511057
description: |-
11056-
The name of the volume used for mounting path.
11057-
Volumes are mounted in the pods at `volumes/<NAME>`
11058-
Must be unique.
11058+
The name of the directory in which to mount this volume.
11059+
Volumes are mounted in containers at `/volumes/{name}`.
1105911060
minLength: 1
1106011061
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
1106111062
type: string
1106211063
readOnly:
11063-
description: Sets the write/read mode of the volume
11064+
description: When true, mount the volume read-only,
11065+
otherwise read-write. Defaults to false.
1106411066
type: boolean
1106511067
required:
1106611068
- claimName
1106711069
- name
1106811070
type: object
11071+
x-kubernetes-map-type: atomic
1106911072
maxItems: 10
1107011073
type: array
1107111074
x-kubernetes-list-map-keys:
@@ -29648,39 +29651,42 @@ spec:
2964829651
items:
2964929652
properties:
2965029653
claimName:
29651-
description: A reference to a preexisting PVC.
29654+
description: Name of an existing PersistentVolumeClaim.
2965229655
maxLength: 253
2965329656
minLength: 1
2965429657
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?([.][a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
2965529658
type: string
2965629659
containers:
2965729660
description: |-
29658-
The containers to attach this volume to.
29659-
An omitted `Containers` field matches all containers.
29660-
An empty `Containers` field matches no containers.
29661+
The names of containers in which to mount this volume.
29662+
The default mounts the volume in *all* containers. An empty list does not mount the volume to any containers.
2966129663
items:
29664+
maxLength: 63
29665+
minLength: 1
29666+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
2966229667
type: string
2966329668
maxItems: 10
2966429669
type: array
29665-
x-kubernetes-list-type: atomic
29670+
x-kubernetes-list-type: set
2966629671
name:
2966729672
allOf:
2966829673
- maxLength: 63
2966929674
- maxLength: 55
2967029675
description: |-
29671-
The name of the volume used for mounting path.
29672-
Volumes are mounted in the pods at `volumes/<NAME>`
29673-
Must be unique.
29676+
The name of the directory in which to mount this volume.
29677+
Volumes are mounted in containers at `/volumes/{name}`.
2967429678
minLength: 1
2967529679
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
2967629680
type: string
2967729681
readOnly:
29678-
description: Sets the write/read mode of the volume
29682+
description: When true, mount the volume read-only,
29683+
otherwise read-write. Defaults to false.
2967929684
type: boolean
2968029685
required:
2968129686
- claimName
2968229687
- name
2968329688
type: object
29689+
x-kubernetes-map-type: atomic
2968429690
maxItems: 10
2968529691
type: array
2968629692
x-kubernetes-list-map-keys:

pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -541,34 +541,50 @@ type PostgresVolumesSpec struct {
541541
Temp *VolumeClaimSpec `json:"temp,omitempty"`
542542
}
543543

544+
// ---
545+
// Only one applier should be managing each volume definition.
546+
// https://docs.k8s.io/reference/using-api/server-side-apply#merge-strategy
547+
// +structType=atomic
544548
type AdditionalVolume struct {
545-
// A reference to a preexisting PVC.
549+
// Name of an existing PersistentVolumeClaim.
546550
// ---
551+
// https://pkg.go.dev/k8s.io/kubernetes/pkg/apis/core/validation#ValidatePersistentVolumeClaim
552+
// https://pkg.go.dev/k8s.io/kubernetes/pkg/apis/core/validation#ValidatePersistentVolumeName
553+
//
547554
// +required
548555
ClaimName DNS1123Subdomain `json:"claimName"`
549556

550-
// The containers to attach this volume to.
551-
// An omitted `Containers` field matches all containers.
552-
// An empty `Containers` field matches no containers.
557+
// The names of containers in which to mount this volume.
558+
// The default mounts the volume in *all* containers. An empty list does not mount the volume to any containers.
553559
// ---
554-
// +optional
555-
// +listType=atomic
560+
// These are matched against [corev1.Container.Name] in a PodSpec, which is a [DNS1123Label].
561+
// https://pkg.go.dev/k8s.io/kubernetes/pkg/apis/core/validation#ValidatePodSpec
562+
//
563+
// Container names are unique within a Pod, so this list can be, too.
564+
// +listType=set
565+
//
556566
// +kubebuilder:validation:MaxItems=10
557-
Containers []string `json:"containers,omitempty"`
567+
// +optional
568+
Containers []DNS1123Label `json:"containers"`
558569

559-
// The name of the volume used for mounting path.
560-
// Volumes are mounted in the pods at `volumes/<NAME>`
561-
// Must be unique.
570+
// The name of the directory in which to mount this volume.
571+
// Volumes are mounted in containers at `/volumes/{name}`.
562572
// ---
563-
// The `Name` field is a `DNS1123Label` type to enforce
564-
// the max length.
565-
// +required
566-
// Max length is less than max 63 to allow prepending `volumes-` to name
573+
// This also goes into the [corev1.Volume.Name] field, which is a [DNS1123Label].
574+
// https://pkg.go.dev/k8s.io/kubernetes/pkg/apis/core/validation#ValidatePodSpec
575+
// https://pkg.go.dev/k8s.io/kubernetes/pkg/apis/core/validation#ValidateVolumes
576+
//
577+
// We prepend "volumes-" to avoid collisions with other [corev1.PodSpec.Volumes],
578+
// so the maximum is 8 less than the inherited 63.
567579
// +kubebuilder:validation:MaxLength=55
580+
//
581+
// +required
568582
Name DNS1123Label `json:"name"`
569583

570-
// Sets the write/read mode of the volume
584+
// When true, mount the volume read-only, otherwise read-write. Defaults to false.
571585
// ---
586+
// [corev1.VolumeMount.ReadOnly]
587+
//
572588
// +optional
573589
ReadOnly bool `json:"readOnly,omitempty"`
574590
}

pkg/apis/postgres-operator.crunchydata.com/v1beta1/shared_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
type ConfigDataKey = string
2424

2525
// ---
26-
// https://docs.k8s.io/concepts/overview/working-with-objects/names/#dns-subdomain-names
26+
// https://docs.k8s.io/concepts/overview/working-with-objects/names#dns-subdomain-names
2727
// https://pkg.go.dev/k8s.io/apimachinery/pkg/util/validation#IsDNS1123Subdomain
2828
// https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Format
2929
//

pkg/apis/postgres-operator.crunchydata.com/v1beta1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)