Skip to content

Commit

Permalink
Fix linter error. Add test case for tablespaces and snapshots both be…
Browse files Browse the repository at this point in the history
…ing enabled.
  • Loading branch information
dsessler7 committed Oct 2, 2024
1 parent ce3c922 commit 2033618
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/controller/postgrescluster/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ func (r *Reconciler) deleteSnapshots(ctx context.Context,
// cluster has tablespace volumes in place.
func clusterUsingTablespaces(ctx context.Context, postgrescluster *v1beta1.PostgresCluster) bool {
for _, instanceSet := range postgrescluster.Spec.InstanceSets {
if instanceSet.TablespaceVolumes != nil && len(instanceSet.TablespaceVolumes) > 0 {
if len(instanceSet.TablespaceVolumes) > 0 {
return feature.Enabled(ctx, feature.TablespaceVolumes)
}
}
Expand Down
39 changes: 39 additions & 0 deletions internal/controller/postgrescluster/snapshots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ func TestReconcileVolumeSnapshots(t *testing.T) {
discoveryClient, err := discovery.NewDiscoveryClientForConfig(cfg)
assert.NilError(t, err)

recorder := record.NewFakeRecorder(100)
r := &Reconciler{
Client: cc,
Owner: client.FieldOwner(t.Name()),
DiscoveryClient: discoveryClient,
Recorder: recorder,
}
ns := setupNamespace(t, cc)

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

t.Run("SnapshotsEnabledTablespacesEnabled", func(t *testing.T) {
// Enable snapshots feature gate
gate := feature.NewGate()
assert.NilError(t, gate.SetFromMap(map[string]bool{
feature.VolumeSnapshots: true,
feature.TablespaceVolumes: true,
}))
ctx := feature.NewContext(ctx, gate)

// Create a cluster with snapshots and tablespaces enabled
volumeSnapshotClassName := "my-snapshotclass"
cluster := testCluster()
cluster.Namespace = ns.Name
cluster.Spec.Backups.Snapshots = &v1beta1.VolumeSnapshots{
VolumeSnapshotClassName: volumeSnapshotClassName,
}
cluster.Spec.InstanceSets[0].TablespaceVolumes = []v1beta1.TablespaceVolume{{
Name: "volume-1",
}}

// Create pvc for reconcile
pvc := &corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: "dedicated-snapshot-volume",
},
}

// Reconcile
err = r.reconcileVolumeSnapshots(ctx, cluster, pvc)
assert.NilError(t, err)

// Assert warning event was created
event, ok := <-recorder.Events
assert.Equal(t, ok, true)
assert.Assert(t, cmp.Contains(event, "IncompatibleFeatures"))
})

t.Run("SnapshotsEnabledNoPvcAnnotation", func(t *testing.T) {
// Enable snapshots feature gate
gate := feature.NewGate()
Expand Down

0 comments on commit 2033618

Please sign in to comment.