Skip to content

Commit

Permalink
feat: support long arguments
Browse files Browse the repository at this point in the history
Co-authored-by: shuangkun <[email protected]>
Co-authored-by: zjgemi <[email protected]>
Signed-off-by: shuangkun <[email protected]>
  • Loading branch information
shuangkun and zjgemi committed Dec 6, 2023
1 parent feaed7a commit f219f0d
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/argoexec/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"time"

"github.com/argoproj/pkg/cli"
Expand Down Expand Up @@ -98,7 +99,13 @@ func initExecutor() *executor.WorkflowExecutor {
}

tmpl := &wfv1.Template{}
checkErr(json.Unmarshal([]byte(os.Getenv(common.EnvVarTemplate)), tmpl))
envVarTemplateValue := os.Getenv(common.EnvVarTemplate)
if envVarTemplateValue == common.EnvVarTemplateOffloaded {
data, err := os.ReadFile(filepath.Join(common.EnvConfigMountPath, common.EnvVarTemplate))
checkErr(err)
envVarTemplateValue = string(data)
}
checkErr(json.Unmarshal([]byte(envVarTemplateValue), tmpl))

includeScriptOutput := os.Getenv(common.EnvVarIncludeScriptOutput) == "true"
deadline, err := time.Parse(time.RFC3339, os.Getenv(common.EnvVarDeadline))
Expand Down
2 changes: 2 additions & 0 deletions workflow/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ const (
ServiceAccountTokenMountPath = "/var/run/secrets/kubernetes.io/serviceaccount" //nolint:gosec
ServiceAccountTokenVolumeName = "exec-sa-token" //nolint:gosec
SecretVolMountPath = "/argo/secret"
EnvConfigMountPath = "/argo/config"
EnvVarTemplateOffloaded = "offloaded"

// CACertificatesVolumeMountName is the name of the secret that contains the CA certificates.
CACertificatesVolumeMountName = "argo-workflows-agent-ca-certificates"
Expand Down
80 changes: 80 additions & 0 deletions workflow/controller/workflowpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
EmptyDir: &apiv1.EmptyDirVolumeSource{},
},
}
maxEnvVarLen = 131072
)

func (woc *wfOperationCtx) hasPodSpecPatch(tmpl *wfv1.Template) bool {
Expand Down Expand Up @@ -405,6 +406,85 @@ func (woc *wfOperationCtx) createWorkflowPod(ctx context.Context, nodeName strin
pod.Spec.Containers[i] = c
}

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
}
}
}
}
}

if offloadEnvVarTemplate {
cmName := fmt.Sprintf("%s-configmap", pod.Name)
cm := &apiv1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: cmName,
Namespace: woc.wf.ObjectMeta.Namespace,
Labels: map[string]string{
common.LabelKeyWorkflow: woc.wf.ObjectMeta.Name,
},
Annotations: map[string]string{
common.AnnotationKeyNodeName: nodeName,
common.AnnotationKeyNodeID: nodeID,
},
OwnerReferences: []metav1.OwnerReference{
*metav1.NewControllerRef(woc.wf, wfv1.SchemeGroupVersion.WithKind(workflow.WorkflowKind)),
},
},
Data: map[string]string{
common.EnvVarTemplate: envVarTemplateValue,
},
}
created, err := woc.controller.kubeclientset.CoreV1().ConfigMaps(woc.wf.ObjectMeta.Namespace).Create(ctx, cm, metav1.CreateOptions{})
if err != nil {
return nil, err
}
woc.log.Infof("Created configmap: %s", created.Name)

volumeConfig := apiv1.Volume{
Name: "argo-env-config",
VolumeSource: apiv1.VolumeSource{
ConfigMap: &apiv1.ConfigMapVolumeSource{
LocalObjectReference: apiv1.LocalObjectReference{
Name: cmName,
},
},
},
}
pod.Spec.Volumes = append(pod.Spec.Volumes, volumeConfig)

volumeMountConfig := apiv1.VolumeMount{
Name: volumeConfig.Name,
MountPath: common.EnvConfigMountPath,
}
for i, c := range pod.Spec.InitContainers {
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.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
node, err := woc.wf.GetNodeByName(nodeName)
if err != nil {
Expand Down

0 comments on commit f219f0d

Please sign in to comment.