Skip to content

Commit 2033618

Browse files
committed
Fix linter error. Add test case for tablespaces and snapshots both being enabled.
1 parent ce3c922 commit 2033618

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

internal/controller/postgrescluster/snapshots.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ func (r *Reconciler) deleteSnapshots(ctx context.Context,
602602
// cluster has tablespace volumes in place.
603603
func clusterUsingTablespaces(ctx context.Context, postgrescluster *v1beta1.PostgresCluster) bool {
604604
for _, instanceSet := range postgrescluster.Spec.InstanceSets {
605-
if instanceSet.TablespaceVolumes != nil && len(instanceSet.TablespaceVolumes) > 0 {
605+
if len(instanceSet.TablespaceVolumes) > 0 {
606606
return feature.Enabled(ctx, feature.TablespaceVolumes)
607607
}
608608
}

internal/controller/postgrescluster/snapshots_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ func TestReconcileVolumeSnapshots(t *testing.T) {
3838
discoveryClient, err := discovery.NewDiscoveryClientForConfig(cfg)
3939
assert.NilError(t, err)
4040

41+
recorder := record.NewFakeRecorder(100)
4142
r := &Reconciler{
4243
Client: cc,
4344
Owner: client.FieldOwner(t.Name()),
4445
DiscoveryClient: discoveryClient,
46+
Recorder: recorder,
4547
}
4648
ns := setupNamespace(t, cc)
4749

@@ -93,6 +95,43 @@ func TestReconcileVolumeSnapshots(t *testing.T) {
9395
assert.Equal(t, len(snapshots.Items), 0)
9496
})
9597

98+
t.Run("SnapshotsEnabledTablespacesEnabled", func(t *testing.T) {
99+
// Enable snapshots feature gate
100+
gate := feature.NewGate()
101+
assert.NilError(t, gate.SetFromMap(map[string]bool{
102+
feature.VolumeSnapshots: true,
103+
feature.TablespaceVolumes: true,
104+
}))
105+
ctx := feature.NewContext(ctx, gate)
106+
107+
// Create a cluster with snapshots and tablespaces enabled
108+
volumeSnapshotClassName := "my-snapshotclass"
109+
cluster := testCluster()
110+
cluster.Namespace = ns.Name
111+
cluster.Spec.Backups.Snapshots = &v1beta1.VolumeSnapshots{
112+
VolumeSnapshotClassName: volumeSnapshotClassName,
113+
}
114+
cluster.Spec.InstanceSets[0].TablespaceVolumes = []v1beta1.TablespaceVolume{{
115+
Name: "volume-1",
116+
}}
117+
118+
// Create pvc for reconcile
119+
pvc := &corev1.PersistentVolumeClaim{
120+
ObjectMeta: metav1.ObjectMeta{
121+
Name: "dedicated-snapshot-volume",
122+
},
123+
}
124+
125+
// Reconcile
126+
err = r.reconcileVolumeSnapshots(ctx, cluster, pvc)
127+
assert.NilError(t, err)
128+
129+
// Assert warning event was created
130+
event, ok := <-recorder.Events
131+
assert.Equal(t, ok, true)
132+
assert.Assert(t, cmp.Contains(event, "IncompatibleFeatures"))
133+
})
134+
96135
t.Run("SnapshotsEnabledNoPvcAnnotation", func(t *testing.T) {
97136
// Enable snapshots feature gate
98137
gate := feature.NewGate()

0 commit comments

Comments
 (0)