Skip to content

Commit

Permalink
fix(#1980): Implement data type support in KameletBinding
Browse files Browse the repository at this point in the history
- Support data type reference in KameletBinding that automatically adds data type action Kamelet to the resulting integration template flow
- Allow the user to specify the data types for output/input on Kamelet references in a binding
- Camel K automatically adds respective steps (using the data-type-action Kamelet) in order to apply the data type conversion logic
- Update YAKS 0.14.3
  • Loading branch information
christophd authored and squakez committed Mar 13, 2023
1 parent 2cedce4 commit 46edffe
Show file tree
Hide file tree
Showing 21 changed files with 586 additions and 221 deletions.
4 changes: 2 additions & 2 deletions .github/actions/e2e-knative-yaks/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ runs:
- name: Install YAKS
uses: ./.github/actions/kamel-install-yaks
with:
image-name: "docker.io/yaks/yaks"
version: 0.11.0-202206130041
image-name: "docker.io/citrusframework/yaks"
version: 0.14.3

- id: report-problematic
name: List Tests Marked As Problematic
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/kamel-install-yaks/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ description: 'Install YAKS artifacts'
inputs:
version:
description: "The YAKS version"
default: 0.10.0
default: 0.14.3
required: false
image-name:
description: "The YAKS operator image name"
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ build/maven
build/m2
/api_*

# YAKS test output
.yaks-jbang/
_output/

# envrc
.envrc

Expand Down Expand Up @@ -170,4 +174,4 @@ config/**/*.gen.json
*-installer*

# Fabric8 CRDs
java/target
java/target
70 changes: 70 additions & 0 deletions e2e/yaks/common/kamelet-data-types/data-type-action.kamelet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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: camel.apache.org/v1alpha1
kind: Kamelet
metadata:
name: data-type-action
annotations:
camel.apache.org/kamelet.support.level: "Stable"
camel.apache.org/catalog.version: "main-SNAPSHOT"
camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG9kaS5zb3VyY2Vmb3JnZS5uZXQvRFREL3NvZGlwb2RpLTAuZHRkIgogICB4bWxuczppbmtzY2FwZT0iaHR0cDovL3d3dy5pbmtzY2FwZS5vcmcvbmFtZXNwYWNlcy9pbmtzY2FwZSIKICAgdmlld0JveD0iMCAtMjU2IDE3OTIgMTc5MiIKICAgaWQ9InN2ZzMwMjUiCiAgIHZlcnNpb249IjEuMSIKICAgaW5rc2NhcGU6dmVyc2lvbj0iMC40OC4zLjEgcjk4ODYiCiAgIHdpZHRoPSIxMDAlIgogICBoZWlnaHQ9IjEwMCUiCiAgIHNvZGlwb2RpOmRvY25hbWU9ImN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OCAtMTAsMTIgLTEwLDI0IDAsMTAgOSwyMyAyNiwzNiA5OC41LDEwNy41IDcyLjUsNzEuNSA5NC41LDcxLjUgMTMsMCAyNiwtMTAgbCAxMzgsLTEwNyBxIDQ0LDIzIDkxLDM4IDE2LDEzNiAyOSwxODYgNywyOCAzNiwyOCBoIDIyMiBxIDE0LDAgMjQuNSwtOC41IFEgOTE0LDEzOTEgOTE1LDEzNzggbCAyOCwtMTg0IHEgNDksLTE2IDkwLC0zNyBsIDE0MiwxMDcgcSA5LDkgMjQsOSAxMywwIDI1LC0xMCAxMjksLTExOSAxNjUsLTE3MCA3LC04IDcsLTIyIDAsLTEyIC04LC0yMyAtMTUsLTIxIC01MSwtNjYuNSAtMzYsLTQ1LjUgLTU0LC03MC41IDI2LC01MCA0MSwtOTggbCAxODMsLTI4IHEgMTMsLTIgMjEsLTEyLjUgOCwtMTAuNSA4LC0yMy41IHoiCiAgICAgICBpZD0icGF0aDMwMjkiCiAgICAgICBpbmtzY2FwZTpjb25uZWN0b3ItY3VydmF0dXJlPSIwIgogICAgICAgc3R5bGU9ImZpbGw6Y3VycmVudENvbG9yIiAvPgogIDwvZz4KPC9zdmc+Cg=="
camel.apache.org/provider: "Apache Software Foundation"
camel.apache.org/kamelet.group: "Actions"
camel.apache.org/kamelet.namespace: "Transformation"
labels:
camel.apache.org/kamelet.type: "action"
spec:
definition:
title: "Data Type Action"
description: |-
Applies a given data type with respective data transformation.
required:
- format
type: object
properties:
scheme:
title: Component Scheme
description: The data type component scheme enables users to apply Camel component specific data type conversions.
type: string
default: "camel"
example: "camel"
format:
title: Data Type Format
description: Defines the data type that will be applied by this action. The Kamelet catalog supports different data types and performs automatic message conversion according to the given type.
type: string
dependencies:
- "mvn:org.apache.camel.kamelets:camel-kamelets-utils:3.20.1"
- "camel:kamelet"
- "camel:core"
template:
beans:
- name: dataTypeRegistry
type: "#class:org.apache.camel.kamelets.utils.format.DefaultDataTypeRegistry"
- name: dataTypeProcessor
type: "#class:org.apache.camel.kamelets.utils.format.DataTypeProcessor"
property:
- key: scheme
value: '{{scheme}}'
- key: format
value: '{{format}}'
- key: registry
value: '#bean:{{dataTypeRegistry}}'
from:
uri: "kamelet:source"
steps:
- process:
ref: "{{dataTypeProcessor}}"
10 changes: 6 additions & 4 deletions e2e/yaks/common/kamelet-data-types/event-binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ spec:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
name: event-source
properties:
outputFormat: ${outputFormat}
dataTypes:
out:
format: binary
steps:
- ref:
kind: Kamelet
Expand All @@ -37,5 +38,6 @@ spec:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
name: event-sink
properties:
inputFormat: ${inputFormat}
dataTypes:
in:
format: string
33 changes: 8 additions & 25 deletions e2e/yaks/common/kamelet-data-types/event-sink.kamelet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,20 @@ spec:
definition:
title: "Event Sink"
description: "Handles incoming event with data type auto conversion"
required:
- inputFormat
properties:
inputFormat:
title: Input Format
description: The data type to convert incoming events to
type: string
dataTypes:
in:
default: string
types:
string:
mediaType: plain/text
binary:
mediaType: application/octet-stream
dependencies:
- github:apache.camel-kamelets:camel-kamelets-utils:3.x-SNAPSHOT
- "camel:core"
- "camel:kamelet"
template:
beans:
- name: dataTypeRegistry
type: "#class:org.apache.camel.kamelets.utils.format.DefaultDataTypeRegistry"
property:
- key: classpathScan
value: false
- name: inputTypeProcessor
type: "#class:org.apache.camel.kamelets.utils.format.DataTypeProcessor"
property:
- key: scheme
value: 'camel'
- key: format
value: '{{inputFormat}}'
- key: registry
value: '#bean:{{dataTypeRegistry}}'
from:
uri: "kamelet:source"
steps:
- process:
ref: "{{inputTypeProcessor}}"
- to:
uri: "log:info"
33 changes: 8 additions & 25 deletions e2e/yaks/common/kamelet-data-types/event-source.kamelet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,21 @@ spec:
definition:
title: "Event Source"
description: "Produces events in given data type"
required:
- outputFormat
properties:
outputFormat:
title: Output Format
description: The data type of produced events
type: string
dataTypes:
out:
default: string
types:
string:
mediaType: plain/text
binary:
mediaType: application/octet-stream
dependencies:
- github:apache.camel-kamelets:camel-kamelets-utils:3.x-SNAPSHOT
- "camel:core"
- "camel:kamelet"
template:
beans:
- name: dataTypeRegistry
type: "#class:org.apache.camel.kamelets.utils.format.DefaultDataTypeRegistry"
property:
- key: classpathScan
value: false
- name: outputTypeProcessor
type: "#class:org.apache.camel.kamelets.utils.format.DataTypeProcessor"
property:
- key: scheme
value: 'camel'
- key: format
value: '{{outputFormat}}'
- key: registry
value: '#bean:{{dataTypeRegistry}}'
from:
uri: timer:tick
steps:
- set-body:
constant: "Hello from Camel K!"
- process:
ref: "{{outputTypeProcessor}}"
- to: "kamelet:sink"
9 changes: 6 additions & 3 deletions e2e/yaks/common/kamelet-data-types/kamelet-data-types.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ Feature: Kamelets with data types
| delayBetweenAttempts | 4000 |

Scenario: Kamelet event data type conversion
Given variables
| outputFormat | binary |
| inputFormat | string |
Given load KameletBinding event-binding.yaml
Given Camel K integration event-binding is running
Then Camel K integration event-binding should print BodyType: byte[], Body: Hello from Camel K!
Then Camel K integration event-binding should print BodyType: String, Body: Hello from Camel K!

Scenario: Kamelet timer-to-log conversion
Given load KameletBinding timer-to-log.yaml
Given Camel K integration timer-to-log is running
Then Camel K integration timer-to-log should print BodyType: byte[], Body: Hello from Camel K!
Then Camel K integration timer-to-log should print BodyType: String, Body: Hello from Camel K!
63 changes: 0 additions & 63 deletions e2e/yaks/common/kamelet-data-types/log-action.kamelet.yaml

This file was deleted.

44 changes: 44 additions & 0 deletions e2e/yaks/common/kamelet-data-types/timer-to-log.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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: camel.apache.org/v1alpha1
kind: KameletBinding
metadata:
name: timer-to-log
spec:
source:
ref:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
name: timer-source
properties:
message: "Hello from Camel K!"
steps:
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
name: log-action
dataTypes:
in:
format: binary
out:
format: string
sink:
ref:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
name: log-sink
3 changes: 2 additions & 1 deletion e2e/yaks/common/kamelet-data-types/yaks-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ config:
level: INFO
resources:
- event-binding.yaml
- timer-to-log.yaml
pre:
- name: installation
run: |
kubectl apply -f event-source.kamelet.yaml -n $YAKS_NAMESPACE
kubectl apply -f event-sink.kamelet.yaml -n $YAKS_NAMESPACE
kubectl apply -f log-action.kamelet.yaml -n $YAKS_NAMESPACE
kubectl apply -f data-type-action.kamelet.yaml -n $YAKS_NAMESPACE
post:
- name: print dump
if: env:CI=true && failure()
Expand Down
14 changes: 7 additions & 7 deletions pkg/client/camel/clientset/versioned/fake/register.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 46edffe

Please sign in to comment.