Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f906775

Browse files
Focus additional volume mounting on preexisting PVCs
1 parent c355873 commit f906775

File tree

8 files changed

+45
-565
lines changed

8 files changed

+45
-565
lines changed

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

Lines changed: 17 additions & 440 deletions
Large diffs are not rendered by default.

‎internal/controller/postgrescluster/instance.go‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,10 +1183,6 @@ func (r *Reconciler) reconcileInstance(
11831183
if err == nil {
11841184
tablespaceVolumes, err = r.reconcileTablespaceVolumes(ctx, cluster, spec, instance, clusterVolumes)
11851185
}
1186-
if err == nil {
1187-
_, err = r.reconcileAdditionalVolumes(ctx,
1188-
cluster, spec.Volumes.Additional)
1189-
}
11901186
if err == nil {
11911187
postgres.InstancePod(
11921188
ctx, cluster, spec,
@@ -1259,7 +1255,7 @@ func (r *Reconciler) reconcileInstance(
12591255

12601256
// mount additional volumes to the Postgres instance containers
12611257
if err == nil && spec.Volumes != nil && spec.Volumes.Additional != nil {
1262-
addAdditionalVolumes(&instance.Spec.Template, cluster, spec.Volumes.Additional)
1258+
addAdditionalVolumesToSpecifiedContainers(&instance.Spec.Template, spec.Volumes.Additional)
12631259
}
12641260

12651261
if err == nil {

‎internal/controller/postgrescluster/util.go‎

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -289,41 +289,39 @@ func safeHash32(content func(w io.Writer) error) (string, error) {
289289
}
290290

291291
// AdditionalVolumeMount returns the name and mount path of the additional volume.
292-
func AdditionalVolumeMount(cluster *v1beta1.PostgresCluster,
293-
additionalVolume *v1beta1.AdditionalVolume) corev1.VolumeMount {
294-
295-
volumeName := naming.AdditionalVolume(cluster, additionalVolume).Name
296-
292+
func AdditionalVolumeMount(volumeName, claimName string) corev1.VolumeMount {
297293
return corev1.VolumeMount{
298-
Name: volumeName,
299-
MountPath: "volumes" + "/" + additionalVolume.Name}
294+
Name: claimName,
295+
MountPath: "/volumes" + "/" + volumeName}
300296
}
301297

302-
// addAdditionalVolumes adds additional volumes to the Postgres pod
303-
funcaddAdditionalVolumes(template*corev1.PodTemplateSpec,
304-
inCluster*v1beta1.PostgresCluster,
298+
// addAdditionalVolumesToSpecifiedContainers adds additional volumes to the specified
299+
// containers in the specified pod
300+
funcaddAdditionalVolumesToSpecifiedContainers(template*corev1.PodTemplateSpec,
305301
additionalVolumes []*v1beta1.AdditionalVolume) {
306302

307-
for _, additionalVolume := range additionalVolumes {
303+
for _, additionalVolumeRequest := range additionalVolumes {
308304

309305
additionalVolumeMount := AdditionalVolumeMount(
310-
inCluster,
311-
additionalVolume)
306+
additionalVolumeRequest.Name,
307+
additionalVolumeRequest.ClaimName)
312308

313-
additionalVolumeSpec := corev1.Volume{
309+
additionalVolume := corev1.Volume{
314310
Name: additionalVolumeMount.Name,
315311
VolumeSource: corev1.VolumeSource{
316312
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
313+
// TODO: Using the claim name as the claim name here means this has to be unique
314+
// We could add the index if we want someone to mount the same PVC in multiple dirs?
317315
ClaimName: additionalVolumeMount.Name,
318-
ReadOnly: additionalVolume.ReadOnly,
316+
ReadOnly: additionalVolumeRequest.ReadOnly,
319317
},
320318
},
321319
}
322320

323321
for i := range template.Spec.Containers {
324-
if len(additionalVolume.Containers) == 0 ||
322+
if len(additionalVolumeRequest.Containers) == 0 ||
325323
slices.Contains(
326-
additionalVolume.Containers,
324+
additionalVolumeRequest.Containers,
327325
template.Spec.Containers[i].Name) {
328326
template.Spec.Containers[i].VolumeMounts = append(
329327
template.Spec.Containers[i].VolumeMounts,
@@ -332,9 +330,9 @@ func addAdditionalVolumes(template *corev1.PodTemplateSpec,
332330
}
333331

334332
for i := range template.Spec.InitContainers {
335-
if len(additionalVolume.Containers) == 0 ||
333+
if len(additionalVolumeRequest.Containers) == 0 ||
336334
slices.Contains(
337-
additionalVolume.Containers,
335+
additionalVolumeRequest.Containers,
338336
template.Spec.InitContainers[i].Name) {
339337
template.Spec.InitContainers[i].VolumeMounts = append(
340338
template.Spec.InitContainers[i].VolumeMounts,
@@ -344,6 +342,6 @@ func addAdditionalVolumes(template *corev1.PodTemplateSpec,
344342

345343
template.Spec.Volumes = append(
346344
template.Spec.Volumes,
347-
additionalVolumeSpec)
345+
additionalVolume)
348346
}
349347
}

‎internal/controller/postgrescluster/volumes.go‎

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -906,64 +906,3 @@ func getPVCName(volumes []*corev1.PersistentVolumeClaim, selector labels.Selecto
906906
}
907907
return ""
908908
}
909-
910-
// +kubebuilder:rbac:groups="",resources="persistentvolumeclaims",verbs={get}
911-
// +kubebuilder:rbac:groups="",resources="persistentvolumeclaims",verbs={create,delete,patch}
912-
913-
// reconcileAdditionalVolumes writes the PersistentVolumeClaim for additional volumes.
914-
func (r *Reconciler) reconcileAdditionalVolumes(
915-
ctx context.Context,
916-
cluster *v1beta1.PostgresCluster,
917-
additionalVolumes []*v1beta1.AdditionalVolume,
918-
// instance *appsv1.StatefulSet,
919-
// observed *Instance,
920-
) (additionalVolumePVCs []*corev1.PersistentVolumeClaim, err error) {
921-
922-
if len(additionalVolumes) == 0 {
923-
return
924-
}
925-
926-
for _, additionalVolume := range additionalVolumes {
927-
// If the user provides a PVC, we leave it alone here
928-
// and use it to mount the volume
929-
if additionalVolume.ClaimName != "" {
930-
continue
931-
}
932-
933-
// TODO: What labels do we want to add
934-
labelMap := map[string]string{
935-
naming.LabelCluster: cluster.Name,
936-
}
937-
938-
pvc := &corev1.PersistentVolumeClaim{ObjectMeta: naming.AdditionalVolume(cluster, additionalVolume)}
939-
940-
pvc.SetGroupVersionKind(corev1.SchemeGroupVersion.WithKind("PersistentVolumeClaim"))
941-
942-
err = errors.WithStack(r.setControllerReference(cluster, pvc))
943-
944-
// TODO: Do we have other labels/annotation sources we want to merge?
945-
pvc.Annotations = naming.Merge(
946-
cluster.Spec.Metadata.GetAnnotationsOrNil())
947-
948-
pvc.Labels = naming.Merge(
949-
cluster.Spec.Metadata.GetLabelsOrNil(),
950-
labelMap,
951-
)
952-
953-
pvc.Spec = additionalVolume.ClaimTemplate.AsPersistentVolumeClaimSpec()
954-
955-
if err == nil {
956-
err = r.handlePersistentVolumeClaimError(cluster,
957-
errors.WithStack(r.apply(ctx, pvc)))
958-
}
959-
960-
if err != nil {
961-
return nil, err
962-
}
963-
964-
additionalVolumePVCs = append(additionalVolumePVCs, pvc)
965-
}
966-
967-
return
968-
969-
}

‎internal/naming/names.go‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -350,21 +350,6 @@ func InstancePostgresWALVolume(instance *appsv1.StatefulSet) metav1.ObjectMeta {
350350
}
351351
}
352352

353-
// AdditionalVolume returns the ObjectMeta for the additional
354-
// volume for instance.
355-
func AdditionalVolume(cluster *v1beta1.PostgresCluster,
356-
volume *v1beta1.AdditionalVolume) metav1.ObjectMeta {
357-
// TODO: What's the name for the PVC if not given?
358-
volumeName := volume.ClaimName
359-
if volumeName == "" {
360-
volumeName = cluster.GetName() + "-additional-something"
361-
}
362-
return metav1.ObjectMeta{
363-
Namespace: cluster.GetNamespace(),
364-
Name: volumeName,
365-
}
366-
}
367-
368353
// MonitoringUserSecret returns ObjectMeta necessary to lookup the Secret
369354
// containing authentication credentials for monitoring tools.
370355
func MonitoringUserSecret(cluster *v1beta1.PostgresCluster) metav1.ObjectMeta {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,14 +535,12 @@ type PostgresVolumesSpec struct {
535535
// +optional
536536
Temp *v1beta1.VolumeClaimSpec `json:"temp,omitempty"`
537537

538-
// TODO: Update when v1beta1 is worked out
539-
// Additional volumes to add to the pod.
538+
// Additional pre-existing volumes to add to the pod.
540539
// ---
541540
// +optional
542541
// +listType=map
543542
// +listMapKey=name
544543
// +kubebuilder:validation:MaxItems=10
545-
// // +kubebuilder:validation:items:XValidation:rule=`[has(self.claimName), has(self.claimTemplate)].filter(x, x).size() <= 1`,message=`can only have one of claimName, claimTemplate`
546544
Additional []*v1beta1.AdditionalVolume `json:"additional,omitempty"`
547545
}
548546

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -532,42 +532,33 @@ type PostgresVolumesSpec struct {
532532
// +optional
533533
Temp *VolumeClaimSpec `json:"temp,omitempty"`
534534

535-
// These CRD xvalidation rules were over the complexity budget
536-
// so I turned them off -- what's wrong here
537-
// Additional volumes to add to the pod.
535+
// Additional pre-existing volumes to add to the pod.
538536
// ---
539537
// +optional
540538
// +listType=map
541539
// +listMapKey=name
542-
// +kubebuilder:validation:MaxItems=1
543-
// // +kubebuilder:validation:items:XValidation:rule=`[has(self.claimName), has(self.claimTemplate)].filter(x, x).size() <= 1`,message=`can only have one of claimName, claimTemplate`
544-
// // +kubebuilder:validation:items:XValidation:rule=`has(oldSelf.claimTemplate) != has(self.claimTemplate)`,message=`testing`
540+
// +kubebuilder:validation:MaxItems=10
545541
Additional []*AdditionalVolume `json:"additional,omitempty"`
546542
}
547543

548544
type AdditionalVolume struct {
549545
// The name of the volume used for mounting path.
546+
// Volumes are mounted in the pods at `volumes/<NAME>`
550547
// Must be unique.
551548
// ---
549+
// The `Name` field is a `DNS1123Subdomain` type to enforce
550+
// the max length and also allow us to more easily transition
551+
// to CPK-provisioned volumes.
552552
// +kubebuilder:validation:Required
553-
// TODO: CHANGE THE MAX LENGTH
554-
// +kubebuilder:validation:MaxLength=10
555553
Name DNS1123Subdomain `json:"name,omitempty"`
556554

557555
// A reference to a preexisting PVC.
558556
// ---
559-
// +optional
560-
// TODO: CHANGE THE MAX LENGTH
561-
// +kubebuilder:validation:MaxLength=10
562-
// // +kubebuilder:validation:XValidation:rule=`self == oldSelf`,message="immutable"
557+
// +kubebuilder:validation:Required
563558
ClaimName string `json:"claimName,omitempty"`
564559

565-
// A PVC request.
566-
// ---
567-
// +optional
568-
ClaimTemplate *VolumeClaimSpec `json:"claimTemplate,omitempty"`
569-
570560
// The containers to attach this volume to.
561+
// A blank/unset `Containers` field matches all containers.
571562
// ---
572563
// +optional
573564
// +listType=set

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

Lines changed: 0 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)

AltStyle によって変換されたページ (->オリジナル) /