Skip to content

Commit 025b572

Browse files
committed
Stop checking that "pgbackrest-cloud-log-volume" PVC exists
1 parent 35b8c2b commit 025b572

File tree

4 files changed

+10
-115
lines changed

4 files changed

+10
-115
lines changed

internal/controller/postgrescluster/pgbackrest.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -884,25 +884,9 @@ func (r *Reconciler) generateBackupJobSpecIntent(ctx context.Context, postgresCl
884884
jobSpec.Template.Spec.SecurityContext = postgres.PodSecurityContext(postgresCluster)
885885
pgbackrest.AddConfigToCloudBackupJob(postgresCluster, &jobSpec.Template)
886886

887-
// If the user has specified a PVC to use as a log volume via the PGBackRestCloudLogVolume
888-
// annotation, check for the PVC. If we find it, mount it to the backup job.
889-
// Otherwise, create a warning event.
887+
// Mount the PVC named in the "pgbackrest-cloud-log-volume" annotation, if any.
890888
if logVolumeName := postgresCluster.Annotations[naming.PGBackRestCloudLogVolume]; logVolumeName != "" {
891-
logVolume := &corev1.PersistentVolumeClaim{
892-
ObjectMeta: metav1.ObjectMeta{
893-
Name: logVolumeName,
894-
Namespace: postgresCluster.GetNamespace(),
895-
},
896-
}
897-
err := errors.WithStack(r.Client.Get(ctx,
898-
client.ObjectKeyFromObject(logVolume), logVolume))
899-
if err != nil {
900-
// PVC not retrieved, create warning event
901-
r.Recorder.Event(postgresCluster, corev1.EventTypeWarning, "PGBackRestCloudLogVolumeNotFound", err.Error())
902-
} else {
903-
// We successfully found the specified PVC, so we will add it to the backup job
904-
util.AddVolumeAndMountsToPod(&jobSpec.Template.Spec, logVolume)
905-
}
889+
util.AddCloudLogVolumeToPod(&jobSpec.Template.Spec, logVolumeName)
906890
}
907891
}
908892

internal/controller/postgrescluster/pgbackrest_test.go

Lines changed: 1 addition & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,96 +2947,14 @@ volumes:
29472947
})
29482948
})
29492949

