From 7a73ed5ac6d910e6c36a84fc256b0700d1ca2d64 Mon Sep 17 00:00:00 2001 From: Ricardo Zanini Date: Tue, 8 Oct 2024 15:36:23 -0400 Subject: [PATCH] Fix #210 - Add kubebuilder annotations to preserve metadata fields Signed-off-by: Ricardo Zanini --- .gitignore | 2 - Makefile | 38 +- ...erlessworkflow.io_serverlessworkflows.yaml | 1990 +++++++++++++++++ ...rkflow.io_v1alpha1_serverlessworkflow.yaml | 2 +- .../{ => api/v1alpha1}/groupversion_info.go | 6 +- .../v1alpha1/serverlessworkflow_types.go} | 27 +- .../api/v1alpha1/zz_generated.deepcopy.go | 113 + model/common.go | 2 + model/states.go | 2 + model/switch_state.go | 2 + parser/parser_test.go | 1 + .../applicationrequest.multiauth.json | 3 + 12 files changed, 2155 insertions(+), 33 deletions(-) create mode 100644 config/crd/bases/serverlessworkflow.io_serverlessworkflows.yaml rename kubernetes/workflow_cr_example.yaml => config/samples/serverlessworkflow.io_v1alpha1_serverlessworkflow.yaml (97%) rename kubernetes/{ => api/v1alpha1}/groupversion_info.go (90%) rename kubernetes/{k8s_workflow_integration.go => api/v1alpha1/serverlessworkflow_types.go} (87%) create mode 100644 kubernetes/api/v1alpha1/zz_generated.deepcopy.go diff --git a/.gitignore b/.gitignore index 33227af..55109f1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,3 @@ bin *.out .vscode -# ignore config directory generated by the controller-gen tool -config diff --git a/Makefile b/Makefile index e516552..a8f36db 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ addheaders: - @command -v addlicense > /dev/null || go install -modfile=tools.mod -v github.com/google/addlicense + @command -v addlicense > /dev/null || (echo "๐Ÿš€ Installing addlicense..."; go install -modfile=tools.mod -v github.com/google/addlicense) @addlicense -c "The Serverless Workflow Specification Authors" -l apache . fmt: @@ -7,34 +7,46 @@ fmt: @go fmt ./... goimports: - @command -v goimports > /dev/null || go install golang.org/x/tools/cmd/goimports@latest + @command -v goimports > /dev/null || (echo "๐Ÿš€ Installing goimports..."; go install golang.org/x/tools/cmd/goimports@latest) @goimports -w . - lint: - @command -v golangci-lint > /dev/null || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${GOPATH}/bin" - make addheaders - make goimports - make fmt - ./hack/go-lint.sh ${params} + @echo "๐Ÿš€ Running lint..." + @command -v golangci-lint > /dev/null || (echo "๐Ÿš€ Installing golangci-lint..."; curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${GOPATH}/bin") + @make addheaders + @make goimports + @make fmt + @./hack/go-lint.sh ${params} + @echo "โœ… Linting completed!" .PHONY: test coverage="false" test: deepcopy buildergen - make lint + @echo "๐Ÿงช Running tests..." @go test ./... + @echo "โœ… Tests completed!" -.PHONY: deepcopy buildergen deepcopy: $(DEEPCOPY_GEN) ## Download deepcopy-gen locally if necessary. - ./hack/deepcopy-gen.sh deepcopy + @echo "๐Ÿ“ฆ Running deepcopy-gen..." + @./hack/deepcopy-gen.sh deepcopy > /dev/null + @make lint + @echo "โœ… Deepcopy generation and linting completed!" buildergen: $(BUILDER_GEN) ## Download builder-gen locally if necessary. - ./hack/builder-gen.sh buildergen + @echo "๐Ÿ“ฆ Running builder-gen..." + @./hack/builder-gen.sh buildergen > /dev/null + @make lint + @echo "โœ… Builder generation and linting completed!" .PHONY: kube-integration kube-integration: controller-gen - $(CONTROLLER_GEN) rbac:roleName=manager-role crd:allowDangerousTypes=true webhook paths="./..." output:crd:artifacts:config=config/crd/bases + @echo "๐Ÿ“ฆ Generating Kubernetes objects..." + @$(CONTROLLER_GEN) object:headerFile="./hack/boilerplate.txt" paths="./kubernetes/api/..." + @echo "๐Ÿ“ฆ Generating Kubernetes CRDs..." + @$(CONTROLLER_GEN) rbac:roleName=manager-role crd:allowDangerousTypes=true webhook paths="./kubernetes/..." output:crd:artifacts:config=config/crd/bases + @make lint + @echo "โœ… Kubernetes integration completed!" #################################### diff --git a/config/crd/bases/serverlessworkflow.io_serverlessworkflows.yaml b/config/crd/bases/serverlessworkflow.io_serverlessworkflows.yaml new file mode 100644 index 0000000..5584a65 --- /dev/null +++ b/config/crd/bases/serverlessworkflow.io_serverlessworkflows.yaml @@ -0,0 +1,1990 @@ +# Copyright 2024 The Serverless Workflow Specification Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.16.3 + name: serverlessworkflows.serverlessworkflow.io +spec: + group: serverlessworkflow.io + names: + kind: ServerlessWorkflow + listKind: ServerlessWorkflowList + plural: serverlessworkflows + singular: serverlessworkflow + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: ServerlessWorkflow ... + 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.k8s.io/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.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: ServerlessWorkflowSpec defines a base API for integration + test with operator-sdk + properties: + annotations: + description: |- + Annotations List of helpful terms describing the workflows intended purpose, subject areas, or other important + qualities. + items: + type: string + type: array + auth: + description: |- + Auth definitions can be used to define authentication information that should be applied to resources defined + in the operation property of function definitions. It is not used as authentication information for the + function invocation, but just to access the resource containing the function invocation information. + x-kubernetes-preserve-unknown-fields: true + autoRetries: + description: AutoRetries If set to true, actions should automatically + be retried on unchecked errors. Default is false + type: boolean + constants: + additionalProperties: + description: |- + RawMessage is a raw encoded JSON value. + It implements [Marshaler] and [Unmarshaler] and can + be used to delay JSON decoding or precompute a JSON encoding. + format: byte + type: string + description: |- + Constants Workflow constants are used to define static, and immutable, data which is available to + Workflow Expressions. + type: object + dataInputSchema: + description: DataInputSchema URI or Object of the JSON Schema used + to validate the workflow data input + properties: + failOnValidationErrors: + type: boolean + schema: + type: object + required: + - failOnValidationErrors + - schema + type: object + description: + description: Workflow description. + type: string + errors: + description: Defines checked errors that can be explicitly handled + during workflow execution. + items: + description: Error declaration for workflow definitions + properties: + code: + description: |- + Code OnError code. Can be used in addition to the name to help runtimes resolve to technical errors/exceptions. + Should not be defined if error is set to '*'. + type: string + description: + description: OnError description. + type: string + name: + description: Name Domain-specific error name. + type: string + required: + - name + type: object + type: array + events: + items: + description: Event used to define events and their correlations + properties: + correlation: + description: Define event correlation rules for this event. + Only used for consumed events. + items: + description: Correlation define event correlation rules for + an event. Only used for `consumed` events + properties: + contextAttributeName: + description: CloudEvent Extension Context Attribute name + type: string + contextAttributeValue: + description: CloudEvent Extension Context Attribute value + type: string + required: + - contextAttributeName + type: object + type: array + dataOnly: + default: true + description: |- + If `true`, only the Event payload is accessible to consuming Workflow states. If `false`, both event payload + and context attributes should be accessible. Defaults to true. + type: boolean + kind: + default: consumed + description: Defines the CloudEvent as either 'consumed' or + 'produced' by the workflow. Defaults to `consumed`. + enum: + - consumed + - produced + type: string + metadata: + description: Metadata information + x-kubernetes-preserve-unknown-fields: true + name: + description: Unique event name. + type: string + source: + description: CloudEvent source. + type: string + type: + description: CloudEvent type. + type: string + required: + - name + - type + type: object + type: array + expressionLang: + default: jq + description: Identifies the expression language used for workflow + expressions. Default is 'jq'. + enum: + - jq + - jsonpath + - cel + type: string + functions: + items: + description: Function ... + properties: + authRef: + description: References an auth definition name to be used to + access to resource defined in the operation parameter. + type: string + metadata: + description: Metadata information + x-kubernetes-preserve-unknown-fields: true + name: + description: Unique function name + type: string + operation: + description: |- + If type is `rest`, #. + If type is `rpc`, ##. + If type is `expression`, defines the workflow expression. If the type is `custom`, + #. + type: string + type: + default: rest + description: |- + Defines the function type. Is either `custom`, `rest`, `rpc`, `expression`, `graphql`, `odata` or `asyncapi`. + Default is `rest`. + enum: + - rest + - rpc + - expression + - graphql + - odata + - asyncapi + - custom + type: string + required: + - name + - operation + type: object + type: array + id: + description: Workflow unique identifier + type: string + keepActive: + description: |- + If "true", workflow instances is not terminated when there are no active execution paths. + Instance can be terminated with "terminate end definition" or reaching defined "workflowExecTimeout" + type: boolean + key: + description: Key Domain-specific workflow identifier + type: string + metadata: + description: Metadata custom information shared with the runtime. + x-kubernetes-preserve-unknown-fields: true + name: + description: Workflow name + type: string + retries: + items: + description: Retry ... + properties: + delay: + description: Time delay between retry attempts (ISO 8601 duration + format) + type: string + increment: + description: Static value by which the delay increases during + each attempt (ISO 8601 time format) + type: string + jitter: + description: If float type, maximum amount of random time added + or subtracted from the delay between each retry relative to + total delay (between 0 and 1). If string type, absolute maximum + amount of random time added or subtracted from the delay between + each retry (ISO 8601 duration format) + properties: + floatVal: + type: number + strVal: + type: string + type: + description: Type represents the stored type of Float32OrString. + format: int64 + type: integer + type: object + maxAttempts: + anyOf: + - type: integer + - type: string + description: Maximum number of retry attempts. + x-kubernetes-int-or-string: true + maxDelay: + description: Maximum time delay between retry attempts (ISO + 8601 duration format) + type: string + multiplier: + description: Numeric value, if specified the delay between retries + is multiplied by this value. + properties: + floatVal: + type: number + strVal: + type: string + type: + description: Type represents the stored type of Float32OrString. + format: int64 + type: integer + type: object + name: + description: Unique retry strategy name + type: string + required: + - maxAttempts + - name + type: object + type: array + secrets: + description: |- + Secrets allow you to access sensitive information, such as passwords, OAuth tokens, ssh keys, etc, + inside your Workflow Expressions. + items: + type: string + type: array + specVersion: + default: "0.8" + description: Serverless Workflow schema version + type: string + start: + description: Workflow start definition. + x-kubernetes-preserve-unknown-fields: true + states: + description: States ... + items: + properties: + callbackState: + description: callbackState executes a function and waits for + callback event that indicates completion of the task. + properties: + action: + description: Defines the action to be executed. + properties: + actionDataFilter: + description: |- + Filter the state data to select only the data that can be used within function definition arguments + using its fromStateData property. Filter the action results to select only the result data that should + be added/merged back into the state data using its results property. Select the part of state data which + the action data results should be added/merged to using the toStateData property. + properties: + fromStateData: + description: Workflow expression that filters state + data that can be used by the action. + type: string + results: + description: Workflow expression that filters the + actions data results. + type: string + toStateData: + description: |- + Workflow expression that selects a state data element to which the action results should be + added/merged into. If not specified denotes the top-level state data element. + type: string + useResults: + description: |- + If set to false, action data results are not added/merged to state data. In this case 'results' + and 'toStateData' should be ignored. Default is true. + type: boolean + type: object + condition: + description: Expression, if defined, must evaluate to + true for this action to be performed. If false, action + is disregarded. + type: string + eventRef: + description: References a 'trigger' and 'result' reusable + event definitions. + properties: + contextAttributes: + additionalProperties: + type: object + description: Add additional extension context attributes + to the produced event. + type: object + data: + description: |- + If string type, an expression which selects parts of the states data output to become the data (payload) + of the event referenced by triggerEventRef. If object type, a custom object to become the data (payload) + of the event referenced by triggerEventRef. + type: object + invoke: + default: sync + description: Specifies if the function should be + invoked sync or async. Default is sync. + enum: + - async + - sync + type: string + resultEventRef: + description: Reference to the unique name of a 'consumed' + event definition + type: string + resultEventTimeout: + description: |- + Maximum amount of time (ISO 8601 format) to wait for the result event. If not defined it be set to the + actionExecutionTimeout + type: string + triggerEventRef: + description: Reference to the unique name of a 'produced' + event definition, + type: string + required: + - resultEventRef + - triggerEventRef + type: object + functionRef: + description: References a reusable function definition. + properties: + arguments: + additionalProperties: + type: object + description: Arguments (inputs) to be passed to + the referenced function + type: object + invoke: + default: sync + description: Specifies if the function should be + invoked sync or async. Default is sync. + enum: + - async + - sync + type: string + refName: + description: Name of the referenced function. + type: string + selectionSet: + description: Used if function type is graphql. String + containing a valid GraphQL selection set. + type: string + required: + - refName + type: object + id: + description: Defines Unique action identifier. + type: string + name: + description: Defines Unique action name. + type: string + nonRetryableErrors: + description: |- + List of unique references to defined workflow errors for which the action should not be retried. + Used only when `autoRetries` is set to `true` + items: + type: string + type: array + retryRef: + description: References a defined workflow retry definition. + If not defined uses the default runtime retry definition. + type: string + retryableErrors: + description: |- + List of unique references to defined workflow errors for which the action should be retried. + Used only when `autoRetries` is set to `false` + items: + type: string + type: array + sleep: + description: Defines time period workflow execution + should sleep before / after function execution. + properties: + after: + description: |- + Defines amount of time (ISO 8601 duration format) to sleep after function/subflow invocation. + Does not apply if 'eventRef' is defined. + type: string + before: + description: |- + Defines amount of time (ISO 8601 duration format) to sleep before function/subflow invocation. + Does not apply if 'eventRef' is defined. + type: string + type: object + subFlowRef: + description: References a workflow to be invoked. + properties: + invoke: + default: sync + description: |- + Specifies if the subflow should be invoked sync or async. + Defaults to sync. + enum: + - async + - sync + type: string + onParentComplete: + default: terminate + description: |- + onParentComplete specifies how subflow execution should behave when parent workflow completes if invoke + is 'async'. Defaults to terminate. + enum: + - terminate + - continue + type: string + version: + description: Sub-workflow version + type: string + workflowId: + description: Sub-workflow unique id + type: string + required: + - workflowId + type: object + type: object + eventDataFilter: + description: Event data filter definition. + properties: + data: + description: Workflow expression that filters of the + event data (payload). + type: string + toStateData: + description: |- + Workflow expression that selects a state data element to which the action results should be added/merged into. + If not specified denotes the top-level state data element + type: string + useData: + description: |- + If set to false, event payload is not added/merged to state data. In this case 'data' and 'toStateData' + should be ignored. Default is true. + type: boolean + type: object + eventRef: + description: References a unique callback event name in + the defined workflow events. + type: string + timeouts: + description: Time period to wait for incoming events (ISO + 8601 format) + properties: + actionExecTimeout: + description: Default single actions definition execution + timeout (ISO 8601 duration format) + type: string + eventTimeout: + description: Default timeout for consuming defined events + (ISO 8601 duration format) + type: string + stateExecTimeout: + description: Default workflow state execution timeout + (ISO 8601 duration format) + properties: + single: + description: Single state execution timeout, not + including retries (ISO 8601 duration format) + type: string + total: + description: Total state execution timeout, including + retries (ISO 8601 duration format) + type: string + required: + - total + type: object + type: object + required: + - action + - eventRef + type: object + compensatedBy: + description: Unique Name of a workflow state which is responsible + for compensation of this state. + type: string + delayState: + description: delayState Causes the workflow execution to delay + for a specified duration. + properties: + timeDelay: + description: Amount of time (ISO 8601 format) to delay + type: string + required: + - timeDelay + type: object + end: + description: State end definition. + x-kubernetes-preserve-unknown-fields: true + eventState: + description: |- + event states await one or more events and perform actions when they are received. If defined as the + workflow starting state, the event state definition controls when the workflow instances should be created. + properties: + exclusive: + default: true + description: |- + If true consuming one of the defined events causes its associated actions to be performed. If false all + the defined events must be consumed in order for actions to be performed. Defaults to true. + type: boolean + onEvents: + description: Define the events to be consumed and optional + actions to be performed. + items: + description: OnEvents define which actions are be performed + for the one or more events. + properties: + actionMode: + default: sequential + description: Should actions be performed sequentially + or in parallel. Default is sequential. + enum: + - sequential + - parallel + type: string + actions: + description: Actions to be performed if expression + matches + items: + description: Action specify invocations of services + or other workflows during workflow execution. + properties: + actionDataFilter: + description: |- + Filter the state data to select only the data that can be used within function definition arguments + using its fromStateData property. Filter the action results to select only the result data that should + be added/merged back into the state data using its results property. Select the part of state data which + the action data results should be added/merged to using the toStateData property. + properties: + fromStateData: + description: Workflow expression that filters + state data that can be used by the action. + type: string + results: + description: Workflow expression that filters + the actions data results. + type: string + toStateData: + description: |- + Workflow expression that selects a state data element to which the action results should be + added/merged into. If not specified denotes the top-level state data element. + type: string + useResults: + description: |- + If set to false, action data results are not added/merged to state data. In this case 'results' + and 'toStateData' should be ignored. Default is true. + type: boolean + type: object + condition: + description: Expression, if defined, must evaluate + to true for this action to be performed. If + false, action is disregarded. + type: string + eventRef: + description: References a 'trigger' and 'result' + reusable event definitions. + properties: + contextAttributes: + additionalProperties: + type: object + description: Add additional extension context + attributes to the produced event. + type: object + data: + description: |- + If string type, an expression which selects parts of the states data output to become the data (payload) + of the event referenced by triggerEventRef. If object type, a custom object to become the data (payload) + of the event referenced by triggerEventRef. + type: object + invoke: + default: sync + description: Specifies if the function should + be invoked sync or async. Default is sync. + enum: + - async + - sync + type: string + resultEventRef: + description: Reference to the unique name + of a 'consumed' event definition + type: string + resultEventTimeout: + description: |- + Maximum amount of time (ISO 8601 format) to wait for the result event. If not defined it be set to the + actionExecutionTimeout + type: string + triggerEventRef: + description: Reference to the unique name + of a 'produced' event definition, + type: string + required: + - resultEventRef + - triggerEventRef + type: object + functionRef: + description: References a reusable function + definition. + properties: + arguments: + additionalProperties: + type: object + description: Arguments (inputs) to be passed + to the referenced function + type: object + invoke: + default: sync + description: Specifies if the function should + be invoked sync or async. Default is sync. + enum: + - async + - sync + type: string + refName: + description: Name of the referenced function. + type: string + selectionSet: + description: Used if function type is graphql. + String containing a valid GraphQL selection + set. + type: string + required: + - refName + type: object + id: + description: Defines Unique action identifier. + type: string + name: + description: Defines Unique action name. + type: string + nonRetryableErrors: + description: |- + List of unique references to defined workflow errors for which the action should not be retried. + Used only when `autoRetries` is set to `true` + items: + type: string + type: array + retryRef: + description: References a defined workflow retry + definition. If not defined uses the default + runtime retry definition. + type: string + retryableErrors: + description: |- + List of unique references to defined workflow errors for which the action should be retried. + Used only when `autoRetries` is set to `false` + items: + type: string + type: array + sleep: + description: Defines time period workflow execution + should sleep before / after function execution. + properties: + after: + description: |- + Defines amount of time (ISO 8601 duration format) to sleep after function/subflow invocation. + Does not apply if 'eventRef' is defined. + type: string + before: + description: |- + Defines amount of time (ISO 8601 duration format) to sleep before function/subflow invocation. + Does not apply if 'eventRef' is defined. + type: string + type: object + subFlowRef: + description: References a workflow to be invoked. + properties: + invoke: + default: sync + description: |- + Specifies if the subflow should be invoked sync or async. + Defaults to sync. + enum: + - async + - sync + type: string + onParentComplete: + default: terminate + description: |- + onParentComplete specifies how subflow execution should behave when parent workflow completes if invoke + is 'async'. Defaults to terminate. + enum: + - terminate + - continue + type: string + version: + description: Sub-workflow version + type: string + workflowId: + description: Sub-workflow unique id + type: string + required: + - workflowId + type: object + type: object + type: array + eventDataFilter: + description: eventDataFilter defines the callback + event data filter definition + properties: + data: + description: Workflow expression that filters + of the event data (payload). + type: string + toStateData: + description: |- + Workflow expression that selects a state data element to which the action results should be added/merged into. + If not specified denotes the top-level state data element + type: string + useData: + description: |- + If set to false, event payload is not added/merged to state data. In this case 'data' and 'toStateData' + should be ignored. Default is true. + type: boolean + type: object + eventRefs: + description: References one or more unique event names + in the defined workflow events. + items: + type: string + minItems: 1 + type: array + required: + - eventRefs + type: object + minItems: 1 + type: array + timeouts: + description: State specific timeouts. + properties: + actionExecTimeout: + description: Default single actions definition execution + timeout (ISO 8601 duration format) + type: string + eventTimeout: + description: Default timeout for consuming defined events + (ISO 8601 duration format) + type: string + stateExecTimeout: + description: Default workflow state execution timeout + (ISO 8601 duration format) + properties: + single: + description: Single state execution timeout, not + including retries (ISO 8601 duration format) + type: string + total: + description: Total state execution timeout, including + retries (ISO 8601 duration format) + type: string + required: + - total + type: object + type: object + required: + - onEvents + type: object + forEachState: + description: forEachState used to execute actions for each element + of a data set. + properties: + actions: + description: Actions to be executed for each of the elements + of inputCollection. + items: + description: Action specify invocations of services or + other workflows during workflow execution. + properties: + actionDataFilter: + description: |- + Filter the state data to select only the data that can be used within function definition arguments + using its fromStateData property. Filter the action results to select only the result data that should + be added/merged back into the state data using its results property. Select the part of state data which + the action data results should be added/merged to using the toStateData property. + properties: + fromStateData: + description: Workflow expression that filters + state data that can be used by the action. + type: string + results: + description: Workflow expression that filters + the actions data results. + type: string + toStateData: + description: |- + Workflow expression that selects a state data element to which the action results should be + added/merged into. If not specified denotes the top-level state data element. + type: string + useResults: + description: |- + If set to false, action data results are not added/merged to state data. In this case 'results' + and 'toStateData' should be ignored. Default is true. + type: boolean + type: object + condition: + description: Expression, if defined, must evaluate + to true for this action to be performed. If false, + action is disregarded. + type: string + eventRef: + description: References a 'trigger' and 'result' reusable + event definitions. + properties: + contextAttributes: + additionalProperties: + type: object + description: Add additional extension context + attributes to the produced event. + type: object + data: + description: |- + If string type, an expression which selects parts of the states data output to become the data (payload) + of the event referenced by triggerEventRef. If object type, a custom object to become the data (payload) + of the event referenced by triggerEventRef. + type: object + invoke: + default: sync + description: Specifies if the function should + be invoked sync or async. Default is sync. + enum: + - async + - sync + type: string + resultEventRef: + description: Reference to the unique name of a + 'consumed' event definition + type: string + resultEventTimeout: + description: |- + Maximum amount of time (ISO 8601 format) to wait for the result event. If not defined it be set to the + actionExecutionTimeout + type: string + triggerEventRef: + description: Reference to the unique name of a + 'produced' event definition, + type: string + required: + - resultEventRef + - triggerEventRef + type: object + functionRef: + description: References a reusable function definition. + properties: + arguments: + additionalProperties: + type: object + description: Arguments (inputs) to be passed to + the referenced function + type: object + invoke: + default: sync + description: Specifies if the function should + be invoked sync or async. Default is sync. + enum: + - async + - sync + type: string + refName: + description: Name of the referenced function. + type: string + selectionSet: + description: Used if function type is graphql. + String containing a valid GraphQL selection + set. + type: string + required: + - refName + type: object + id: + description: Defines Unique action identifier. + type: string + name: + description: Defines Unique action name. + type: string + nonRetryableErrors: + description: |- + List of unique references to defined workflow errors for which the action should not be retried. + Used only when `autoRetries` is set to `true` + items: + type: string + type: array + retryRef: + description: References a defined workflow retry definition. + If not defined uses the default runtime retry definition. + type: string + retryableErrors: + description: |- + List of unique references to defined workflow errors for which the action should be retried. + Used only when `autoRetries` is set to `false` + items: + type: string + type: array + sleep: + description: Defines time period workflow execution + should sleep before / after function execution. + properties: + after: + description: |- + Defines amount of time (ISO 8601 duration format) to sleep after function/subflow invocation. + Does not apply if 'eventRef' is defined. + type: string + before: + description: |- + Defines amount of time (ISO 8601 duration format) to sleep before function/subflow invocation. + Does not apply if 'eventRef' is defined. + type: string + type: object + subFlowRef: + description: References a workflow to be invoked. + properties: + invoke: + default: sync + description: |- + Specifies if the subflow should be invoked sync or async. + Defaults to sync. + enum: + - async + - sync + type: string + onParentComplete: + default: terminate + description: |- + onParentComplete specifies how subflow execution should behave when parent workflow completes if invoke + is 'async'. Defaults to terminate. + enum: + - terminate + - continue + type: string + version: + description: Sub-workflow version + type: string + workflowId: + description: Sub-workflow unique id + type: string + required: + - workflowId + type: object + type: object + minItems: 0 + type: array + batchSize: + anyOf: + - type: integer + - type: string + description: |- + Specifies how many iterations may run in parallel at the same time. Used if mode property is set to + parallel (default). If not specified, its value should be the size of the inputCollection. + x-kubernetes-int-or-string: true + inputCollection: + description: Workflow expression selecting an array element + of the states' data. + type: string + iterationParam: + description: |- + Name of the iteration parameter that can be referenced in actions/workflow. For each parallel iteration, + this param should contain a unique element of the inputCollection array. + type: string + mode: + default: parallel + description: Specifies how iterations are to be performed + (sequential or in parallel), defaults to parallel. + enum: + - sequential + - parallel + type: string + outputCollection: + description: Workflow expression specifying an array element + of the states data to add the results of each iteration. + type: string + timeouts: + description: State specific timeout. + properties: + actionExecTimeout: + description: Default single actions definition execution + timeout (ISO 8601 duration format) + type: string + stateExecTimeout: + description: Default workflow state execution timeout + (ISO 8601 duration format) + properties: + single: + description: Single state execution timeout, not + including retries (ISO 8601 duration format) + type: string + total: + description: Total state execution timeout, including + retries (ISO 8601 duration format) + type: string + required: + - total + type: object + type: object + required: + - inputCollection + type: object + id: + description: Unique State id. + type: string + injectState: + description: injectState used to inject static data into state + data input. + properties: + data: + additionalProperties: + type: object + description: JSON object which can be set as state's data + input and can be manipulated via filter + minProperties: 1 + type: object + timeouts: + description: State specific timeouts + properties: + stateExecTimeout: + description: Default workflow state execution timeout + (ISO 8601 duration format) + properties: + single: + description: Single state execution timeout, not + including retries (ISO 8601 duration format) + type: string + total: + description: Total state execution timeout, including + retries (ISO 8601 duration format) + type: string + required: + - total + type: object + type: object + required: + - data + type: object + metadata: + description: Metadata information. + x-kubernetes-preserve-unknown-fields: true + name: + description: State name. + type: string + onErrors: + description: States error handling and retries definitions. + items: + description: OnError ... + properties: + end: + description: |- + End workflow execution in case of this error. If retryRef is defined, this ends workflow only if + retries were unsuccessful. + x-kubernetes-preserve-unknown-fields: true + errorRef: + description: ErrorRef Reference to a unique workflow error + definition. Used of errorRefs is not used + type: string + errorRefs: + description: ErrorRefs References one or more workflow + error definitions. Used if errorRef is not used + items: + type: string + type: array + transition: + description: |- + Transition to next state to handle the error. If retryRef is defined, this transition is taken only if + retries were unsuccessful. + x-kubernetes-preserve-unknown-fields: true + type: object + type: array + operationState: + description: operationState defines a set of actions to be performed + in sequence or in parallel. + properties: + actionMode: + default: sequential + description: Specifies whether actions are performed in + sequence or in parallel, defaults to sequential. + enum: + - sequential + - parallel + type: string + actions: + description: Actions to be performed + items: + description: Action specify invocations of services or + other workflows during workflow execution. + properties: + actionDataFilter: + description: |- + Filter the state data to select only the data that can be used within function definition arguments + using its fromStateData property. Filter the action results to select only the result data that should + be added/merged back into the state data using its results property. Select the part of state data which + the action data results should be added/merged to using the toStateData property. + properties: + fromStateData: + description: Workflow expression that filters + state data that can be used by the action. + type: string + results: + description: Workflow expression that filters + the actions data results. + type: string + toStateData: + description: |- + Workflow expression that selects a state data element to which the action results should be + added/merged into. If not specified denotes the top-level state data element. + type: string + useResults: + description: |- + If set to false, action data results are not added/merged to state data. In this case 'results' + and 'toStateData' should be ignored. Default is true. + type: boolean + type: object + condition: + description: Expression, if defined, must evaluate + to true for this action to be performed. If false, + action is disregarded. + type: string + eventRef: + description: References a 'trigger' and 'result' reusable + event definitions. + properties: + contextAttributes: + additionalProperties: + type: object + description: Add additional extension context + attributes to the produced event. + type: object + data: + description: |- + If string type, an expression which selects parts of the states data output to become the data (payload) + of the event referenced by triggerEventRef. If object type, a custom object to become the data (payload) + of the event referenced by triggerEventRef. + type: object + invoke: + default: sync + description: Specifies if the function should + be invoked sync or async. Default is sync. + enum: + - async + - sync + type: string + resultEventRef: + description: Reference to the unique name of a + 'consumed' event definition + type: string + resultEventTimeout: + description: |- + Maximum amount of time (ISO 8601 format) to wait for the result event. If not defined it be set to the + actionExecutionTimeout + type: string + triggerEventRef: + description: Reference to the unique name of a + 'produced' event definition, + type: string + required: + - resultEventRef + - triggerEventRef + type: object + functionRef: + description: References a reusable function definition. + properties: + arguments: + additionalProperties: + type: object + description: Arguments (inputs) to be passed to + the referenced function + type: object + invoke: + default: sync + description: Specifies if the function should + be invoked sync or async. Default is sync. + enum: + - async + - sync + type: string + refName: + description: Name of the referenced function. + type: string + selectionSet: + description: Used if function type is graphql. + String containing a valid GraphQL selection + set. + type: string + required: + - refName + type: object + id: + description: Defines Unique action identifier. + type: string + name: + description: Defines Unique action name. + type: string + nonRetryableErrors: + description: |- + List of unique references to defined workflow errors for which the action should not be retried. + Used only when `autoRetries` is set to `true` + items: + type: string + type: array + retryRef: + description: References a defined workflow retry definition. + If not defined uses the default runtime retry definition. + type: string + retryableErrors: + description: |- + List of unique references to defined workflow errors for which the action should be retried. + Used only when `autoRetries` is set to `false` + items: + type: string + type: array + sleep: + description: Defines time period workflow execution + should sleep before / after function execution. + properties: + after: + description: |- + Defines amount of time (ISO 8601 duration format) to sleep after function/subflow invocation. + Does not apply if 'eventRef' is defined. + type: string + before: + description: |- + Defines amount of time (ISO 8601 duration format) to sleep before function/subflow invocation. + Does not apply if 'eventRef' is defined. + type: string + type: object + subFlowRef: + description: References a workflow to be invoked. + properties: + invoke: + default: sync + description: |- + Specifies if the subflow should be invoked sync or async. + Defaults to sync. + enum: + - async + - sync + type: string + onParentComplete: + default: terminate + description: |- + onParentComplete specifies how subflow execution should behave when parent workflow completes if invoke + is 'async'. Defaults to terminate. + enum: + - terminate + - continue + type: string + version: + description: Sub-workflow version + type: string + workflowId: + description: Sub-workflow unique id + type: string + required: + - workflowId + type: object + type: object + minItems: 0 + type: array + timeouts: + description: State specific timeouts + properties: + actionExecTimeout: + description: Default single actions definition execution + timeout (ISO 8601 duration format) + type: string + stateExecTimeout: + description: Defines workflow state execution timeout. + properties: + single: + description: Single state execution timeout, not + including retries (ISO 8601 duration format) + type: string + total: + description: Total state execution timeout, including + retries (ISO 8601 duration format) + type: string + required: + - total + type: object + type: object + required: + - actions + type: object + parallelState: + description: parallelState Consists of a number of states that + are executed in parallel. + properties: + branches: + description: List of branches for this parallel state. + items: + description: Branch Definition + properties: + actions: + description: Actions to be executed in this branch + items: + description: Action specify invocations of services + or other workflows during workflow execution. + properties: + actionDataFilter: + description: |- + Filter the state data to select only the data that can be used within function definition arguments + using its fromStateData property. Filter the action results to select only the result data that should + be added/merged back into the state data using its results property. Select the part of state data which + the action data results should be added/merged to using the toStateData property. + properties: + fromStateData: + description: Workflow expression that filters + state data that can be used by the action. + type: string + results: + description: Workflow expression that filters + the actions data results. + type: string + toStateData: + description: |- + Workflow expression that selects a state data element to which the action results should be + added/merged into. If not specified denotes the top-level state data element. + type: string + useResults: + description: |- + If set to false, action data results are not added/merged to state data. In this case 'results' + and 'toStateData' should be ignored. Default is true. + type: boolean + type: object + condition: + description: Expression, if defined, must evaluate + to true for this action to be performed. If + false, action is disregarded. + type: string + eventRef: + description: References a 'trigger' and 'result' + reusable event definitions. + properties: + contextAttributes: + additionalProperties: + type: object + description: Add additional extension context + attributes to the produced event. + type: object + data: + description: |- + If string type, an expression which selects parts of the states data output to become the data (payload) + of the event referenced by triggerEventRef. If object type, a custom object to become the data (payload) + of the event referenced by triggerEventRef. + type: object + invoke: + default: sync + description: Specifies if the function should + be invoked sync or async. Default is sync. + enum: + - async + - sync + type: string + resultEventRef: + description: Reference to the unique name + of a 'consumed' event definition + type: string + resultEventTimeout: + description: |- + Maximum amount of time (ISO 8601 format) to wait for the result event. If not defined it be set to the + actionExecutionTimeout + type: string + triggerEventRef: + description: Reference to the unique name + of a 'produced' event definition, + type: string + required: + - resultEventRef + - triggerEventRef + type: object + functionRef: + description: References a reusable function + definition. + properties: + arguments: + additionalProperties: + type: object + description: Arguments (inputs) to be passed + to the referenced function + type: object + invoke: + default: sync + description: Specifies if the function should + be invoked sync or async. Default is sync. + enum: + - async + - sync + type: string + refName: + description: Name of the referenced function. + type: string + selectionSet: + description: Used if function type is graphql. + String containing a valid GraphQL selection + set. + type: string + required: + - refName + type: object + id: + description: Defines Unique action identifier. + type: string + name: + description: Defines Unique action name. + type: string + nonRetryableErrors: + description: |- + List of unique references to defined workflow errors for which the action should not be retried. + Used only when `autoRetries` is set to `true` + items: + type: string + type: array + retryRef: + description: References a defined workflow retry + definition. If not defined uses the default + runtime retry definition. + type: string + retryableErrors: + description: |- + List of unique references to defined workflow errors for which the action should be retried. + Used only when `autoRetries` is set to `false` + items: + type: string + type: array + sleep: + description: Defines time period workflow execution + should sleep before / after function execution. + properties: + after: + description: |- + Defines amount of time (ISO 8601 duration format) to sleep after function/subflow invocation. + Does not apply if 'eventRef' is defined. + type: string + before: + description: |- + Defines amount of time (ISO 8601 duration format) to sleep before function/subflow invocation. + Does not apply if 'eventRef' is defined. + type: string + type: object + subFlowRef: + description: References a workflow to be invoked. + properties: + invoke: + default: sync + description: |- + Specifies if the subflow should be invoked sync or async. + Defaults to sync. + enum: + - async + - sync + type: string + onParentComplete: + default: terminate + description: |- + onParentComplete specifies how subflow execution should behave when parent workflow completes if invoke + is 'async'. Defaults to terminate. + enum: + - terminate + - continue + type: string + version: + description: Sub-workflow version + type: string + workflowId: + description: Sub-workflow unique id + type: string + required: + - workflowId + type: object + type: object + minItems: 1 + type: array + name: + description: Branch name + type: string + timeouts: + description: Branch specific timeout settings + properties: + actionExecTimeout: + description: Single actions definition execution + timeout duration (ISO 8601 duration format) + type: string + branchExecTimeout: + description: Single branch execution timeout duration + (ISO 8601 duration format) + type: string + type: object + required: + - actions + - name + type: object + minItems: 1 + type: array + completionType: + default: allOf + description: Option types on how to complete branch execution. + Defaults to `allOf`. + enum: + - allOf + - atLeast + type: string + numCompleted: + anyOf: + - type: integer + - type: string + description: |- + Used when branchCompletionType is set to atLeast to specify the least number of branches that must complete + in order for the state to transition/end. + x-kubernetes-int-or-string: true + timeouts: + description: State specific timeouts + properties: + branchExecTimeout: + description: Default single branch execution timeout + (ISO 8601 duration format) + type: string + stateExecTimeout: + description: Default workflow state execution timeout + (ISO 8601 duration format) + properties: + single: + description: Single state execution timeout, not + including retries (ISO 8601 duration format) + type: string + total: + description: Total state execution timeout, including + retries (ISO 8601 duration format) + type: string + required: + - total + type: object + type: object + required: + - branches + type: object + sleepState: + description: sleepState suspends workflow execution for a given + time duration. + properties: + duration: + description: Duration (ISO 8601 duration format) to sleep + type: string + timeouts: + description: Timeouts State specific timeouts + properties: + stateExecTimeout: + description: Default workflow state execution timeout + (ISO 8601 duration format) + properties: + single: + description: Single state execution timeout, not + including retries (ISO 8601 duration format) + type: string + total: + description: Total state execution timeout, including + retries (ISO 8601 duration format) + type: string + required: + - total + type: object + type: object + required: + - duration + type: object + stateDataFilter: + description: State data filter. + properties: + input: + description: Workflow expression to filter the state data + input + type: string + output: + description: Workflow expression that filters the state + data output + type: string + type: object + switchState: + description: 'switchState is workflow''s gateways: direct transitions + onf a workflow based on certain conditions.' + properties: + dataConditions: + description: Defines conditions evaluated against data + items: + description: |- + DataCondition specify a data-based condition statement which causes a transition to another workflow state + if evaluated to true. + properties: + condition: + description: Workflow expression evaluated against + state data. Must evaluate to true or false. + type: string + end: + description: Explicit transition to end + properties: + compensate: + description: If set to true, triggers workflow + compensation before workflow execution completes. + Default is false. + type: boolean + continueAs: + description: |- + Defines that current workflow execution should stop, and execution should continue as a new workflow + instance of the provided id + properties: + data: + description: |- + If string type, an expression which selects parts of the states data output to become the workflow data input of + continued execution. If object type, a custom object to become the workflow data input of the continued execution + type: object + version: + description: Version of the workflow to continue + execution as. + type: string + workflowExecTimeout: + description: |- + WorkflowExecTimeout Workflow execution timeout to be used by the workflow continuing execution. + Overwrites any specific settings set by that workflow + properties: + duration: + default: unlimited + description: Workflow execution timeout + duration (ISO 8601 duration format). + If not specified should be 'unlimited'. + type: string + interrupt: + description: |- + If false, workflow instance is allowed to finish current execution. If true, current workflow execution + is stopped immediately. Default is false. + type: boolean + runBefore: + description: Name of a workflow state + to be executed before workflow instance + is terminated. + type: string + required: + - duration + type: object + workflowId: + description: Unique id of the workflow to + continue execution as. + type: string + required: + - workflowId + type: object + produceEvents: + description: Array of producedEvent definitions. + Defines events that should be produced. + items: + description: |- + ProduceEvent Defines the event (CloudEvent format) to be produced when workflow execution completes or during a + workflow transitions. The eventRef property must match the name of one of the defined produced events in the + events definition. + properties: + contextAttributes: + additionalProperties: + type: string + description: Add additional event extension + context attributes. + type: object + data: + description: |- + If String, expression which selects parts of the states data output to become the data of the produced event. + If object a custom object to become the data of produced event. + type: object + eventRef: + description: Reference to a defined unique + event name in the events definition + type: string + required: + - eventRef + type: object + type: array + terminate: + description: If true, completes all execution + flows in the given workflow instance. + type: boolean + type: object + metadata: + description: Metadata information. + x-kubernetes-preserve-unknown-fields: true + name: + description: Data condition name. + type: string + transition: + description: Workflow transition if condition is evaluated + to true + properties: + compensate: + default: false + description: If set to true, triggers workflow + compensation before this transition is taken. + Default is false. + type: boolean + nextState: + description: Name of the state to transition to + next. + type: string + produceEvents: + description: Array of producedEvent definitions. + Events to be produced before the transition + takes place. + items: + description: |- + ProduceEvent Defines the event (CloudEvent format) to be produced when workflow execution completes or during a + workflow transitions. The eventRef property must match the name of one of the defined produced events in the + events definition. + properties: + contextAttributes: + additionalProperties: + type: string + description: Add additional event extension + context attributes. + type: object + data: + description: |- + If String, expression which selects parts of the states data output to become the data of the produced event. + If object a custom object to become the data of produced event. + type: object + eventRef: + description: Reference to a defined unique + event name in the events definition + type: string + required: + - eventRef + type: object + type: array + required: + - nextState + type: object + required: + - condition + - end + type: object + type: array + defaultCondition: + description: |- + Default transition of the workflow if there is no matching data conditions. Can include a transition or + end definition. + properties: + end: + description: "\tIf this state an end state" + x-kubernetes-preserve-unknown-fields: true + transition: + description: |- + Serverless workflow states can have one or more incoming and outgoing transitions (from/to other states). + Each state can define a transition definition that is used to determine which state to transition to next. + x-kubernetes-preserve-unknown-fields: true + type: object + eventConditions: + description: Defines conditions evaluated against events. + items: + description: EventCondition specify events which the switch + state must wait for. + properties: + end: + description: Explicit transition to end + x-kubernetes-preserve-unknown-fields: true + eventDataFilter: + description: Event data filter definition. + properties: + data: + description: Workflow expression that filters + of the event data (payload). + type: string + toStateData: + description: |- + Workflow expression that selects a state data element to which the action results should be added/merged into. + If not specified denotes the top-level state data element + type: string + useData: + description: |- + If set to false, event payload is not added/merged to state data. In this case 'data' and 'toStateData' + should be ignored. Default is true. + type: boolean + type: object + eventRef: + description: References a unique event name in the + defined workflow events. + type: string + metadata: + description: Metadata information. + x-kubernetes-preserve-unknown-fields: true + name: + description: Event condition name. + type: string + transition: + description: Workflow transition if condition is evaluated + to true + x-kubernetes-preserve-unknown-fields: true + required: + - eventRef + type: object + type: array + timeouts: + description: SwitchState specific timeouts + properties: + eventTimeout: + description: |- + Specify the expire value to transitions to defaultCondition. When event-based conditions do not arrive. + NOTE: this is only available for EventConditions + type: string + stateExecTimeout: + description: Default workflow state execution timeout + (ISO 8601 duration format) + properties: + single: + description: Single state execution timeout, not + including retries (ISO 8601 duration format) + type: string + total: + description: Total state execution timeout, including + retries (ISO 8601 duration format) + type: string + required: + - total + type: object + type: object + required: + - defaultCondition + type: object + transition: + description: Next transition of the workflow after the time + delay. + x-kubernetes-preserve-unknown-fields: true + type: + description: stateType can be any of delay, callback, event, + foreach, inject, operation, parallel, sleep, switch + enum: + - delay + - callback + - event + - foreach + - inject + - operation + - parallel + - sleep + - switch + type: string + usedForCompensation: + description: If true, this state is used to compensate another + state. Default is false. + type: boolean + required: + - name + - type + type: object + minItems: 1 + type: array + x-kubernetes-preserve-unknown-fields: true + timeouts: + description: Defines the workflow default timeout settings. + properties: + actionExecTimeout: + description: ActionExecTimeout Single actions definition execution + timeout duration (ISO 8601 duration format). + type: string + branchExecTimeout: + description: BranchExecTimeout Single branch execution timeout + duration (ISO 8601 duration format). + type: string + eventTimeout: + description: EventTimeout Timeout duration to wait for consuming + defined events (ISO 8601 duration format). + type: string + stateExecTimeout: + description: StateExecTimeout Total state execution timeout (including + retries) (ISO 8601 duration format). + properties: + single: + description: Single state execution timeout, not including + retries (ISO 8601 duration format) + type: string + total: + description: Total state execution timeout, including retries + (ISO 8601 duration format) + type: string + required: + - total + type: object + workflowExecTimeout: + description: |- + WorkflowExecTimeout Workflow execution timeout duration (ISO 8601 duration format). If not specified should + be 'unlimited'. + properties: + duration: + default: unlimited + description: Workflow execution timeout duration (ISO 8601 + duration format). If not specified should be 'unlimited'. + type: string + interrupt: + description: |- + If false, workflow instance is allowed to finish current execution. If true, current workflow execution + is stopped immediately. Default is false. + type: boolean + runBefore: + description: Name of a workflow state to be executed before + workflow instance is terminated. + type: string + required: + - duration + type: object + type: object + version: + description: Workflow version. + type: string + required: + - specVersion + - states + type: object + status: + description: ServerlessWorkflowStatus ... + properties: + observedGeneration: + format: int64 + type: integer + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/kubernetes/workflow_cr_example.yaml b/config/samples/serverlessworkflow.io_v1alpha1_serverlessworkflow.yaml similarity index 97% rename from kubernetes/workflow_cr_example.yaml rename to config/samples/serverlessworkflow.io_v1alpha1_serverlessworkflow.yaml index 5d79bfa..5faa2c0 100644 --- a/kubernetes/workflow_cr_example.yaml +++ b/config/samples/serverlessworkflow.io_v1alpha1_serverlessworkflow.yaml @@ -15,7 +15,7 @@ # This is an example on how the CR would look like when importing the sdk go types into your operator's spec # the cr instantiation would be validated by this issue: https://github.com/serverlessworkflow/sdk-go/issues/152 -apiVersion: io.serverlessworkflow/v08 +apiVersion: io.serverlessworkflow/v1alpha1 kind: ServerlessWorkflow metadata: name: custom.greeting diff --git a/kubernetes/groupversion_info.go b/kubernetes/api/v1alpha1/groupversion_info.go similarity index 90% rename from kubernetes/groupversion_info.go rename to kubernetes/api/v1alpha1/groupversion_info.go index 9b85567..135263e 100644 --- a/kubernetes/groupversion_info.go +++ b/kubernetes/api/v1alpha1/groupversion_info.go @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package kubernetes contains API Schema definitions for the serverless v1alpha1 API group +// Package v1alpha1 contains API Schema definitions for the serverless v1alpha1 API group // +kubebuilder:object:generate=true -// +groupName=sdk.serverless.workflow -package kubernetes +// +groupName=serverlessworkflow.io +package v1alpha1 import ( "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/kubernetes/k8s_workflow_integration.go b/kubernetes/api/v1alpha1/serverlessworkflow_types.go similarity index 87% rename from kubernetes/k8s_workflow_integration.go rename to kubernetes/api/v1alpha1/serverlessworkflow_types.go index 0f929c0..7144062 100644 --- a/kubernetes/k8s_workflow_integration.go +++ b/kubernetes/api/v1alpha1/serverlessworkflow_types.go @@ -12,12 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -package kubernetes +package v1alpha1 import ( "github.com/serverlessworkflow/sdk-go/v2/model" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" ) // This package provides a very simple api for kubernetes operator to test the integration @@ -36,6 +35,7 @@ import ( // TODO add a webhook example // ServerlessWorkflowSpec defines a base API for integration test with operator-sdk +// +k8s:openapi-gen=true type ServerlessWorkflowSpec struct { model.Workflow `json:",inline"` } @@ -49,8 +49,17 @@ type ServerlessWorkflow struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec ServerlessWorkflowSpec `json:"spec,omitempty"` - Status string `json:"status,omitempty"` + Spec ServerlessWorkflowSpec `json:"spec,omitempty"` + Status ServerlessWorkflowStatus `json:"status,omitempty"` +} + +// ServerlessWorkflowStatus ... +// +k8s:openapi-gen=true +type ServerlessWorkflowStatus struct { + // add your conditions struct here ... + + // +optional + ObservedGeneration int64 `json:"observedGeneration,omitempty"` } // ServerlessWorkflowList contains a list of SDKServerlessWorkflow @@ -62,16 +71,6 @@ type ServerlessWorkflowList struct { Items []ServerlessWorkflow `json:"items"` } -func (S ServerlessWorkflowList) DeepCopyObject() runtime.Object { - //TODO implement me - panic("implement me") -} - -func (S ServerlessWorkflow) DeepCopyObject() runtime.Object { - //TODO implement me - panic("implement me") -} - func init() { SchemeBuilder.Register(&ServerlessWorkflow{}, &ServerlessWorkflowList{}) } diff --git a/kubernetes/api/v1alpha1/zz_generated.deepcopy.go b/kubernetes/api/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 0000000..453a82c --- /dev/null +++ b/kubernetes/api/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,113 @@ +//go:build !ignore_autogenerated + +// Copyright 2023 The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by controller-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ServerlessWorkflow) DeepCopyInto(out *ServerlessWorkflow) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServerlessWorkflow. +func (in *ServerlessWorkflow) DeepCopy() *ServerlessWorkflow { + if in == nil { + return nil + } + out := new(ServerlessWorkflow) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ServerlessWorkflow) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ServerlessWorkflowList) DeepCopyInto(out *ServerlessWorkflowList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ServerlessWorkflow, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServerlessWorkflowList. +func (in *ServerlessWorkflowList) DeepCopy() *ServerlessWorkflowList { + if in == nil { + return nil + } + out := new(ServerlessWorkflowList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ServerlessWorkflowList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ServerlessWorkflowSpec) DeepCopyInto(out *ServerlessWorkflowSpec) { + *out = *in + in.Workflow.DeepCopyInto(&out.Workflow) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServerlessWorkflowSpec. +func (in *ServerlessWorkflowSpec) DeepCopy() *ServerlessWorkflowSpec { + if in == nil { + return nil + } + out := new(ServerlessWorkflowSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ServerlessWorkflowStatus) DeepCopyInto(out *ServerlessWorkflowStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServerlessWorkflowStatus. +func (in *ServerlessWorkflowStatus) DeepCopy() *ServerlessWorkflowStatus { + if in == nil { + return nil + } + out := new(ServerlessWorkflowStatus) + in.DeepCopyInto(out) + return out +} diff --git a/model/common.go b/model/common.go index 6a9be3b..6993de7 100644 --- a/model/common.go +++ b/model/common.go @@ -18,6 +18,8 @@ package model type Common struct { // Metadata information // +optional + // +kubebuilder:validation:Schemaless + // +kubebuilder:pruning:PreserveUnknownFields Metadata Metadata `json:"metadata,omitempty"` } diff --git a/model/states.go b/model/states.go index fa834f7..a19429d 100644 --- a/model/states.go +++ b/model/states.go @@ -100,6 +100,8 @@ type BaseState struct { End *End `json:"end,omitempty"` // Metadata information. // +optional + // +kubebuilder:validation:Schemaless + // +kubebuilder:pruning:PreserveUnknownFields Metadata *Metadata `json:"metadata,omitempty"` } diff --git a/model/switch_state.go b/model/switch_state.go index 15d1a6d..88d0c83 100644 --- a/model/switch_state.go +++ b/model/switch_state.go @@ -141,6 +141,8 @@ type DataCondition struct { Condition string `json:"condition" validate:"required"` // Metadata information. // +optional + // +kubebuilder:validation:Schemaless + // +kubebuilder:pruning:PreserveUnknownFields Metadata Metadata `json:"metadata,omitempty"` // TODO End or Transition needs to be exclusive tag, one or another should be set. // Explicit transition to end diff --git a/parser/parser_test.go b/parser/parser_test.go index 8cc3de1..760f181 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -237,6 +237,7 @@ func TestFromFile(t *testing.T) { // metadata assert.Equal(t, model.Metadata{"metadata1": model.FromString("metadata1"), "metadata2": model.FromString("metadata2")}, w.Metadata) assert.Equal(t, model.Metadata{"auth1": model.FromString("auth1"), "auth2": model.FromString("auth2")}, auth[0].Properties.Bearer.Metadata) + assert.Equal(t, &model.Metadata{"metadataState": model.FromString("state info")}, w.States[0].Metadata) }, }, { "./testdata/workflows/applicationrequest.rp.json", func(t *testing.T, w *model.Workflow) { diff --git a/parser/testdata/workflows/applicationrequest.multiauth.json b/parser/testdata/workflows/applicationrequest.multiauth.json index cd7391d..0bdfe5f 100644 --- a/parser/testdata/workflows/applicationrequest.multiauth.json +++ b/parser/testdata/workflows/applicationrequest.multiauth.json @@ -48,6 +48,9 @@ { "name": "CheckApplication", "type": "switch", + "metadata": { + "metadataState": "state info" + }, "dataConditions": [ { "condition": "${ .applicants | .age >= 18 }",