From 6cb762ed18d6f94b43a112d1f6eac89c3ee5d739 Mon Sep 17 00:00:00 2001 From: jmckulk Date: Tue, 16 Sep 2025 15:39:24 -0400 Subject: [PATCH 1/2] Update pgWAL autogrow events to warnings WAL volumes growing could indicate an issue with backups that needs to be addressed. This event should be presented to users as a warning. --- .../controller/postgrescluster/autogrow.go | 13 +++++++++--- .../postgrescluster/autogrow_test.go | 20 +++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/internal/controller/postgrescluster/autogrow.go b/internal/controller/postgrescluster/autogrow.go index 6abe380c06..f06cd78ebe 100644 --- a/internal/controller/postgrescluster/autogrow.go +++ b/internal/controller/postgrescluster/autogrow.go @@ -63,7 +63,11 @@ func (r *Reconciler) storeDesiredRequest( } if limitSet && current.Value() > previous.Value() { - r.Recorder.Eventf(cluster, corev1.EventTypeNormal, "VolumeAutoGrow", + eventType := corev1.EventTypeNormal + if volumeType == "pgWAL" { + eventType = corev1.EventTypeWarning + } + r.Recorder.Eventf(cluster, eventType, "VolumeAutoGrow", "%s volume expansion to %v requested for %s/%s.", volumeType, current.String(), cluster.Name, host) } @@ -165,8 +169,11 @@ func (r *Reconciler) setVolumeSize(ctx context.Context, cluster *v1beta1.Postgre // If the user manually requests a lower limit that is smaller than the current // or requested volume size, it will be ignored in favor of the limit value. if volumeRequestSize.Value() >= volumeLimitFromSpec.Value() { - - r.Recorder.Eventf(cluster, corev1.EventTypeNormal, "VolumeLimitReached", + eventType := corev1.EventTypeNormal + if volumeType == "pgWAL" { + eventType = corev1.EventTypeWarning + } + r.Recorder.Eventf(cluster, eventType, "VolumeLimitReached", "%s volume(s) for %s/%s are at size limit (%v).", volumeType, cluster.Name, host, volumeLimitFromSpec) diff --git a/internal/controller/postgrescluster/autogrow_test.go b/internal/controller/postgrescluster/autogrow_test.go index e276e60a19..180bd49084 100644 --- a/internal/controller/postgrescluster/autogrow_test.go +++ b/internal/controller/postgrescluster/autogrow_test.go @@ -101,6 +101,7 @@ func TestStoreDesiredRequest(t *testing.T) { expectedLog string expectedNumEvents int expectedEvent string + expectedEventType string }{{ tcName: "PGData-BadRequestNoBackup", Voltype: "pgData", host: "red", @@ -122,13 +123,13 @@ func TestStoreDesiredRequest(t *testing.T) { tcName: "PGData-BadBackupRequest", Voltype: "pgData", host: "red", desiredRequest: "2Gi", desiredRequestBackup: "bar", expectedValue: "2Gi", - expectedNumEvents: 1, expectedEvent: "pgData volume expansion to 2Gi requested for rhino/red.", + expectedNumEvents: 1, expectedEvent: "pgData volume expansion to 2Gi requested for rhino/red.", expectedEventType: corev1.EventTypeNormal, expectedNumLogs: 1, expectedLog: "Unable to parse pgData volume request from status backup (bar) for rhino/red", }, { tcName: "PGData-ValueUpdateWithEvent", Voltype: "pgData", host: "red", desiredRequest: "1Gi", desiredRequestBackup: "", expectedValue: "1Gi", - expectedNumEvents: 1, expectedEvent: "pgData volume expansion to 1Gi requested for rhino/red.", + expectedNumEvents: 1, expectedEvent: "pgData volume expansion to 1Gi requested for rhino/red.", expectedEventType: corev1.EventTypeNormal, expectedNumLogs: 0, }, { tcName: "PGWAL-BadRequestNoBackup", @@ -156,13 +157,13 @@ func TestStoreDesiredRequest(t *testing.T) { tcName: "PGWAL-BadBackupRequest", Voltype: "pgWAL", host: "red", desiredRequest: "2Gi", desiredRequestBackup: "bar", expectedValue: "2Gi", - expectedNumEvents: 1, expectedEvent: "pgWAL volume expansion to 2Gi requested for rhino/red.", + expectedNumEvents: 1, expectedEvent: "pgWAL volume expansion to 2Gi requested for rhino/red.", expectedEventType: corev1.EventTypeWarning, expectedNumLogs: 1, expectedLog: "Unable to parse pgWAL volume request from status backup (bar) for rhino/red", }, { tcName: "PGWAL-ValueUpdateWithEvent", Voltype: "pgWAL", host: "red", desiredRequest: "1Gi", desiredRequestBackup: "", expectedValue: "1Gi", - expectedNumEvents: 1, expectedEvent: "pgWAL volume expansion to 1Gi requested for rhino/red.", + expectedNumEvents: 1, expectedEvent: "pgWAL volume expansion to 1Gi requested for rhino/red.", expectedEventType: corev1.EventTypeWarning, expectedNumLogs: 0, }, { tcName: "Repo-BadRequestNoBackup", @@ -190,13 +191,13 @@ func TestStoreDesiredRequest(t *testing.T) { tcName: "Repo-BadBackupRequest", Voltype: "repo1", host: "repo-host", desiredRequest: "2Gi", desiredRequestBackup: "bar", expectedValue: "2Gi", - expectedNumEvents: 1, expectedEvent: "repo1 volume expansion to 2Gi requested for rhino/repo-host.", + expectedNumEvents: 1, expectedEvent: "repo1 volume expansion to 2Gi requested for rhino/repo-host.", expectedEventType: corev1.EventTypeNormal, expectedNumLogs: 1, expectedLog: "Unable to parse repo1 volume request from status backup (bar) for rhino/repo-host", }, { tcName: "Repo-ValueUpdateWithEvent", Voltype: "repo1", host: "repo-host", desiredRequest: "1Gi", desiredRequestBackup: "", expectedValue: "1Gi", - expectedNumEvents: 1, expectedEvent: "repo1 volume expansion to 1Gi requested for rhino/repo-host.", + expectedNumEvents: 1, expectedEvent: "repo1 volume expansion to 1Gi requested for rhino/repo-host.", expectedEventType: corev1.EventTypeNormal, expectedNumLogs: 0, }} @@ -220,6 +221,7 @@ func TestStoreDesiredRequest(t *testing.T) { assert.Equal(t, recorder.Events[0].Regarding.Name, cluster.Name) assert.Equal(t, recorder.Events[0].Reason, "VolumeAutoGrow") assert.Equal(t, recorder.Events[0].Note, tc.expectedEvent) + assert.Equal(t, recorder.Events[0].Type, tc.expectedEventType) } assert.Equal(t, len(*logs), tc.expectedNumLogs) if tc.expectedNumLogs == 1 { @@ -430,6 +432,7 @@ resources: assert.Equal(t, len(recorder.Events), 1) assert.Equal(t, recorder.Events[0].Regarding.Name, cluster.Name) assert.Equal(t, recorder.Events[0].Reason, "VolumeRequestOverLimit") + assert.Equal(t, recorder.Events[0].Type, corev1.EventTypeWarning) assert.Equal(t, recorder.Events[0].Note, "pgData volume request (4Gi) for elephant/some-instance is greater than set limit (3Gi). Limit value will be used.") }) @@ -599,6 +602,7 @@ resources: assert.Equal(t, len(recorder.Events), 1) assert.Equal(t, recorder.Events[0].Regarding.Name, cluster.Name) assert.Equal(t, recorder.Events[0].Reason, "VolumeLimitReached") + assert.Equal(t, recorder.Events[0].Type, corev1.EventTypeNormal) assert.Equal(t, recorder.Events[0].Note, "pgData volume(s) for elephant/some-instance are at size limit (2Gi).") }) @@ -629,11 +633,13 @@ resources: if event.Reason == "VolumeLimitReached" { found1 = true assert.Equal(t, event.Regarding.Name, cluster.Name) + assert.Equal(t, event.Type, corev1.EventTypeNormal) assert.Equal(t, event.Note, "pgData volume(s) for elephant/some-instance are at size limit (5Gi).") } if event.Reason == "DesiredVolumeAboveLimit" { found2 = true assert.Equal(t, event.Regarding.Name, cluster.Name) + assert.Equal(t, event.Type, corev1.EventTypeWarning) assert.Equal(t, event.Note, "The desired size (10Gi) for the elephant/some-instance pgData volume(s) is greater than the size limit (5Gi).") } @@ -675,6 +681,7 @@ resources: assert.Equal(t, len(recorder.Events), 1) assert.Equal(t, recorder.Events[0].Regarding.Name, cluster.Name) assert.Equal(t, recorder.Events[0].Reason, "VolumeLimitReached") + assert.Equal(t, recorder.Events[0].Type, corev1.EventTypeNormal) assert.Equal(t, recorder.Events[0].Note, "repo1 volume(s) for elephant/repo-host are at size limit (2Gi).") }) @@ -707,6 +714,7 @@ resources: assert.Equal(t, len(recorder.Events), 1) assert.Equal(t, recorder.Events[0].Regarding.Name, cluster.Name) assert.Equal(t, recorder.Events[0].Reason, "VolumeLimitReached") + assert.Equal(t, recorder.Events[0].Type, corev1.EventTypeWarning) assert.Equal(t, recorder.Events[0].Note, "pgWAL volume(s) for elephant/another-instance are at size limit (3Gi).") }) From f253d4b44940e83f1d09b159a756ab2ee59fdede Mon Sep 17 00:00:00 2001 From: jmckulk Date: Tue, 16 Sep 2025 15:40:41 -0400 Subject: [PATCH 2/2] Preserve path when clearing environment Unsetting PATH could lead to issues in some environments (nix) where tools (mktemp) aren't in a standard location. Keep path to avoid issues --- internal/postgres/config_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/postgres/config_test.go b/internal/postgres/config_test.go index cd4962be79..53bcfc1bf1 100644 --- a/internal/postgres/config_test.go +++ b/internal/postgres/config_test.go @@ -256,7 +256,10 @@ func TestBashRecreateDirectory(t *testing.T) { filepath.Join(dir, "d"), "0740") // The assertion below expects alphabetically sorted filenames. // Set an empty environment to always use the default/standard locale. - cmd.Env = []string{} + cmd.Env = []string{ + // Preserve the path to find bash tools (i.e., mktemp) + "PATH=" + os.Getenv("PATH"), + } output, err := cmd.CombinedOutput() assert.NilError(t, err, string(output)) assert.Assert(t, cmp.Regexp(`^`+