mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-10-05 21:56:50 +08:00
feat: Support script templates in Workflow
This commit is contained in:
@@ -173,10 +173,27 @@ func injectContainerResourceQuotas(wf *wfv1.Workflow, template *wfv1.Template, s
|
|||||||
if option != nil && option.Resources.Limits != nil {
|
if option != nil && option.Resources.Limits != nil {
|
||||||
// If a node is selected specifically, match the resources request to limits
|
// If a node is selected specifically, match the resources request to limits
|
||||||
option.Resources.Requests = option.Resources.Limits
|
option.Resources.Requests = option.Resources.Limits
|
||||||
template.Container.Resources = option.Resources
|
if template.Container != nil {
|
||||||
|
template.Container.Resources = option.Resources
|
||||||
|
}
|
||||||
|
if template.Script != nil {
|
||||||
|
template.Script.Container.Resources = option.Resources
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func injectEnvironmentVariables(container *corev1.Container, systemConfig SystemConfig) {
|
||||||
|
//Generate ENV vars from secret, if there is a container present in the workflow
|
||||||
|
//Get template ENV vars, avoid over-writing them with secret values
|
||||||
|
env.AddDefaultEnvVarsToContainer(container)
|
||||||
|
env.PrependEnvVarToContainer(container, "ONEPANEL_API_URL", systemConfig["ONEPANEL_API_URL"])
|
||||||
|
env.PrependEnvVarToContainer(container, "ONEPANEL_FQDN", systemConfig["ONEPANEL_FQDN"])
|
||||||
|
env.PrependEnvVarToContainer(container, "ONEPANEL_DOMAIN", systemConfig["ONEPANEL_DOMAIN"])
|
||||||
|
env.PrependEnvVarToContainer(container, "ONEPANEL_PROVIDER", systemConfig["ONEPANEL_PROVIDER"])
|
||||||
|
env.PrependEnvVarToContainer(container, "ONEPANEL_RESOURCE_NAMESPACE", "{{workflow.namespace}}")
|
||||||
|
env.PrependEnvVarToContainer(container, "ONEPANEL_RESOURCE_UID", "{{workflow.name}}")
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) injectAutomatedFields(namespace string, wf *wfv1.Workflow, opts *WorkflowExecutionOptions) (err error) {
|
func (c *Client) injectAutomatedFields(namespace string, wf *wfv1.Workflow, opts *WorkflowExecutionOptions) (err error) {
|
||||||
if opts.PodGCStrategy == nil {
|
if opts.PodGCStrategy == nil {
|
||||||
if wf.Spec.PodGC == nil {
|
if wf.Spec.PodGC == nil {
|
||||||
@@ -226,48 +243,46 @@ func (c *Client) injectAutomatedFields(namespace string, wf *wfv1.Workflow, opts
|
|||||||
}
|
}
|
||||||
template.Metadata.Annotations["sidecar.istio.io/inject"] = "false"
|
template.Metadata.Annotations["sidecar.istio.io/inject"] = "false"
|
||||||
|
|
||||||
if template.Container == nil {
|
if template.Container != nil {
|
||||||
continue
|
// Mount dev/shm
|
||||||
|
template.Container.VolumeMounts = append(template.Container.VolumeMounts, corev1.VolumeMount{
|
||||||
|
Name: "sys-dshm",
|
||||||
|
MountPath: "/dev/shm",
|
||||||
|
})
|
||||||
|
|
||||||
|
injectContainerResourceQuotas(wf, template, systemConfig)
|
||||||
|
|
||||||
|
injectEnvironmentVariables(template.Container, systemConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mount dev/shm
|
if template.Script != nil {
|
||||||
template.Container.VolumeMounts = append(template.Container.VolumeMounts, corev1.VolumeMount{
|
injectContainerResourceQuotas(wf, template, systemConfig)
|
||||||
Name: "sys-dshm",
|
|
||||||
MountPath: "/dev/shm",
|
|
||||||
})
|
|
||||||
|
|
||||||
// Always add output artifacts for metrics but make them optional
|
injectEnvironmentVariables(&template.Script.Container, systemConfig)
|
||||||
template.Outputs.Artifacts = append(template.Outputs.Artifacts, wfv1.Artifact{
|
|
||||||
Name: "sys-metrics",
|
|
||||||
Path: "/tmp/sys-metrics.json",
|
|
||||||
Optional: true,
|
|
||||||
Archive: &wfv1.ArchiveStrategy{
|
|
||||||
None: &wfv1.NoneStrategy{},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
// Extend artifact credentials if only key is provided
|
|
||||||
for j, artifact := range template.Outputs.Artifacts {
|
|
||||||
injectArtifactRepositoryConfig(&artifact, namespaceConfig)
|
|
||||||
template.Outputs.Artifacts[j] = artifact
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for j, artifact := range template.Inputs.Artifacts {
|
if template.Container != nil || template.Script != nil {
|
||||||
injectArtifactRepositoryConfig(&artifact, namespaceConfig)
|
// Always add output artifacts for metrics but make them optional
|
||||||
template.Inputs.Artifacts[j] = artifact
|
template.Outputs.Artifacts = append(template.Outputs.Artifacts, wfv1.Artifact{
|
||||||
|
Name: "sys-metrics",
|
||||||
|
Path: "/tmp/sys-metrics.json",
|
||||||
|
Optional: true,
|
||||||
|
Archive: &wfv1.ArchiveStrategy{
|
||||||
|
None: &wfv1.NoneStrategy{},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// Extend artifact credentials if only key is provided
|
||||||
|
for j, artifact := range template.Outputs.Artifacts {
|
||||||
|
injectArtifactRepositoryConfig(&artifact, namespaceConfig)
|
||||||
|
template.Outputs.Artifacts[j] = artifact
|
||||||
|
}
|
||||||
|
|
||||||
|
for j, artifact := range template.Inputs.Artifacts {
|
||||||
|
injectArtifactRepositoryConfig(&artifact, namespaceConfig)
|
||||||
|
template.Inputs.Artifacts[j] = artifact
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
injectContainerResourceQuotas(wf, template, systemConfig)
|
|
||||||
|
|
||||||
//Generate ENV vars from secret, if there is a container present in the workflow
|
|
||||||
//Get template ENV vars, avoid over-writing them with secret values
|
|
||||||
env.AddDefaultEnvVarsToContainer(template.Container)
|
|
||||||
env.PrependEnvVarToContainer(template.Container, "ONEPANEL_API_URL", systemConfig["ONEPANEL_API_URL"])
|
|
||||||
env.PrependEnvVarToContainer(template.Container, "ONEPANEL_FQDN", systemConfig["ONEPANEL_FQDN"])
|
|
||||||
env.PrependEnvVarToContainer(template.Container, "ONEPANEL_DOMAIN", systemConfig["ONEPANEL_DOMAIN"])
|
|
||||||
env.PrependEnvVarToContainer(template.Container, "ONEPANEL_PROVIDER", systemConfig["ONEPANEL_PROVIDER"])
|
|
||||||
env.PrependEnvVarToContainer(template.Container, "ONEPANEL_RESOURCE_NAMESPACE", "{{workflow.namespace}}")
|
|
||||||
env.PrependEnvVarToContainer(template.Container, "ONEPANEL_RESOURCE_UID", "{{workflow.name}}")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user