Skip to content

Commit

Permalink
feat(server): Trigger workflows from webhooks. Closes #2667 (#3488)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec authored Aug 7, 2020
1 parent a5d995d commit 71d6128
Show file tree
Hide file tree
Showing 81 changed files with 5,751 additions and 694 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ git-ask-pass.sh
/pkg/apiclient/_.secondary.swagger.json
/pkg/apiclient/clusterworkflowtemplate/cluster-workflow-template.swagger.json
/pkg/apiclient/cronworkflow/cron-workflow.swagger.json
/pkg/apiclient/event/event.swagger.json
/pkg/apiclient/info/info.swagger.json
/pkg/apiclient/workflow/workflow.swagger.json
/pkg/apiclient/workflowarchive/workflow-archive.swagger.json
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ SWAGGER_FILES := pkg/apiclient/_.primary.swagger.json \
pkg/apiclient/_.secondary.swagger.json \
pkg/apiclient/clusterworkflowtemplate/cluster-workflow-template.swagger.json \
pkg/apiclient/cronworkflow/cron-workflow.swagger.json \
pkg/apiclient/event/event.swagger.json \
pkg/apiclient/info/info.swagger.json \
pkg/apiclient/workflow/workflow.swagger.json \
pkg/apiclient/workflowarchive/workflow-archive.swagger.json \
Expand Down Expand Up @@ -456,8 +457,7 @@ dist/kubeified.swagger.json: dist/swaggifed.swagger.json dist/kubernetes.swagger
go run ./hack kubeifyswagger dist/swaggifed.swagger.json dist/kubeified.swagger.json

api/openapi-spec/swagger.json: dist/kubeified.swagger.json
swagger flatten --with-flatten minimal --with-flatten remove-unused dist/kubeified.swagger.json > dist/swagger.json
mv dist/swagger.json api/openapi-spec/swagger.json
swagger flatten --with-flatten minimal --with-flatten remove-unused dist/kubeified.swagger.json -o api/openapi-spec/swagger.json
swagger validate api/openapi-spec/swagger.json
go test ./api/openapi-spec

