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

fix: Apply workflow level PodSpecPatch in agent pod. Fixes #12387 #12440

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions workflow/controller/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo-workflows/v3/util/env"
"github.com/argoproj/argo-workflows/v3/workflow/common"
"github.com/argoproj/argo-workflows/v3/workflow/util"
)

func (woc *wfOperationCtx) getAgentPodName() string {
Expand Down Expand Up @@ -243,6 +244,14 @@ func (woc *wfOperationCtx) createAgentPod(ctx context.Context) (*apiv1.Pod, erro
addSchedulingConstraints(pod, woc.execWf.Spec.DeepCopy(), tmpl)
woc.addMetadata(pod, tmpl)

if woc.execWf.Spec.HasPodSpecPatch() {
patchedPodSpec, err := util.ApplyPodSpecPatch(pod.Spec, woc.execWf.Spec.PodSpecPatch)
if err != nil {
return nil, errors.Wrap(err, "", "Error applying PodSpecPatch")
}
pod.Spec = *patchedPodSpec
}
jswxstw marked this conversation as resolved.
Show resolved Hide resolved

if woc.controller.Config.InstanceID != "" {
pod.ObjectMeta.Labels[common.LabelKeyControllerInstanceID] = woc.controller.Config.InstanceID
}
Expand Down Expand Up @@ -293,17 +302,17 @@ func (woc *wfOperationCtx) getExecutorPlugins(ctx context.Context) ([]apiv1.Cont
}

func addresses(containers []apiv1.Container) []string {
var addresses []string
var pluginAddresses []string
for _, c := range containers {
addresses = append(addresses, fmt.Sprintf("http://localhost:%d", c.Ports[0].ContainerPort))
pluginAddresses = append(pluginAddresses, fmt.Sprintf("http://localhost:%d", c.Ports[0].ContainerPort))
}
return addresses
return pluginAddresses
}

func names(containers []apiv1.Container) []string {
var addresses []string
var pluginNames []string
for _, c := range containers {
addresses = append(addresses, c.Name)
pluginNames = append(pluginNames, c.Name)
}
return addresses
return pluginNames
}
4 changes: 4 additions & 0 deletions workflow/controller/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ metadata:
name: http-template
namespace: default
spec:
podSpecPatch: |
nodeName: virtual-node
entrypoint: main
templates:
- name: main
Expand Down Expand Up @@ -107,6 +109,7 @@ status:
for _, pod := range pods.Items {
assert.NotNil(t, pod)
assert.True(t, strings.HasSuffix(pod.Name, "-agent"))
assert.Equal(t, "virtual-node", pod.Spec.NodeName)
}
})
t.Run("CreateTaskSetWithInstanceID", func(t *testing.T) {
Expand All @@ -133,6 +136,7 @@ status:
assert.NotNil(t, pod)
assert.True(t, strings.HasSuffix(pod.Name, "-agent"))
assert.Equal(t, "testID", pod.ObjectMeta.Labels[common.LabelKeyControllerInstanceID])
assert.Equal(t, "virtual-node", pod.Spec.NodeName)
}
})
}
Expand Down