Skip to content

Commit 5ee34a4

Browse files
committed
rpk: add maintenance node status to cluster health
Use cl.Brokers() to check maintenance status across all nodes and surface draining nodes in `rpk cluster health` output.
1 parent efbcf9a commit 5ee34a4

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

src/go/rpk/pkg/cli/cluster/health.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type healthResponse struct {
3232
ControllerID int `json:"controller_id" yaml:"controller_id"`
3333
AllNodes []int `json:"all_nodes" yaml:"all_nodes"`
3434
NodesDown []int `json:"nodes_down" yaml:"nodes_down"`
35+
NodesInMaintenance []int `json:"nodes_in_maintenance" yaml:"nodes_in_maintenance"`
3536
NodesInRecoveryMode []int `json:"nodes_in_recovery_mode" yaml:"nodes_in_recovery_mode"`
3637
LeaderlessPartitions []string `json:"leaderless_partitions" yaml:"leaderless_partitions"`
3738
LeaderlessCount *int `json:"leaderless_count,omitempty" yaml:"leaderless_count,omitempty"`
@@ -99,8 +100,12 @@ Get cluster health information and exit when the cluster is healthy:
99100
ret, err := cl.GetHealthOverview(cmd.Context())
100101
out.MaybeDie(err, "unable to request cluster health: %v", err)
101102
exit10 = !ret.IsHealthy
103+
brokers, err := cl.Brokers(cmd.Context())
104+
if err != nil {
105+
zap.L().Sugar().Warnf("unable to get broker list for maintenance status: %v; skipping maintenance status", err)
106+
}
102107
if !reflect.DeepEqual(ret, lastOverview) {
103-
hr := buildHealthResponses(&ret, clusterUUID)
108+
hr := buildHealthResponses(&ret, brokers, clusterUUID)
104109
if isText, _, s, err := f.Format(hr); !isText {
105110
out.MaybeDie(err, "unable to print in the required format %q: %v", f.Kind, err)
106111
fmt.Println(s)
@@ -130,20 +135,30 @@ Get cluster health information and exit when the cluster is healthy:
130135
return cmd
131136
}
132137

133-
func buildHealthResponses(hov *rpadmin.ClusterHealthOverview, clusterUUID *string) healthResponse {
138+
func buildHealthResponses(hov *rpadmin.ClusterHealthOverview, brokers []rpadmin.Broker, clusterUUID *string) healthResponse {
134139
// This is needed as NodesInRecoveryMode can be nil, and the json formatter
135140
// will print "null" instead of an empty array.
136141
nodesInRecoveryMode := hov.NodesInRecoveryMode
137142
if len(nodesInRecoveryMode) == 0 {
138143
nodesInRecoveryMode = []int{}
139144
}
145+
var nodesInMaintenance []int
146+
for _, b := range brokers {
147+
if b.Maintenance != nil && b.Maintenance.Draining {
148+
nodesInMaintenance = append(nodesInMaintenance, b.NodeID)
149+
}
150+
}
151+
if len(nodesInMaintenance) == 0 {
152+
nodesInMaintenance = []int{}
153+
}
140154
return healthResponse{
141155
ClusterUUID: clusterUUID,
142156
IsHealthy: hov.IsHealthy,
143157
UnhealthyReasons: hov.UnhealthyReasons,
144158
ControllerID: hov.ControllerID,
145159
AllNodes: hov.AllNodes,
146160
NodesDown: hov.NodesDown,
161+
NodesInMaintenance: nodesInMaintenance,
147162
NodesInRecoveryMode: nodesInRecoveryMode,
148163
LeaderlessPartitions: hov.LeaderlessPartitions,
149164
LeaderlessCount: hov.LeaderlessCount,
@@ -181,6 +196,9 @@ func printHealthOverview(hr healthResponse) {
181196
tw.Print("Controller ID:", hr.ControllerID)
182197
tw.Print("All nodes:", hr.AllNodes)
183198
tw.Print("Nodes down:", hr.NodesDown)
199+
if len(hr.NodesInMaintenance) > 0 {
200+
tw.Print("Nodes in maintenance:", hr.NodesInMaintenance)
201+
}
184202
if hr.NodesInRecoveryMode != nil {
185203
tw.Print("Nodes in recovery mode:", hr.NodesInRecoveryMode)
186204
}

0 commit comments

Comments
 (0)