Expand Down
118 changes: 117 additions & 1 deletion api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,47 @@
}
}
},
"/api/v1/events/{namespace}/{discriminator}": {
"post": {
"tags": [
"EventService"
],
"operationId": "ReceiveEvent",
"parameters": [
{
"type": "string",
"description": "The namespace for the io.argoproj.workflow.v1alpha1. This can be empty if the client has cluster scoped permissions.\nIf empty, then the event is \"broadcast\" to workflow event binding in all namespaces.",
"name": "namespace",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Optional discriminator for the io.argoproj.workflow.v1alpha1. This should almost always be empty.\nUsed for edge-cases where the event payload alone is not provide enough information to discriminate the event.\nThis MUST NOT be used as security mechanism, e.g. to allow two clients to use the same access token, or\nto support webhooks on unsecured server. Instead, use access tokens.\nThis is made available as `discriminator` in the event binding selector (`/spec/event/selector)`",
"name": "discriminator",
"in": "path",
"required": true
},
{
"description": "The event itself can be any data.",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.Item"
}
}
],
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.EventResponse"
}
}
}
}
},
"/api/v1/info": {
"get": {
"tags": [
Expand Down Expand Up @@ -2364,6 +2405,21 @@
}
}
},
"io.argoproj.workflow.v1alpha1.Event": {
"type": "object",
"required": [
"selector"
],
"properties": {
"selector": {
"description": "Selector (https://github.com/antonmedv/expr) that we must must match the io.argoproj.workflow.v1alpha1. E.g. `payload.message == \"test\"`",
"type": "string"
}
}
},
"io.argoproj.workflow.v1alpha1.EventResponse": {
"type": "object"
},
"io.argoproj.workflow.v1alpha1.ExecutorConfig": {
"description": "ExecutorConfig holds configurations of an executor container.",
"type": "object",
Expand Down Expand Up @@ -3336,6 +3392,22 @@
}
}
},
"io.argoproj.workflow.v1alpha1.Submit": {
"type": "object",
"required": [
"workflowTemplateRef"
],
"properties": {
"arguments": {
"description": "Arguments extracted from the event and then set as arguments to the workflow created.",
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.Arguments"
},
"workflowTemplateRef": {
"description": "WorkflowTemplateRef the workflow template to submit",
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.WorkflowTemplateRef"
}
}
},
"io.argoproj.workflow.v1alpha1.SubmitOpts": {
"description": "SubmitOpts are workflow submission options",
"type": "object",
Expand Down Expand Up @@ -3821,6 +3893,10 @@
"description": "Default specifies a value to be used if retrieving the value from the specified source fails",
"$ref": "#/definitions/io.k8s.apimachinery.pkg.util.intstr.IntOrString"
},
"event": {
"description": "Selector (https://github.com/antonmedv/expr) that is evaluated against the event to get the value of the parameter. E.g. `payload.message`",
"type": "string"
},
"jqFilter": {
"description": "JQFilter expression against the resource object in resource templates",
"type": "string"
Expand Down Expand Up @@ -3934,6 +4010,46 @@
"io.argoproj.workflow.v1alpha1.WorkflowDeleteResponse": {
"type": "object"
},
"io.argoproj.workflow.v1alpha1.WorkflowEventBinding": {
"description": "WorkflowEventBinding is the definition of an event resource",
"type": "object",
"required": [
"metadata",
"spec"
],
"properties": {
"apiVersion": {
"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": {
"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"
},
"metadata": {
"$ref": "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta"
},
"spec": {
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.WorkflowEventBindingSpec"
}
}
},
"io.argoproj.workflow.v1alpha1.WorkflowEventBindingSpec": {
"type": "object",
"required": [
"event"
],
"properties": {
"event": {
"description": "Event is the event to bind to",
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.Event"
},
"submit": {
"description": "Submit is the workflow template to submit",
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.Submit"
}
}
},
"io.argoproj.workflow.v1alpha1.WorkflowLintRequest": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -7386,4 +7502,4 @@
"type": "basic"
}
}
}
}
44 changes: 25 additions & 19 deletions cmd/argo/commands/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ import (

func NewServerCommand() *cobra.Command {
var (
authModes []string
configMap string
port int
baseHRef string
secure bool
htst bool
namespaced bool // --namespaced
managedNamespace string // --managed-namespace
enableOpenBrowser bool
authModes []string
configMap string
port int
baseHRef string
secure bool
htst bool
namespaced bool // --namespaced
managedNamespace string // --managed-namespace
enableOpenBrowser bool
eventOperationQueueSize int
eventWorkerCount int
)

var command = cobra.Command{
Expand Down Expand Up @@ -94,16 +96,18 @@ See %s`, help.ArgoSever),
}

opts := apiserver.ArgoServerOpts{
BaseHRef: baseHRef,
TLSConfig: tlsConfig,
HSTS: htst,
Namespace: namespace,
WfClientSet: wflientset,
KubeClientset: kubeConfig,
RestConfig: config,
AuthModes: modes,
ManagedNamespace: managedNamespace,
ConfigName: configMap,
BaseHRef: baseHRef,
TLSConfig: tlsConfig,
HSTS: htst,
Namespace: namespace,
WfClientSet: wflientset,
KubeClientset: kubeConfig,
RestConfig: config,
AuthModes: modes,
ManagedNamespace: managedNamespace,
ConfigName: configMap,
EventOperationQueueSize: eventOperationQueueSize,
EventWorkerCount: eventWorkerCount,
}
browserOpenFunc := func(url string) {}
if enableOpenBrowser {
Expand Down Expand Up @@ -135,5 +139,7 @@ See %s`, help.ArgoSever),
command.Flags().BoolVar(&namespaced, "namespaced", false, "run as namespaced mode")
command.Flags().StringVar(&managedNamespace, "managed-namespace", "", "namespace that watches, default to the installation namespace")
command.Flags().BoolVarP(&enableOpenBrowser, "browser", "b", false, "enable automatic launching of the browser [local mode]")
command.Flags().IntVar(&eventOperationQueueSize, "event-operation-queue-size", 16, "how many events operations that can be queued at once")
command.Flags().IntVar(&eventWorkerCount, "event-worker-count", 4, "how many event workers to run")
return &command
}
20 changes: 11 additions & 9 deletions docs/cli/argo_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ See https://github.com/argoproj/argo/blob/master/docs/argo-server.md
### Options

```
--auth-mode stringArray API server authentication mode. Any 1 or more length permutation of: client,server,sso (default [server])
--basehref string Value for base href in index.html. Used if the server is running behind reverse proxy under subpath different from /. Defaults to the environment variable BASE_HREF. (default "/")
-b, --browser enable automatic launching of the browser [local mode]
--configmap string Name of K8s configmap to retrieve workflow controller configuration (default "workflow-controller-configmap")
-h, --help help for server
--hsts Whether or not we should add a HTTP Secure Transport Security header. This only has effect if secure is enabled. (default true)
--managed-namespace string namespace that watches, default to the installation namespace
--namespaced run as namespaced mode
-p, --port int Port to listen on (default 2746)
--auth-mode stringArray API server authentication mode. Any 1 or more length permutation of: client,server,sso (default [server])
--basehref string Value for base href in index.html. Used if the server is running behind reverse proxy under subpath different from /. Defaults to the environment variable BASE_HREF. (default "/")
-b, --browser enable automatic launching of the browser [local mode]
--configmap string Name of K8s configmap to retrieve workflow controller configuration (default "workflow-controller-configmap")
--event-operation-queue-size int how many events operations that can be queued at once (default 16)
--event-worker-count int how many event workers to run (default 4)
-h, --help help for server
--hsts Whether or not we should add a HTTP Secure Transport Security header. This only has effect if secure is enabled. (default true)
--managed-namespace string namespace that watches, default to the installation namespace
--namespaced run as namespaced mode
-p, --port int Port to listen on (default 2746)
```

### Options inherited from parent commands
Expand Down
Loading

0 comments on commit 71d6128

Please sign in to comment.