-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lint #520
lint #520
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,40 @@ func (c *Calcium) GetNode(ctx context.Context, nodename string) (*types.Node, er | |
return node, logger.Err(ctx, errors.WithStack(err)) | ||
} | ||
|
||
func (c *Calcium) setAllWorkloadsOnNodeDown(ctx context.Context, nodename string) { | ||
workloads, err := c.store.ListNodeWorkloads(ctx, nodename, nil) | ||
if err != nil { | ||
log.Errorf(ctx, "[setAllWorkloadsOnNodeDown] failed to list node workloads, node %v, err: %v", nodename, errors.WithStack(err)) | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 需要注意一下这里跟之前的行为是不一样的,之前ListNodeWorkloads报错是会直接return err,在这里并不会阻塞后续SetNode的各种行为。我觉得这里的似乎更合理一些,但是我不一定对(逃 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我倒是关心如果 set workloads down 里出错, 恐怕很难及时知道. |
||
} | ||
|
||
for _, workload := range workloads { | ||
appname, entrypoint, _, err := utils.ParseWorkloadName(workload.Name) | ||
if err != nil { | ||
log.Errorf(ctx, "[setAllWorkloadsOnNodeDown] Set workload %s on node %s as inactive failed %v", workload.ID, nodename, err) | ||
continue | ||
} | ||
|
||
if workload.StatusMeta == nil { | ||
workload.StatusMeta = &types.StatusMeta{ID: workload.ID} | ||
} | ||
workload.StatusMeta.Running = false | ||
workload.StatusMeta.Healthy = false | ||
|
||
// Set these attributes to set workload status | ||
workload.StatusMeta.Appname = appname | ||
workload.StatusMeta.Nodename = workload.Nodename | ||
workload.StatusMeta.Entrypoint = entrypoint | ||
|
||
// mark workload which belongs to this node as unhealthy | ||
if err = c.store.SetWorkloadStatus(ctx, workload.StatusMeta, 0); err != nil { | ||
log.Errorf(ctx, "[SetNodeAvailable] Set workload %s on node %s as inactive failed %v", workload.ID, nodename, errors.WithStack(err)) | ||
} else { | ||
log.Infof(ctx, "[SetNodeAvailable] Set workload %s on node %s as inactive", workload.ID, nodename) | ||
} | ||
} | ||
} | ||
|
||
// SetNode set node available or not | ||
func (c *Calcium) SetNode(ctx context.Context, opts *types.SetNodeOptions) (*types.Node, error) { // nolint | ||
logger := log.WithField("Calcium", "SetNode").WithField("opts", opts) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 借个楼,L102(原L68)这句litter.Dump要不要留着?看着挺实用的。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 留着吧 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 好像 litter.Dump 是 pretty print? 要不要改成打印成单行的日志, 这样 grep 和查询都更好一点. |
||
|
@@ -82,35 +116,7 @@ func (c *Calcium) SetNode(ctx context.Context, opts *types.SetNodeOptions) (*typ | |
} | ||
} | ||
if opts.WorkloadsDown { | ||
workloads, err := c.store.ListNodeWorkloads(ctx, opts.Nodename, nil) | ||
if err != nil { | ||
return logger.Err(ctx, errors.WithStack(err)) | ||
} | ||
for _, workload := range workloads { | ||
appname, entrypoint, _, err := utils.ParseWorkloadName(workload.Name) | ||
if err != nil { | ||
log.Errorf(ctx, "[SetNodeAvailable] Set workload %s on node %s inactive failed %v", workload.ID, opts.Nodename, err) | ||
continue | ||
} | ||
|
||
if workload.StatusMeta == nil { | ||
workload.StatusMeta = &types.StatusMeta{ID: workload.ID} | ||
} | ||
workload.StatusMeta.Running = false | ||
workload.StatusMeta.Healthy = false | ||
|
||
// Set these attributes to set workload status | ||
workload.StatusMeta.Appname = appname | ||
workload.StatusMeta.Nodename = workload.Nodename | ||
workload.StatusMeta.Entrypoint = entrypoint | ||
|
||
// mark workload which belongs to this node as unhealthy | ||
if err = c.store.SetWorkloadStatus(ctx, workload.StatusMeta, 0); err != nil { | ||
log.Errorf(ctx, "[SetNodeAvailable] Set workload %s on node %s as inactive failed %v", workload.ID, opts.Nodename, errors.WithStack(err)) | ||
} else { | ||
log.Infof(ctx, "[SetNodeAvailable] Set workload %s on node %s as inactive", workload.ID, opts.Nodename) | ||
} | ||
} | ||
c.setAllWorkloadsOnNodeDown(ctx, opts.Nodename) | ||
} | ||
// update node endpoint | ||
if opts.Endpoint != "" { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里没有返回error,感觉没必要,因为不想因为这里的error就终止SetNode的其它操作,而且该打的错误日志在里面也都打过了。不过看起来不太好看
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你指的是 workload 的后续 mark down 操作么
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不是,是SetNode后面的修改metadata的其它操作
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node_test.go里改了个测试用例,就是ListNodeWorkloads报错不会影响node本身metadata的更新