Skip to content

Commit

Permalink
feat: Only set ARGO_TEMPLATE env for init container.
Browse files Browse the repository at this point in the history
Signed-off-by: oninowang <[email protected]>
  • Loading branch information
jswxstw authored and oninowang committed Oct 15, 2024
1 parent cf6223d commit 87e02d3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 27 deletions.
2 changes: 0 additions & 2 deletions .spelling
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
5xx
8Ki
90m
ARGO_TEMPLATE
Alexandre
Alibaba
Ang
Expand Down Expand Up @@ -166,7 +165,6 @@ govaluate
gzipped
i.e.
idempotence
inputs.parameters
instantiator
instantiators
jenkins
Expand Down
9 changes: 7 additions & 2 deletions cmd/argoexec/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,13 @@ func initExecutor() *executor.WorkflowExecutor {
}

tmpl := &wfv1.Template{}
envVarTemplateValue := os.Getenv(common.EnvVarTemplate)
if envVarTemplateValue == common.EnvVarTemplateOffloaded {
envVarTemplateValue, ok := os.LookupEnv(common.EnvVarTemplate)
// wait container reads template from the file written by init container, instead of from environment variable.
if !ok {
data, err := os.ReadFile(varRunArgo + "/template")
checkErr(err)
envVarTemplateValue = string(data)
} else if envVarTemplateValue == common.EnvVarTemplateOffloaded {
data, err := os.ReadFile(filepath.Join(common.EnvConfigMountPath, common.EnvVarTemplate))
checkErr(err)
envVarTemplateValue = string(data)
Expand Down
6 changes: 3 additions & 3 deletions docs/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This document outlines environment variables that can be used to customize behav
| `ARGO_AGENT_CPU_LIMIT` | `resource.Quantity` | `100m` | CPU resource limit for the agent. |
| `ARGO_AGENT_MEMORY_LIMIT` | `resource.Quantity` | `256m` | Memory resource limit for the agent. |
| `ARGO_POD_STATUS_CAPTURE_FINALIZER` | `bool` | `false` | The finalizer blocks the deletion of pods until the controller captures their status.
| `ARGO_TEMPLATE_WITH_INPUTS_PARAMETERS` | `bool` | `true` | Whether to keep inputs.parameters inside the ARGO_TEMPLATE environment variable of pods.
| `ARGO_TEMPLATE_WITH_INPUTS_PARAMETERS` | `bool` | `true` | Whether to keep `inputs.parameters` inside the `ARGO_TEMPLATE` environment variable of pods.
| `BUBBLE_ENTRY_TEMPLATE_ERR` | `bool` | `true` | Whether to bubble up template errors to workflow. |
| `CACHE_GC_PERIOD` | `time.Duration` | `0s` | How often to perform memoization cache GC, which is disabled by default and can be enabled by providing a non-zero duration. |
| `CACHE_GC_AFTER_NOT_HIT_DURATION` | `time.Duration` | `30s` | When a memoization cache has not been hit after this duration, it will be deleted. |
Expand Down Expand Up @@ -55,8 +55,8 @@ This document outlines environment variables that can be used to customize behav
| `WF_DEL_PROPAGATION_POLICY` | `string` | `""` | The deletion propagation policy for workflows. |
| `WORKFLOW_GC_PERIOD` | `time.Duration` | `5m` | The periodicity for GC of workflows. |
| `SEMAPHORE_NOTIFY_DELAY` | `time.Duration` | `1s` | Tuning Delay when notifying semaphore waiters about availability in the semaphore |
| `WATCH_CONTROLLER_SEMAPHORE_CONFIGMAPS` | `bool` | `true` | Whether to watch the Controller's ConfigMap and semaphore ConfigMaps for run-time changes. When disabled, the Controller will only read these ConfigMaps once and will have to be manually restarted to pick up new changes. |
| `SKIP_WORKFLOW_DURATION_ESTIMATION` | `bool` | `false` | Whether to lookup resource usage from prior workflows to estimate usage for new workflows. |
| `WATCH_CONTROLLER_SEMAPHORE_CONFIGMAPS` | `bool` | `true` | Whether to watch the Controller's ConfigMap and semaphore ConfigMaps for run-time changes. When disabled, the Controller will only read these ConfigMaps once and will have to be manually restarted to pick up new changes. |
| `SKIP_WORKFLOW_DURATION_ESTIMATION` | `bool` | `false` | Whether to lookup resource usage from prior workflows to estimate usage for new workflows. |

CLI parameters of the Controller can be specified as environment variables with the `ARGO_` prefix.
For example:
Expand Down
28 changes: 8 additions & 20 deletions workflow/controller/workflowpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ func (woc *wfOperationCtx) createWorkflowPod(ctx context.Context, nodeName strin

// Add standard environment variables, making pod spec larger
envVars := []apiv1.EnvVar{
{Name: common.EnvVarTemplate, Value: envVarTemplateValue},
{Name: common.EnvVarNodeID, Value: nodeID},
{Name: common.EnvVarIncludeScriptOutput, Value: strconv.FormatBool(opts.includeScriptOutput)},
{Name: common.EnvVarDeadline, Value: woc.getDeadline(opts).Format(time.RFC3339)},
Expand All @@ -338,6 +337,7 @@ func (woc *wfOperationCtx) createWorkflowPod(ctx context.Context, nodeName strin

for i, c := range pod.Spec.InitContainers {
c.Env = append(c.Env, apiv1.EnvVar{Name: common.EnvVarContainerName, Value: c.Name})
c.Env = append(c.Env, apiv1.EnvVar{Name: common.EnvVarTemplate, Value: envVarTemplateValue})
c.Env = append(c.Env, envVars...)
pod.Spec.InitContainers[i] = c
}
Expand All @@ -359,7 +359,7 @@ func (woc *wfOperationCtx) createWorkflowPod(ctx context.Context, nodeName strin
// only to check ArchiveLocation for now, since everything else should have been substituted
// earlier (i.e. in executeTemplate). But archive location is unique in that the variables
// are formulated from the configmap. We can expand this to other fields as necessary.
for _, c := range pod.Spec.Containers {
for _, c := range pod.Spec.InitContainers {
for _, e := range c.Env {
if e.Name == common.EnvVarTemplate {
err = json.Unmarshal([]byte(e.Value), tmpl)
Expand Down Expand Up @@ -438,14 +438,12 @@ func (woc *wfOperationCtx) createWorkflowPod(ctx context.Context, nodeName strin
}

offloadEnvVarTemplate := false
for _, c := range pod.Spec.Containers {
if c.Name == common.MainContainerName {
for _, e := range c.Env {
if e.Name == common.EnvVarTemplate {
envVarTemplateValue = e.Value
if len(envVarTemplateValue) > maxEnvVarLen {
offloadEnvVarTemplate = true
}
for _, c := range pod.Spec.InitContainers {
for _, e := range c.Env {
if e.Name == common.EnvVarTemplate {
envVarTemplateValue = e.Value
if len(envVarTemplateValue) > maxEnvVarLen {
offloadEnvVarTemplate = true
}
}
}
Expand Down Expand Up @@ -504,16 +502,6 @@ func (woc *wfOperationCtx) createWorkflowPod(ctx context.Context, nodeName strin
c.VolumeMounts = append(c.VolumeMounts, volumeMountConfig)
pod.Spec.InitContainers[i] = c
}
for i, c := range pod.Spec.Containers {
for j, e := range c.Env {
if e.Name == common.EnvVarTemplate {
e.Value = common.EnvVarTemplateOffloaded
c.Env[j] = e
}
}
c.VolumeMounts = append(c.VolumeMounts, volumeMountConfig)
pod.Spec.Containers[i] = c
}
}

// Check if the template has exceeded its timeout duration. If it hasn't set the applicable activeDeadlineSeconds
Expand Down

0 comments on commit 87e02d3

Please sign in to comment.