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 committed Dec 2, 2021
1 parent e0d5abc commit cb8c063
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 8 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:
- dist
- docs
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 @@ -843,6 +843,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}}'
11 changes: 6 additions & 5 deletions workflow/controller/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ 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(),
Env: envVars,
Name: "main",
Command: []string{"argoexec"},
Args: []string{"agent"},
Image: woc.controller.executorImage(),
ImagePullPolicy: woc.controller.executorImagePullPolicy(),
Env: envVars,
},
},
},
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"

wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
workflow "github.com/argoproj/argo-workflows/v3/pkg/client/clientset/versioned"
Expand Down Expand Up @@ -221,7 +222,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 cb8c063

Please sign in to comment.