Skip to content

Commit cedf6b4

Browse files
committed
PR feedback
1 parent 4901e18 commit cedf6b4

File tree

6 files changed

+42
-27
lines changed

6 files changed

+42
-27
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11034,6 +11034,9 @@ spec:
1103411034
properties:
1103511035
claimName:
1103611036
description: A reference to a preexisting PVC.
11037+
maxLength: 253
11038+
minLength: 1
11039+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?([.][a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
1103711040
type: string
1103811041
containers:
1103911042
description: |-
@@ -11045,11 +11048,13 @@ spec:
1104511048
type: array
1104611049
x-kubernetes-list-type: atomic
1104711050
name:
11051+
allOf:
11052+
- maxLength: 63
11053+
- maxLength: 55
1104811054
description: |-
1104911055
The name of the volume used for mounting path.
1105011056
Volumes are mounted in the pods at `volumes/<NAME>`
1105111057
Must be unique.
11052-
maxLength: 55
1105311058
minLength: 1
1105411059
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
1105511060
type: string
@@ -29643,6 +29648,9 @@ spec:
2964329648
properties:
2964429649
claimName:
2964529650
description: A reference to a preexisting PVC.
29651+
maxLength: 253
29652+
minLength: 1
29653+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?([.][a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
2964629654
type: string
2964729655
containers:
2964829656
description: |-
@@ -29654,11 +29662,13 @@ spec:
2965429662
type: array
2965529663
x-kubernetes-list-type: atomic
2965629664
name:
29665+
allOf:
29666+
- maxLength: 63
29667+
- maxLength: 55
2965729668
description: |-
2965829669
The name of the volume used for mounting path.
2965929670
Volumes are mounted in the pods at `volumes/<NAME>`
2966029671
Must be unique.
29661-
maxLength: 55
2966229672
minLength: 1
2966329673
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
2966429674
type: string

internal/controller/postgrescluster/util.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,12 @@ func addAdditionalVolumesToSpecifiedContainers(template *corev1.PodTemplateSpec,
323323
},
324324
}
325325

326+
// Create a set of all the requested containers,
327+
// then in the loops below when we attach the volume to a container,
328+
// we can safely remove that container name from the set.
329+
// This gives us a way to track the containers that are requested but not found.
330+
// This relies on `containers` and `initContainers` together being unique.
331+
// - https://github.com/kubernetes/api/blob/b40c1cacbb902b21a7e0c7bf0967321860c1a632/core/v1/types.go#L3895C27-L3896C33
326332
names := sets.New(additionalVolumeRequest.Containers...)
327333
allContainers := false
328334
if names.Len() == 0 {
@@ -335,9 +341,7 @@ func addAdditionalVolumesToSpecifiedContainers(template *corev1.PodTemplateSpec,
335341
template.Spec.Containers[i].VolumeMounts,
336342
additionalVolumeMount)
337343

338-
if names.Has(template.Spec.Containers[i].Name) {
339-
names.Delete(template.Spec.Containers[i].Name)
340-
}
344+
names.Delete(template.Spec.Containers[i].Name)
341345
}
342346
}
343347

@@ -347,9 +351,8 @@ func addAdditionalVolumesToSpecifiedContainers(template *corev1.PodTemplateSpec,
347351
template.Spec.InitContainers[i].VolumeMounts,
348352
additionalVolumeMount)
349353

350-
if names.Has(template.Spec.InitContainers[i].Name) {
351-
names.Delete(template.Spec.InitContainers[i].Name)
352-
}
354+
names.Delete(template.Spec.InitContainers[i].Name)
355+
353356
}
354357
}
355358

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -529,19 +529,19 @@ type PostgresInstanceSetSpec struct {
529529
}
530530

531531
type PostgresVolumesSpec struct {
532-
// An ephemeral volume for temporary files.
533-
// More info: https://kubernetes.io/docs/concepts/storage/ephemeral-volumes
534-
// ---
535-
// +optional
536-
Temp *v1beta1.VolumeClaimSpec `json:"temp,omitempty"`
537-
538532
// Additional pre-existing volumes to add to the pod.
539533
// ---
540534
// +optional
541535
// +listType=map
542536
// +listMapKey=name
543537
// +kubebuilder:validation:MaxItems=10
544538
Additional []v1beta1.AdditionalVolume `json:"additional,omitempty"`
539+
540+
// An ephemeral volume for temporary files.
541+
// More info: https://kubernetes.io/docs/concepts/storage/ephemeral-volumes
542+
// ---
543+
// +optional
544+
Temp *v1beta1.VolumeClaimSpec `json:"temp,omitempty"`
545545
}
546546

547547
type TablespaceVolume struct {

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -526,19 +526,19 @@ type PostgresInstanceSetSpec struct {
526526
}
527527

528528
type PostgresVolumesSpec struct {
529-
// An ephemeral volume for temporary files.
530-
// More info: https://kubernetes.io/docs/concepts/storage/ephemeral-volumes
531-
// ---
532-
// +optional
533-
Temp *VolumeClaimSpec `json:"temp,omitempty"`
534-
535529
// Additional pre-existing volumes to add to the pod.
536530
// ---
537531
// +optional
538532
// +listType=map
539533
// +listMapKey=name
540534
// +kubebuilder:validation:MaxItems=10
541535
Additional []AdditionalVolume `json:"additional,omitempty"`
536+
537+
// An ephemeral volume for temporary files.
538+
// More info: https://kubernetes.io/docs/concepts/storage/ephemeral-volumes
539+
// ---
540+
// +optional
541+
Temp *VolumeClaimSpec `json:"temp,omitempty"`
542542
}
543543

544544
type AdditionalVolume struct {
@@ -549,12 +549,14 @@ type AdditionalVolume struct {
549549
// The `Name` field is a `DNS1123Label` type to enforce
550550
// the max length.
551551
// +required
552+
// Max length is less than max 63 to allow prepending `volumes-` to name
553+
// +kubebuilder:validation:MaxLength=55
552554
Name DNS1123Label `json:"name"`
553555

554556
// A reference to a preexisting PVC.
555557
// ---
556558
// +required
557-
ClaimName string `json:"claimName"`
559+
ClaimName DNS1123Subdomain `json:"claimName"`
558560

559561
// The containers to attach this volume to.
560562
// A blank/unset `Containers` field matches all containers.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ type ConfigDataKey = string
3333
type DNS1123Subdomain = string
3434

3535
// ---
36+
// https://docs.k8s.io/concepts/overview/working-with-objects/names#dns-label-names
3637
// https://pkg.go.dev/k8s.io/apimachinery/pkg/util/validation#IsDNS1123Label
3738
// https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Format
3839
//
3940
// +kubebuilder:validation:MinLength=1
40-
// Max length is less than max 63 to allow prepending `volumes-` to name
41-
// +kubebuilder:validation:MaxLength=55
41+
// +kubebuilder:validation:MaxLength=63
4242
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`
4343
type DNS1123Label = string
4444

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

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)