Skip to content

Commit ff909ee

Browse files
authored
set node status before remove node (#645)
* set node status before remove node * fix metric help message * fix UT issue
1 parent b9632e7 commit ff909ee

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

cluster/calcium/node.go

+6
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ func (c *Calcium) RemoveNode(ctx context.Context, nodename string) error {
8787
return utils.Txn(ctx,
8888
// if: remove node metadata
8989
func(ctx context.Context) error {
90+
// we need set node status here, consider the following scenery:
91+
// the node is down, so the node status doesn't exist in ETCD,
92+
// if we don't set node status here, other core instances will not be notified when the node is removed
93+
if err = c.store.SetNodeStatus(ctx, node, 90); err != nil {
94+
logger.Warnf(ctx, "failed to set node status: %s", err)
95+
}
9096
if err := c.store.RemoveNode(ctx, node); err != nil {
9197
return err
9298
}

cluster/calcium/node_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,14 @@ func TestRemoveNode(t *testing.T) {
9090

9191
// fail by store.RemoveNode
9292
store.On("ListNodeWorkloads", mock.Anything, mock.Anything, mock.Anything).Return([]*types.Workload{}, nil)
93+
store.On("SetNodeStatus", mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
9394
store.On("RemoveNode", mock.Anything, mock.Anything).Return(types.ErrMockError).Once()
9495
assert.Error(t, c.RemoveNode(ctx, name))
9596

9697
// success
98+
store.On("SetNodeStatus", mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
9799
store.On("RemoveNode", mock.Anything, mock.Anything).Return(nil)
98-
store.On("SetNodeStatus", mock.Anything, mock.Anything, int64(-1)).Return(nil)
100+
store.On("SetNodeStatus", mock.Anything, mock.Anything, int64(-1)).Return(nil).Once()
99101
rmgr := c.rmgr.(*resourcemocks.Manager)
100102
rmgr.On("RemoveNode", mock.Anything, mock.Anything).Return(nil)
101103
assert.NoError(t, c.RemoveNode(ctx, name))

metrics/metrics.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func InitMetrics(ctx context.Context, config types.Config, metricsDescriptions [
225225

226226
Client.Collectors[podNodeStatusName] = prometheus.NewGaugeVec(prometheus.GaugeOpts{
227227
Name: podNodeStatusName,
228-
Help: "number of up nodes",
228+
Help: "node status",
229229
}, []string{"hostname", "podname", "nodename"})
230230

231231
once.Do(func() {

0 commit comments

Comments
 (0)