2950-
t.Run("CloudLogVolumeAnnotationNoPvc", func(t *testing.T) {
2951-
recorder := events.NewRecorder(t, runtime.Scheme)
2952-
r.Recorder = recorder
2953-
2954-
cluster.Namespace = ns.Name
2955-
cluster.Annotations = map[string]string{}
2956-
cluster.Annotations[naming.PGBackRestCloudLogVolume] = "some-pvc"
2957-
spec := r.generateBackupJobSpecIntent(ctx,
2958-
&cluster, v1beta1.PGBackRestRepo{},
2959-
"",
2960-
nil, nil,
2961-
)
2962-
assert.Assert(t, cmp.MarshalMatches(spec.Template.Spec, `
2963-
containers:
2964-
- command:
2965-
- /bin/pgbackrest
2966-
- backup
2967-
- --stanza=db
2968-
- --repo=
2969-
name: pgbackrest
2970-
resources: {}
2971-
securityContext:
2972-
allowPrivilegeEscalation: false
2973-
capabilities:
2974-
drop:
2975-
- ALL
2976-
privileged: false
2977-
readOnlyRootFilesystem: true
2978-
runAsNonRoot: true
2979-
seccompProfile:
2980-
type: RuntimeDefault
2981-
volumeMounts:
2982-
- mountPath: /etc/pgbackrest/conf.d
2983-
name: pgbackrest-config
2984-
readOnly: true
2985-
- mountPath: /tmp
2986-
name: tmp
2987-
enableServiceLinks: false
2988-
restartPolicy: Never
2989-
securityContext:
2990-
fsGroup: 26
2991-
fsGroupChangePolicy: OnRootMismatch
2992-
volumes:
2993-
- name: pgbackrest-config
2994-
projected:
2995-
sources:
2996-
- configMap:
2997-
items:
2998-
- key: pgbackrest_cloud.conf
2999-
path: pgbackrest_cloud.conf
3000-
name: hippo-test-pgbackrest-config
3001-
- secret:
3002-
items:
3003-
- key: pgbackrest.ca-roots
3004-
path: ~postgres-operator/tls-ca.crt
3005-
- key: pgbackrest-client.crt
3006-
path: ~postgres-operator/client-tls.crt
3007-
- key: pgbackrest-client.key
3008-
mode: 384
3009-
path: ~postgres-operator/client-tls.key
3010-
name: hippo-test-pgbackrest
3011-
- emptyDir:
3012-
sizeLimit: 16Mi
3013-
name: tmp
3014-
`))
3015-
3016-
assert.Equal(t, len(recorder.Events), 1)
3017-
assert.Equal(t, recorder.Events[0].Regarding.Name, cluster.Name)
3018-
assert.Equal(t, recorder.Events[0].Reason, "PGBackRestCloudLogVolumeNotFound")
3019-
assert.Equal(t, recorder.Events[0].Note, "persistentvolumeclaims \"some-pvc\" not found")
3020-
})
3021-
3022-
t.Run("CloudLogVolumeAnnotationPvcInPlace", func(t *testing.T) {
2950+
t.Run("CloudLogVolumeAnnotation", func(t *testing.T) {
30232951
recorder := events.NewRecorder(t, runtime.Scheme)
30242952
r.Recorder = recorder
30252953

30262954
cluster.Namespace = ns.Name
30272955
cluster.Annotations = map[string]string{}
30282956
cluster.Annotations[naming.PGBackRestCloudLogVolume] = "another-pvc"
30292957

3030-
pvc := &corev1.PersistentVolumeClaim{
3031-
ObjectMeta: metav1.ObjectMeta{
3032-
Name: "another-pvc",
3033-
Namespace: ns.Name,
3034-
},
3035-
Spec: corev1.PersistentVolumeClaimSpec(testVolumeClaimSpec()),
3036-
}
3037-
err := r.Client.Create(ctx, pvc)
3038-
assert.NilError(t, err)
3039-
30402958
spec := r.generateBackupJobSpecIntent(ctx,
30412959
&cluster, v1beta1.PGBackRestRepo{},
30422960
"",

internal/util/volumes.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ func AddAdditionalVolumesAndMounts(pod *corev1.PodSpec, volumes []v1beta1.Additi
2828
return addVolumesAndMounts(pod, volumes, AdditionalVolumeMount)
2929
}
3030

31-
// AddVolumeAndMountsToPod takes a Pod spec and a PVC and adds a Volume to the Pod spec with
31+
// AddCloudLogVolumeToPod takes a Pod spec and a PVC and adds a Volume to the Pod spec with
3232
// the PVC as the VolumeSource and mounts the volume to all containers and init containers
3333
// in the Pod spec.
34-
func AddVolumeAndMountsToPod(podSpec *corev1.PodSpec, volume *corev1.PersistentVolumeClaim) {
34+
func AddCloudLogVolumeToPod(podSpec *corev1.PodSpec, pvcName string) {
3535
additional := []v1beta1.AdditionalVolume{{
36-
ClaimName: volume.Name,
37-
Name: volume.Name,
36+
ClaimName: pvcName,
37+
Name: pvcName,
3838
ReadOnly: false,
3939
}}
4040

4141
addVolumesAndMounts(podSpec, additional, func(string, bool) corev1.VolumeMount {
4242
return corev1.VolumeMount{
4343
// This name has no prefix and differs from [AdditionalVolumeMount].
44-
Name: volume.Name,
45-
MountPath: fmt.Sprintf("/volumes/%s", volume.Name),
44+
Name: pvcName,
45+
MountPath: fmt.Sprintf("/volumes/%s", pvcName),
4646
ReadOnly: false,
4747
}
4848
})

internal/util/volumes_test.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/google/go-cmp/cmp/cmpopts"
1212
"gotest.tools/v3/assert"
1313
corev1 "k8s.io/api/core/v1"
14-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1514

1615
"github.com/crunchydata/postgres-operator/internal/testing/cmp"
1716
"github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
@@ -237,12 +236,6 @@ func TestAddVolumeAndMountsToPod(t *testing.T) {
237236
},
238237
}
239238

240-
volume := &corev1.PersistentVolumeClaim{
241-
ObjectMeta: metav1.ObjectMeta{
242-
Name: "volume-name",
243-
},
244-
}
245-
246239
alwaysExpect := func(t testing.TB, result *corev1.PodSpec) {
247240
// Only Containers, InitContainers, and Volumes fields have changed.
248241
assert.DeepEqual(t, *pod, *result, cmpopts.IgnoreFields(*pod, "Containers", "InitContainers", "Volumes"))
@@ -282,6 +275,6 @@ func TestAddVolumeAndMountsToPod(t *testing.T) {
282275
}
283276

284277
out := pod.DeepCopy()
285-
AddVolumeAndMountsToPod(out, volume)
278+
AddCloudLogVolumeToPod(out, "volume-name")
286279
alwaysExpect(t, out)
287280
}

0 commit comments

Comments
 (0)