Skip to content

Commit 92cadfb

Browse files
armrumnencia
andauthored
fix(plugin,status): display "Disabled" for skipWalArchiving annotation (#9709)
The status command now correctly shows "Disabled" instead of "Starting Up" when a cluster has the cnpg.io/skipWalArchiving annotation enabled. Closes #9692 Signed-off-by: Armando Ruocco <[email protected]> Signed-off-by: Marco Nenciarini <[email protected]> Co-authored-by: Marco Nenciarini <[email protected]>
1 parent f272887 commit 92cadfb

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

‎internal/cmd/plugin/status/status.go‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,14 @@ func (fullStatus *PostgresqlStatus) printWALArchivingStatus(status *tabby.Tabby)
630630
status.AddLine("No Primary instance found")
631631
return
632632
}
633+
isWalArchivingDisabled := fullStatus.Cluster != nil &&
634+
utils.IsWalArchivingDisabled(&fullStatus.Cluster.ObjectMeta)
635+
633636
status.AddLine("Working WAL archiving:",
634-
getWalArchivingStatus(primaryInstanceStatus.IsArchivingWAL, primaryInstanceStatus.LastFailedWAL))
637+
getWalArchivingStatus(
638+
primaryInstanceStatus.IsArchivingWAL,
639+
primaryInstanceStatus.LastFailedWAL,
640+
isWalArchivingDisabled))
635641
status.AddLine("WALs waiting to be archived:", primaryInstanceStatus.ReadyWALFiles)
636642

637643
if primaryInstanceStatus.LastArchivedWAL == "" {
@@ -648,8 +654,10 @@ func (fullStatus *PostgresqlStatus) printWALArchivingStatus(status *tabby.Tabby)
648654
}
649655
}
650656

651-
func getWalArchivingStatus(isArchivingWAL bool, lastFailedWAL string) string {
657+
func getWalArchivingStatus(isArchivingWAL bool, lastFailedWAL string, isWalArchivingDisabled bool) string {
652658
switch {
659+
case isWalArchivingDisabled:
660+
return aurora.Yellow("Disabled").String()
653661
case isArchivingWAL:
654662
return aurora.Green("OK").String()
655663
case lastFailedWAL != "":

‎internal/cmd/plugin/status/status_test.go‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,36 @@ var _ = Describe("getPrimaryPromotionTime", func() {
7979
})
8080
})
8181
})
82+
83+
var _ = Describe("getWalArchivingStatus", func() {
84+
It("should return 'Disabled' when WAL archiving is disabled", func() {
85+
result := getWalArchivingStatus(false, "", true)
86+
Expect(result).To(ContainSubstring("Disabled"))
87+
})
88+
89+
It("should return 'OK' when archiving is working", func() {
90+
result := getWalArchivingStatus(true, "", false)
91+
Expect(result).To(ContainSubstring("OK"))
92+
})
93+
94+
It("should return 'Failing' when there is a failed WAL", func() {
95+
result := getWalArchivingStatus(false, "000000010000000000000001", false)
96+
Expect(result).To(ContainSubstring("Failing"))
97+
})
98+
99+
It("should return 'OK' even when there is a failed WAL if archiving is working", func() {
100+
result := getWalArchivingStatus(true, "000000010000000000000001", false)
101+
Expect(result).To(ContainSubstring("OK"))
102+
})
103+
104+
It("should return 'Starting Up' when archiving hasn't started yet", func() {
105+
result := getWalArchivingStatus(false, "", false)
106+
Expect(result).To(ContainSubstring("Starting Up"))
107+
})
108+
109+
It("should prioritize 'Disabled' over other statuses", func() {
110+
// Even if archiving is working, disabled should take precedence
111+
result := getWalArchivingStatus(true, "", true)
112+
Expect(result).To(ContainSubstring("Disabled"))
113+
})
114+
})

0 commit comments

Comments
 (0)