Skip to content

Commit

Permalink
fix: cannot access HTTP template's outputs (#7200)
Browse files Browse the repository at this point in the history
Signed-off-by: book987 <book78987book@gmail.com>
  • Loading branch information
book987 authored and sarabala1979 committed Dec 15, 2021
1 parent a85458e commit 5a472dd
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# https://golangci-lint.run/usage/quick-start/
run:
concurrency: 4
timeout: 5m
timeout: 8m
skip-dirs:
- pkg/client
- vendor
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/workflow/v1alpha1/workflow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2425,7 +2425,7 @@ func (tmpl *Template) GetVolumeMounts() []apiv1.VolumeMount {

// whether or not the template can and will have outputs (i.e. exit code and result)
func (tmpl *Template) HasOutput() bool {
return tmpl.Container != nil || tmpl.ContainerSet.HasContainerNamed("main") || tmpl.Script != nil || tmpl.Data != nil
return tmpl.Container != nil || tmpl.ContainerSet.HasContainerNamed("main") || tmpl.Script != nil || tmpl.Data != nil || tmpl.HTTP != nil
}

// if logs should be saved as an artifact
Expand Down
15 changes: 15 additions & 0 deletions test/e2e/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,21 @@ func (s *FunctionalSuite) TestDataTransformation() {
})
}

func (s *FunctionalSuite) TestHTTPOutputs() {
s.Given().
Workflow("@testdata/http-outputs.yaml").
When().
SubmitWorkflow().
WaitForWorkflow(fixtures.ToBeSucceeded).
Then().
ExpectWorkflow(func(t *testing.T, metadata *metav1.ObjectMeta, status *wfv1.WorkflowStatus) {
httpNode := status.Nodes.FindByDisplayName("http")
assert.NotNil(t, httpNode.Outputs.Result)
echoNode := status.Nodes.FindByDisplayName("echo")
assert.Equal(t, *httpNode.Outputs.Result, echoNode.Inputs.Parameters[0].Value.String())
})
}

func (s *FunctionalSuite) TestScriptAsNonRoot() {
s.Given().
Workflow(`
Expand Down
40 changes: 40 additions & 0 deletions test/e2e/testdata/http-outputs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: http-outputs-
spec:
entrypoint: main
templates:
- name: main
dag:
tasks:
- name: http
template: http
arguments:
parameters:
- name: url
value: >-
https://raw.githubusercontent.com/argoproj/argo-workflows/4e450e250168e6b4d51a126b784e90b11a0162bc/pkg/apis/workflow/v1alpha1/generated.swagger.json
- name: echo
template: echo
arguments:
parameters:
- name: msg
value: '{{tasks.http.outputs.result}}'
dependencies:
- http
- name: http
inputs:
parameters:
- name: url
http:
url: '{{inputs.parameters.url}}'
- name: echo
inputs:
parameters:
- name: msg
container:
image: 'argoproj/argosay:v2'
args:
- echo
- '{{inputs.parameters.msg}}'
9 changes: 5 additions & 4 deletions workflow/controller/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ func (woc *wfOperationCtx) createAgentPod(ctx context.Context) (*apiv1.Pod, erro
ImagePullSecrets: woc.execWf.Spec.ImagePullSecrets,
Containers: []apiv1.Container{
{
Name: "main",
Command: []string{"argoexec"},
Args: []string{"agent"},
Image: woc.controller.executorImage(),
Name: "main",
Command: []string{"argoexec"},
Args: []string{"agent"},
Image: woc.controller.executorImage(),
ImagePullPolicy: woc.controller.executorImagePullPolicy(),
Env: []apiv1.EnvVar{
{Name: common.EnvVarWorkflowName, Value: woc.wf.Name},
},
Expand Down
3 changes: 2 additions & 1 deletion workflow/executor/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/utils/pointer"

"github.com/argoproj/argo-workflows/v3/errors"
wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
Expand Down Expand Up @@ -133,7 +134,7 @@ func (ae *AgentExecutor) executeHTTPTemplate(ctx context.Context, tmpl wfv1.Temp
return nil, err
}
outputs := &wfv1.Outputs{}
outputs.Parameters = append(outputs.Parameters, wfv1.Parameter{Name: "result", Value: wfv1.AnyStringPtr(response)})
outputs.Result = pointer.StringPtr(response)

return outputs, nil
}
Expand Down

0 comments on commit 5a472dd

Please sign in to comment.