Skip to content
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

add restart policy & scheduler name for workflow pods #1109

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -951,10 +951,18 @@
"description": "Resource template subtype which can run k8s resources",
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.ResourceTemplate"
},
"restartPolicy": {
"description": "Restart policy for all containers within all the pods. One of OnFailure or Never. Default to Never. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy",
"type": "string"
},
"retryStrategy": {
"description": "RetryStrategy describes how to retry a template when it fails",
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.RetryStrategy"
},
"schedulerName": {
"description": "If specified, all the pods will be dispatched by specified scheduler. If not specified, all the pods will be dispatched by default scheduler.",
"type": "string"
},
"script": {
"description": "Script runs a portion of code against an interpreter",
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.ScriptTemplate"
Expand Down
14 changes: 14 additions & 0 deletions pkg/apis/workflow/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions pkg/apis/workflow/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,18 @@ type Template struct {

// Tolerations to apply to workflow pods.
Tolerations []apiv1.Toleration `json:"tolerations,omitempty"`

// Restart policy for all containers within all the pods.
// One of OnFailure or Never.
// Default to Never.
// More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy
// +optional
RestartPolicy *apiv1.RestartPolicy `json:"restartPolicy,omitempty"`

// If specified, all the pods will be dispatched by specified scheduler.
// If not specified, all the pods will be dispatched by default scheduler.
// +optional
SchedulerName *string `json:"schedulerName,omitempty"`
}

// Inputs are the mechanism for passing parameters, artifacts, volumes from one template to another
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion workflow/controller/workflowpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ func (woc *wfOperationCtx) createWorkflowPod(nodeName string, mainCtr apiv1.Cont
},
},
Spec: apiv1.PodSpec{
RestartPolicy: apiv1.RestartPolicyNever,
Containers: []apiv1.Container{
mainCtr,
},
Expand Down Expand Up @@ -149,6 +148,16 @@ func (woc *wfOperationCtx) createWorkflowPod(nodeName string, mainCtr apiv1.Cont
addSchedulingConstraints(pod, wfSpec, tmpl)
woc.addMetadata(pod, tmpl)

if tmpl.RestartPolicy != nil {
pod.Spec.RestartPolicy = *tmpl.RestartPolicy
} else {
pod.Spec.RestartPolicy = apiv1.RestartPolicyNever
}

if tmpl.SchedulerName != nil {
pod.Spec.SchedulerName = *tmpl.SchedulerName
}

err := addVolumeReferences(pod, wfSpec, tmpl, woc.wf.Status.PersistentVolumeClaims)
if err != nil {
return nil, err
Expand Down
13 changes: 13 additions & 0 deletions workflow/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/argoproj/argo/workflow/artifacts/hdfs"
"github.com/argoproj/argo/workflow/common"
"github.com/valyala/fasttemplate"
apiv1 "k8s.io/api/core/v1"
apivalidation "k8s.io/apimachinery/pkg/util/validation"
)

Expand Down Expand Up @@ -237,6 +238,12 @@ func validateNonLeaf(tmpl *wfv1.Template) error {
if tmpl.RetryStrategy != nil {
return errors.Errorf(errors.CodeBadRequest, "templates.%s.retryStrategy is only valid for container templates", tmpl.Name)
}
if tmpl.RestartPolicy != nil {
return errors.Errorf(errors.CodeBadRequest, "templates.%s.restartPolicy is only valid for leaf templates", tmpl.Name)
}
if tmpl.SchedulerName != nil {
return errors.Errorf(errors.CodeBadRequest, "templates.%s.schedulerName is only valid for leaf templates", tmpl.Name)
}
return nil
}

Expand Down Expand Up @@ -264,6 +271,12 @@ func validateLeaf(scope map[string]interface{}, tmpl *wfv1.Template) error {
}
mountPaths[art.Path] = fmt.Sprintf("inputs.artifacts.%s", art.Name)
}
if tmpl.RestartPolicy != nil {
if *tmpl.RestartPolicy != apiv1.RestartPolicyNever &&
*tmpl.RestartPolicy != apiv1.RestartPolicyOnFailure {
return errors.Errorf(errors.CodeBadRequest, "templates.%s.restartPolicy should be one of Never or OnFailure", tmpl.Name)
}
}
}
if tmpl.ActiveDeadlineSeconds != nil {
if *tmpl.ActiveDeadlineSeconds <= 0 {
Expand Down