Skip to content

Commit

Permalink
fix: resource template getting duplicate exec-sa-token volume mounts …
Browse files Browse the repository at this point in the history
…with automountServiceAccountToken: false. Fixes #12848

Signed-off-by: Minyi Zhong <[email protected]>
  • Loading branch information
Minyi Zhong committed Oct 26, 2024
1 parent 1017c1d commit 6c8400a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 16 deletions.
42 changes: 42 additions & 0 deletions test/e2e/resource_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,48 @@ func (s *ResourceTemplateSuite) TestResourceTemplateWithOutputs() {
})
}

func (s *ResourceTemplateSuite) TestResourceTemplateAutomountServiceAccountTokenDisabled() {
s.Given().
Workflow(`
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: k8s-resource-tmpl-with-automountservicetoken-disabled-
spec:
serviceAccountName: argo
automountServiceAccountToken: false
executor:
serviceAccountName: argo
entrypoint: main
templates:
- name: main
resource:
action: create
setOwnerReference: true
successCondition: status.phase == Succeeded
failureCondition: status.phase == Failed
manifest: |
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: k8s-wf-resource-
spec:
entrypoint: main
templates:
- name: main
container:
image: argoproj/argosay:v2
command: ["/argosay"]
`).
When().
SubmitWorkflow().
WaitForWorkflow().
Then().
ExpectWorkflow(func(t *testing.T, _ *metav1.ObjectMeta, status *wfv1.WorkflowStatus) {
assert.Equal(t, wfv1.WorkflowSucceeded, status.Phase)
})
}

func (s *ResourceTemplateSuite) TestResourceTemplateFailed() {
s.Given().
Workflow("@testdata/resource-templates/failed.yaml").
Expand Down
18 changes: 18 additions & 0 deletions test/e2e/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ spec:
- -c
- |
kubectl get cm
volumeMounts:
- name: sa-token
mountPath: /var/run/secrets/kubernetes.io/serviceaccount
readOnly: true
volumes:
- name: sa-token
secret:
defaultMode: 420
secretName: get-cm.service-account-token
`).
When().
SubmitWorkflow().
Expand Down Expand Up @@ -78,6 +87,15 @@ spec:
- sh
source:
kubectl get cm
volumeMounts:
- name: sa-token
mountPath: /var/run/secrets/kubernetes.io/serviceaccount
readOnly: true
volumes:
- name: sa-token
secret:
defaultMode: 420
secretName: get-cm.service-account-token
`).
When().
SubmitWorkflow().
Expand Down
16 changes: 0 additions & 16 deletions workflow/controller/workflowpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,22 +224,6 @@ func (woc *wfOperationCtx) createWorkflowPod(ctx context.Context, nodeName strin
// container's PID and root filesystem.
pod.Spec.Containers = append(pod.Spec.Containers, mainCtrs...)

// Configure service account token volume for the main container when AutomountServiceAccountToken is disabled
if (woc.execWf.Spec.AutomountServiceAccountToken != nil && !*woc.execWf.Spec.AutomountServiceAccountToken) ||
(tmpl.AutomountServiceAccountToken != nil && !*tmpl.AutomountServiceAccountToken) {
for i, c := range pod.Spec.Containers {
if c.Name == common.WaitContainerName {
continue
}
c.VolumeMounts = append(c.VolumeMounts, apiv1.VolumeMount{
Name: common.ServiceAccountTokenVolumeName,
MountPath: common.ServiceAccountTokenMountPath,
ReadOnly: true,
})
pod.Spec.Containers[i] = c
}
}

// Configuring default container to be used with commands like "kubectl exec/logs".
// Select "main" container if it's available. In other case use the last container (can happen when pod created from ContainerSet).
defaultContainer := pod.Spec.Containers[len(pod.Spec.Containers)-1].Name
Expand Down

0 comments on commit 6c8400a

Please sign in to comment.