Skip to content

Commit

Permalink
fix: default not respected in setting global configmap params. Fixes a…
Browse files Browse the repository at this point in the history
…rgoproj#9745 (argoproj#9758)

Signed-off-by: Rohan Kumar <[email protected]>
Signed-off-by: juchao <[email protected]>
  • Loading branch information
rohankmr414 authored and juchaosong committed Nov 3, 2022
1 parent fc6dc88 commit cfc94c9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
41 changes: 41 additions & 0 deletions test/e2e/workflow_configmap_substitution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,47 @@ spec:
})
}

func (s *WorkflowConfigMapSelectorSubstitutionSuite) TestGlobalArgDefaultCMParamValueWhenNotFound() {
s.Given().
Workflow(`apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: workflow-template-cmkeyselector-wf-global-arg-default-param-
label:
workflows.argoproj.io/test: "true"
spec:
serviceAccountName: argo
entrypoint: whalesay
arguments:
parameters:
- name: simple-global-param
valueFrom:
default: "default value"
configMapKeyRef:
name: not-existing-cm
key: not-existing-key
templates:
- name: whalesay
container:
image: argoproj/argosay:v2
command: [sh, -c]
args: ["sleep 1; echo -n {{workflow.parameters.simple-global-param}} > /tmp/message.txt"]
outputs:
parameters:
- name: message
valueFrom:
path: /tmp/message.txt
`).
When().
SubmitWorkflow().
WaitForWorkflow(fixtures.ToBeSucceeded).
Then().
ExpectWorkflow(func(t *testing.T, metadata *metav1.ObjectMeta, status *wfv1.WorkflowStatus) {
assert.Equal(t, "default value", status.Nodes[metadata.Name].Outputs.Parameters[0].Value.String())
assert.Equal(t, wfv1.WorkflowSucceeded, status.Phase)
})
}

func TestConfigMapKeySelectorSubstitutionSuite(t *testing.T) {
suite.Run(t, new(WorkflowConfigMapSelectorSubstitutionSuite))
}
11 changes: 8 additions & 3 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,15 @@ func (woc *wfOperationCtx) setGlobalParameters(executionParameters wfv1.Argument
if param.ValueFrom != nil && param.ValueFrom.ConfigMapKeyRef != nil {
cmValue, err := common.GetConfigMapValue(woc.controller.configMapInformer, woc.wf.ObjectMeta.Namespace, param.ValueFrom.ConfigMapKeyRef.Name, param.ValueFrom.ConfigMapKeyRef.Key)
if err != nil {
return fmt.Errorf("failed to set global parameter %s from configmap with name %s and key %s: %w",
param.Name, param.ValueFrom.ConfigMapKeyRef.Name, param.ValueFrom.ConfigMapKeyRef.Key, err)
if param.ValueFrom.Default != nil {
woc.globalParams["workflow.parameters."+param.Name] = param.ValueFrom.Default.String()
} else {
return fmt.Errorf("failed to set global parameter %s from configmap with name %s and key %s: %w",
param.Name, param.ValueFrom.ConfigMapKeyRef.Name, param.ValueFrom.ConfigMapKeyRef.Key, err)
}
} else {
woc.globalParams["workflow.parameters."+param.Name] = cmValue
}
woc.globalParams["workflow.parameters."+param.Name] = cmValue
} else {
woc.globalParams["workflow.parameters."+param.Name] = param.Value.String()
}
Expand Down

0 comments on commit cfc94c9

Please sign in to comment.