Skip to content

Commit

Permalink
feat(controller): HTTP Template and Agent support feature (argoproj#5750
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sarabala1979 committed Jul 29, 2021
1 parent 20efb52 commit b16a0a0
Show file tree
Hide file tree
Showing 47 changed files with 7,435 additions and 6,048 deletions.
26 changes: 8 additions & 18 deletions api/jsonschema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5443,21 +5443,6 @@
},
"type": "object"
},
"io.argoproj.workflow.v1alpha1.Task": {
"properties": {
"nodeId": {
"type": "string"
},
"template": {
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.Template"
}
},
"required": [
"nodeId",
"template"
],
"type": "object"
},
"io.argoproj.workflow.v1alpha1.Template": {
"description": "Template is a reusable and composable unit of execution in a workflow",
"properties": {
Expand Down Expand Up @@ -6526,10 +6511,12 @@
"io.argoproj.workflow.v1alpha1.WorkflowTaskSet": {
"properties": {
"apiVersion": {
"const": "argoproj.io/v1alpha1",
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.io.k8s.community/contributors/devel/sig-architecture/api-conventions.md#resources",
"type": "string"
},
"kind": {
"const": "WorkflowTaskSet",
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.io.k8s.community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
"type": "string"
},
Expand All @@ -6552,10 +6539,10 @@
"io.argoproj.workflow.v1alpha1.WorkflowTaskSetSpec": {
"properties": {
"tasks": {
"items": {
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.Task"
"additionalProperties": {
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.Template"
},
"type": "array"
"type": "object"
}
},
"type": "object"
Expand Down Expand Up @@ -9741,6 +9728,9 @@
},
{
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.WorkflowTemplate"
},
{
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.WorkflowTaskSet"
}
],
"type": "object"
Expand Down
21 changes: 3 additions & 18 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -8872,21 +8872,6 @@
}
}
},
"io.argoproj.workflow.v1alpha1.Task": {
"type": "object",
"required": [
"nodeId",
"template"
],
"properties": {
"nodeId": {
"type": "string"
},
"template": {
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.Template"
}
}
},
"io.argoproj.workflow.v1alpha1.Template": {
"description": "Template is a reusable and composable unit of execution in a workflow",
"type": "object",
Expand Down Expand Up @@ -9978,9 +9963,9 @@
"type": "object",
"properties": {
"tasks": {
"type": "array",
"items": {
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.Task"
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.Template"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/argo/commands/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func isNonBoundaryParentNode(node wfv1.NodeType) bool {
}

func isExecutionNode(node wfv1.NodeType) bool {
return (node == wfv1.NodeTypePod) || (node == wfv1.NodeTypeSkipped) || (node == wfv1.NodeTypeSuspend)
return (node == wfv1.NodeTypePod) || (node == wfv1.NodeTypeSkipped) || (node == wfv1.NodeTypeSuspend) || (node == wfv1.NodeTypeHTTP)
}

func insertSorted(wf *wfv1.Workflow, sortedArray []renderNode, item renderNode) []renderNode {
Expand Down
63 changes: 63 additions & 0 deletions cmd/argoexec/commands/agent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package commands

import (
"context"
"fmt"
"os"

log "github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest"

"github.com/argoproj/argo-workflows/v3"
workflow "github.com/argoproj/argo-workflows/v3/pkg/client/clientset/versioned"
"github.com/argoproj/argo-workflows/v3/util/logs"
"github.com/argoproj/argo-workflows/v3/workflow/common"
"github.com/argoproj/argo-workflows/v3/workflow/executor"

"github.com/spf13/cobra"
)

func NewAgentCommand() *cobra.Command {
return &cobra.Command{
Use: "agent",
SilenceUsage: true, // this prevents confusing usage message being printed on error
RunE: func(cmd *cobra.Command, args []string) error {
return initAgentExecutor().Agent(context.Background())
},
}
}

func initAgentExecutor() *executor.AgentExecutor {
version := argo.GetVersion()
log.WithFields(log.Fields{"version": version.Version}).Info("Starting Workflow Executor")
config, err := clientConfig.ClientConfig()
checkErr(err)

config = restclient.AddUserAgent(config, fmt.Sprintf("argo-workflows/%s argo-executor/%s", version.Version, "agent Executor"))

logs.AddK8SLogTransportWrapper(config) // lets log all request as we should typically do < 5 per pod, so this is will show up problems

namespace, _, err := clientConfig.Namespace()
checkErr(err)

clientSet, err := kubernetes.NewForConfig(config)
checkErr(err)

restClient := clientSet.RESTClient()

workflowName, ok := os.LookupEnv(common.EnvVarWorkflowName)
if !ok {
log.Fatalf("Unable to determine workflow name from environment variable %s", common.EnvVarWorkflowName)
}
agentExecutor := executor.AgentExecutor{
ClientSet: clientSet,
RESTClient: restClient,
Namespace: namespace,
WorkflowName: workflowName,
WorkflowInterface: workflow.NewForConfigOrDie(config),
CompleteTask: make(map[string]struct{}),
}
return &agentExecutor

}
2 changes: 2 additions & 0 deletions cmd/argoexec/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func NewRootCommand() *cobra.Command {
},
}

command.AddCommand(NewAgentCommand())
command.AddCommand(NewEmissaryCommand())
command.AddCommand(NewInitCommand())
command.AddCommand(NewResourceCommand())
Expand Down Expand Up @@ -121,6 +122,7 @@ func initExecutor() *executor.WorkflowExecutor {
checkErr(err)

wfExecutor := executor.NewExecutor(clientset, restClient, podName, namespace, cre, *tmpl, includeScriptOutput, deadline)

log.
WithField("version", version.String()).
WithField("namespace", namespace).
Expand Down
28 changes: 28 additions & 0 deletions docs/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ Workflow is the definition of a workflow resource

- [`hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/hello-world.yaml)

- [`http-hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/http-hello-world.yaml)

- [`image-pull-secrets.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/image-pull-secrets.yaml)

- [`influxdb-ci.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/influxdb-ci.yaml)
Expand Down Expand Up @@ -533,6 +535,8 @@ WorkflowSpec is the specification of a Workflow.

- [`hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/hello-world.yaml)

- [`http-hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/http-hello-world.yaml)

- [`image-pull-secrets.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/image-pull-secrets.yaml)

- [`influxdb-ci.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/influxdb-ci.yaml)
Expand Down Expand Up @@ -941,6 +945,8 @@ CronWorkflowSpec is the specification of a CronWorkflow

- [`hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/hello-world.yaml)

- [`http-hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/http-hello-world.yaml)

- [`image-pull-secrets.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/image-pull-secrets.yaml)

- [`influxdb-ci.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/influxdb-ci.yaml)
Expand Down Expand Up @@ -1306,6 +1312,8 @@ WorkflowTemplateSpec is a spec of WorkflowTemplate.

- [`hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/hello-world.yaml)

- [`http-hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/http-hello-world.yaml)

- [`image-pull-secrets.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/image-pull-secrets.yaml)

- [`influxdb-ci.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/influxdb-ci.yaml)
Expand Down Expand Up @@ -1626,6 +1634,8 @@ Arguments to a template

- [`hdfs-artifact.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/hdfs-artifact.yaml)

- [`http-hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/http-hello-world.yaml)

- [`influxdb-ci.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/influxdb-ci.yaml)

- [`k8s-orchestration.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-orchestration.yaml)
Expand Down Expand Up @@ -2347,6 +2357,8 @@ Parameter indicate a passed string parameter to a service template with an optio

- [`handle-large-output-results.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/handle-large-output-results.yaml)

- [`http-hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/http-hello-world.yaml)

- [`influxdb-ci.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/influxdb-ci.yaml)

- [`k8s-jobs.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-jobs.yaml)
Expand Down Expand Up @@ -2713,6 +2725,8 @@ _No description available_

- [`dag-daemon-task.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-daemon-task.yaml)

- [`http-hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/http-hello-world.yaml)

- [`influxdb-ci.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/influxdb-ci.yaml)

- [`input-artifact-http.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/input-artifact-http.yaml)
Expand Down Expand Up @@ -2851,6 +2865,8 @@ Inputs are the mechanism for passing parameters, artifacts, volumes from one tem

- [`hdfs-artifact.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/hdfs-artifact.yaml)

- [`http-hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/http-hello-world.yaml)

- [`influxdb-ci.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/influxdb-ci.yaml)

- [`input-artifact-gcs.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/input-artifact-gcs.yaml)
Expand Down Expand Up @@ -3174,6 +3190,8 @@ WorkflowStep is a reference to a template to execute in a series of step

- [`hello-hybrid.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/hello-hybrid.yaml)

- [`http-hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/http-hello-world.yaml)

- [`influxdb-ci.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/influxdb-ci.yaml)

- [`k8s-orchestration.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-orchestration.yaml)
Expand Down Expand Up @@ -3549,6 +3567,8 @@ HTTPArtifact allows an file served on HTTP to be placed as an input artifact in

- [`dag-daemon-task.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/dag-daemon-task.yaml)

- [`http-hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/http-hello-world.yaml)

- [`influxdb-ci.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/influxdb-ci.yaml)

- [`input-artifact-http.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/input-artifact-http.yaml)
Expand Down Expand Up @@ -3788,6 +3808,8 @@ MetricLabel is a single label for a prometheus metric

- [`hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/hello-world.yaml)

- [`http-hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/http-hello-world.yaml)

- [`k8s-owner-reference.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-owner-reference.yaml)

- [`k8s-patch-basic.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-patch-basic.yaml)
Expand Down Expand Up @@ -4086,6 +4108,8 @@ ContinueOn defines if a workflow should continue even if a task or step fails/er

- [`exit-code-output-variable.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/exit-code-output-variable.yaml)

- [`http-hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/http-hello-world.yaml)

- [`resource-flags.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/resource-flags.yaml)

- [`status-reference.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/status-reference.yaml)
Expand Down Expand Up @@ -4640,6 +4664,8 @@ ObjectMeta is metadata that all persisted resources must have, which includes al

- [`hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/hello-world.yaml)

- [`http-hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/http-hello-world.yaml)

- [`image-pull-secrets.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/image-pull-secrets.yaml)

- [`influxdb-ci.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/influxdb-ci.yaml)
Expand Down Expand Up @@ -5901,6 +5927,8 @@ PersistentVolumeClaimSpec describes the common attributes of storage devices and

- [`hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/hello-world.yaml)

- [`http-hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/http-hello-world.yaml)

- [`image-pull-secrets.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/image-pull-secrets.yaml)

- [`influxdb-ci.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/influxdb-ci.yaml)
Expand Down
34 changes: 34 additions & 0 deletions docs/http-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# HTTP Template

> v3.2 and after
`HTTP Template` is a type of template which can execute the HTTP Requests.

### Agent Architecture
V3.2 introduced `Agent` architecture to execute the multiple HTTPTemplates in single pod which improve a performance and resource utilization.
`WorkflowTaskSet` CRD is introduced to exchange the data between Controller and Agent.
Agent pod named <workflowname-agent> and WorkflowTaskSet name as WorkflowName.

```yaml
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: http-template-
spec:
entrypoint: main
templates:
- name: main
steps:
- - name: good
template: http
arguments:
parameters: [{name: url, value: "https://raw.githubusercontent.com/argoproj/argo-workflows/4e450e250168e6b4d51a126b784e90b11a0162bc/pkg/apis/workflow/v1alpha1/generated.swagger.json"}]
- name: http
inputs:
parameters:
- name: url
http:
# url: http:https://dummy.restapiexample.com/api/v1/employees
url: "{{inputs.parameters.url}}"

```
36 changes: 36 additions & 0 deletions examples/http-hello-world.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: http-template-
labels:
workflows.argoproj.io/test: "true"
annotations:
workflows.argoproj.io/description: |
Http template will demostrate http template functionality
workflows.argoproj.io/version: '>= 3.2.0'
workflows.argoproj.io/verify.py: |
assert status["phase"] == "Succeeded"
spec:
entrypoint: main
templates:
- name: main
steps:
- - name: good
template: http
arguments:
parameters: [{name: url, value: "https://raw.githubusercontent.com/argoproj/argo-workflows/4e450e250168e6b4d51a126b784e90b11a0162bc/pkg/apis/workflow/v1alpha1/generated.swagger.json"}]
- name: bad
template: http
continueOn:
failed: true
arguments:
parameters: [{name: url, value: "http:https://openlibrary.org/people/george08/nofound.json"}]

- name: http
inputs:
parameters:
- name: url
http:
# url: http:https://dummy.restapiexample.com/api/v1/employees
url: "{{inputs.parameters.url}}"

2 changes: 2 additions & 0 deletions hack/jsonschema/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func main() {
"Workflow",
"WorkflowEventBinding",
"WorkflowTemplate",
"WorkflowTaskSet",
} {
v := definitions.(obj)["io.argoproj.workflow.v1alpha1."+kind].(obj)["properties"].(obj)
v["apiVersion"].(obj)["const"] = "argoproj.io/v1alpha1"
Expand All @@ -40,6 +41,7 @@ func main() {
obj{"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.Workflow"},
obj{"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.WorkflowEventBinding"},
obj{"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.WorkflowTemplate"},
obj{"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.WorkflowTaskSet"},
},
"definitions": definitions,
}
Expand Down
Loading

0 comments on commit b16a0a0

Please sign in to comment.