-
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
support excluding nodes when creating workloads #365
Changes from 1 commit
5cf625d
eed9d65
79f01ad
a329a79
90d582b
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 |
---|---|---|
|
@@ -38,6 +38,34 @@ func (c *Calcium) CreateWorkload(ctx context.Context, opts *types.DeployOptions) | |
return c.doCreateWorkloads(ctx, opts), nil | ||
} | ||
|
||
// getDeployNodenames checks nodenames and excludedNodenames | ||
// if excludedNodenames is not set or nodenames is set, then return nodenames | ||
// for other cases, then node within excludedNodename list will not be returned | ||
func (c *Calcium) getDeployNodenames(podname string, nodenames, excludedNodenames []string) ([]string, error) { | ||
if len(excludedNodenames) == 0 || len(nodenames) != 0 { | ||
return nodenames, nil | ||
} | ||
|
||
allNodes, err := c.ListPodNodes(context.Background(), podname, map[string]string{}, false) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
excludes := map[string]struct{}{} | ||
for _, n := range excludedNodenames { | ||
excludes[n] = struct{}{} | ||
} | ||
|
||
rv := []string{} | ||
for _, n := range allNodes { | ||
if _, ok := excludes[n.Name]; ok { | ||
continue | ||
} | ||
rv = append(rv, n.Name) | ||
} | ||
return rv, nil | ||
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. 我觉得你这样不如直接改 withNodeLocks 了 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. 那你不如抽出整个 node 筛选的函数,包括 pod,all,黑名单白名单,withNodeLocks 就当纯粹的锁……现在就很分裂 |
||
} | ||
|
||
// transaction: resource metadata consistency | ||
func (c *Calcium) doCreateWorkloads(ctx context.Context, opts *types.DeployOptions) chan *types.CreateWorkloadMessage { | ||
logger := log.WithField("Calcium", "doCreateWorkloads").WithField("opts", opts) | ||
|
@@ -62,12 +90,18 @@ func (c *Calcium) doCreateWorkloads(ctx context.Context, opts *types.DeployOptio | |
close(ch) | ||
}() | ||
|
||
nodenames, err := c.getDeployNodenames(opts.Podname, opts.Nodenames, opts.ExcludedNodenames) | ||
if err != nil { | ||
ch <- &types.CreateWorkloadMessage{Error: logger.Err(err)} | ||
return | ||
} | ||
|
||
_ = utils.Txn( | ||
ctx, | ||
|
||
// if: alloc resources | ||
func(ctx context.Context) error { | ||
return c.withNodesLocked(ctx, opts.Podname, opts.Nodenames, opts.NodeLabels, false, func(ctx context.Context, nodeMap map[string]*types.Node) (err error) { | ||
return c.withNodesLocked(ctx, opts.Podname, nodenames, opts.NodeLabels, false, func(ctx context.Context, nodeMap map[string]*types.Node) (err error) { | ||
defer func() { | ||
if err != nil { | ||
ch <- &types.CreateWorkloadMessage{Error: logger.Err(err)} | ||
|
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.
ctx ! 不要用 background,另外这个函数为啥在这里,不应该在 helper 么
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.
为了用这个
ListPodNodes
啦