diff --git a/.spelling b/.spelling index 6bfe6bd93bde..27bc74f90714 100644 --- a/.spelling +++ b/.spelling @@ -23,7 +23,6 @@ 5xx 8Ki 90m -ARGO_TEMPLATE Alexandre Alibaba Ang @@ -166,7 +165,6 @@ govaluate gzipped i.e. idempotence -inputs.parameters instantiator instantiators jenkins diff --git a/cmd/argoexec/commands/root.go b/cmd/argoexec/commands/root.go index 824734752c40..7a49cc7e1fc9 100644 --- a/cmd/argoexec/commands/root.go +++ b/cmd/argoexec/commands/root.go @@ -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) diff --git a/docs/environment-variables.md b/docs/environment-variables.md index 45ee275208e7..0a5e1533bc4f 100644 --- a/docs/environment-variables.md +++ b/docs/environment-variables.md @@ -23,7 +23,6 @@ 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. | `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. | diff --git a/workflow/controller/operator_test.go b/workflow/controller/operator_test.go index 0a1d6789ce5c..4378ef2010ae 100644 --- a/workflow/controller/operator_test.go +++ b/workflow/controller/operator_test.go @@ -1787,7 +1787,7 @@ func TestAssessNodeStatus(t *testing.T) { func getPodTemplate(pod *apiv1.Pod) (*wfv1.Template, error) { tmpl := &wfv1.Template{} - for _, c := range pod.Spec.Containers { + for _, c := range pod.Spec.InitContainers { for _, e := range c.Env { if e.Name == common.EnvVarTemplate { return tmpl, json.Unmarshal([]byte(e.Value), tmpl) @@ -1817,7 +1817,7 @@ func TestGetPodTemplate(t *testing.T) { name: "missing template", pod: &apiv1.Pod{ Spec: apiv1.PodSpec{ - Containers: []apiv1.Container{ + InitContainers: []apiv1.Container{ { Env: []apiv1.EnvVar{}, }, @@ -1829,7 +1829,7 @@ func TestGetPodTemplate(t *testing.T) { name: "empty template", pod: &apiv1.Pod{ Spec: apiv1.PodSpec{ - Containers: []apiv1.Container{ + InitContainers: []apiv1.Container{ { Env: []apiv1.EnvVar{ { @@ -1846,7 +1846,7 @@ func TestGetPodTemplate(t *testing.T) { name: "simple template", pod: &apiv1.Pod{ Spec: apiv1.PodSpec{ - Containers: []apiv1.Container{ + InitContainers: []apiv1.Container{ { Env: []apiv1.EnvVar{ { @@ -7310,8 +7310,8 @@ func TestWFWithRetryAndWithParam(t *testing.T) { ctrs := pods.Items[0].Spec.Containers assert.Len(t, ctrs, 2) envs := ctrs[1].Env - assert.Len(t, envs, 8) - assert.Equal(t, apiv1.EnvVar{Name: "ARGO_INCLUDE_SCRIPT_OUTPUT", Value: "true"}, envs[3]) + assert.Len(t, envs, 7) + assert.Equal(t, apiv1.EnvVar{Name: "ARGO_INCLUDE_SCRIPT_OUTPUT", Value: "true"}, envs[2]) }) } diff --git a/workflow/controller/workflowpod.go b/workflow/controller/workflowpod.go index def6833d1694..c612b12f0cca 100644 --- a/workflow/controller/workflowpod.go +++ b/workflow/controller/workflowpod.go @@ -296,25 +296,15 @@ func (woc *wfOperationCtx) createWorkflowPod(ctx context.Context, nodeName strin pod.Spec.InitContainers[i] = c } - envVarTemplateValue := wfv1.MustMarshallJSON(tmpl) - if os.Getenv("ARGO_TEMPLATE_WITH_INPUTS_PARAMETERS") == "false" { - tmplWithoutInputs := tmpl.DeepCopy() - // Preserve Inputs.Artifacts and clear other inputs - var artifacts []wfv1.Artifact - if len(tmplWithoutInputs.Inputs.Artifacts) > 0 { - artifacts = tmplWithoutInputs.Inputs.Artifacts - } else { - artifacts = []wfv1.Artifact{} - } - tmplWithoutInputs.Inputs = wfv1.Inputs{ - Artifacts: artifacts, - } - envVarTemplateValue = wfv1.MustMarshallJSON(tmplWithoutInputs) + // simplify template by clearing useless `inputs.parameters` and preserving `inputs.artifacts`. + simplifiedTmpl := tmpl.DeepCopy() + simplifiedTmpl.Inputs = wfv1.Inputs{ + Artifacts: simplifiedTmpl.Inputs.Artifacts, } + envVarTemplateValue := wfv1.MustMarshallJSON(simplifiedTmpl) // 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)}, @@ -341,6 +331,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 } @@ -362,7 +353,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) @@ -441,14 +432,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 } } } @@ -511,16 +500,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