add resources requests and limits to nodePoolOptions

This commit is contained in:
rushtehrani
2020-07-02 22:29:05 -07:00
parent 18428c4e82
commit 2868ab69c9
4 changed files with 133 additions and 81 deletions

View File

@@ -104,6 +104,7 @@ func injectArtifactRepositoryConfig(artifact *wfv1.Artifact, namespaceConfig *Na
}
}
// injectNvidiaGPUFields adds GPU specific fields if there is a GPU request
func injectNvidiaGPUFields(template *wfv1.Template, systemConfig SystemConfig) {
limitsGPUCount := template.Container.Resources.Limits["nvidia.com/gpu"]
requestsGPUCount := template.Container.Resources.Requests["nvidia.com/gpu"]
@@ -129,6 +130,29 @@ func injectNvidiaGPUFields(template *wfv1.Template, systemConfig SystemConfig) {
}
}
// injectNodeSelectorResources adds resource requests and limits if they exist
func injectNodeSelectorResources(template *wfv1.Template, systemConfig SystemConfig) {
if template.NodeSelector == nil {
return
}
var (
option *NodePoolOption
err error
)
for k, v := range template.NodeSelector {
if k == *systemConfig.NodePoolLabel() {
option, err = systemConfig.NodePoolOptionByValue(v)
if err != nil {
return
}
}
}
if option != nil && (option.Resources.Requests != nil || option.Resources.Limits != nil) {
template.Container.Resources = option.Resources
}
}
func (c *Client) injectAutomatedFields(namespace string, wf *wfv1.Workflow, opts *WorkflowExecutionOptions) (err error) {
if opts.PodGCStrategy == nil {
if wf.Spec.PodGC == nil {
@@ -209,6 +233,7 @@ func (c *Client) injectAutomatedFields(namespace string, wf *wfv1.Workflow, opts
template.Inputs.Artifacts[j] = artifact
}
injectNodeSelectorResources(template, systemConfig)
injectNvidiaGPUFields(template, systemConfig)
//Generate ENV vars from secret, if there is a container present in the workflow