Skip to content

Commit

Permalink
Fix #145: allow kamelets of type action and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro authored and oscerd committed Apr 19, 2021
1 parent e22fa6d commit a45e8e6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ Kamelets **MUST** be provided in the *Kubernetes YAML* format, i.e. they **MUST*

The file name of each Kamelet **MUST** follow this specific pattern: `<kamelet-name>.kamelet.yaml`. The `<kamelet-name>` **MUST** match field `metadata` -> `name` inside the Kamelet YAML.

For the time being, we'll accept only two kind of Kamelets:
For the time being, we'll accept only these kinds of Kamelets:

- **Sources**: Kamelets producing data that can be forwarded to any chosen destination. In the Camel jargon, a source can be used consumer-side.
Kamelets belonging to this category **MUST** be marked with label: `camel.apache.org/kamelet.type=source`.
- **Sinks**: Kamelets that accept data with a specific datashape and forward it to an external system. In the Camel jargon, a sink can be used producer-side.
Kamelets belonging to this category **MUST** be marked with label: `camel.apache.org/kamelet.type=sink`.
- **Actions**: Kamelets that can be used as intermediate steps as they both accept and produce data, applying transformations to it or changing the behavior of the whole integration flow (e.g. using enterprise integration patterns). Kamelets belonging to this category **MUST** be marked with label: `camel.apache.org/kamelet.type=action`.

All Kamelets **MUST** provide a value for label `camel.apache.org/kamelet.type`.

Expand Down
38 changes: 29 additions & 9 deletions docs/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func saveImage(k camel.Kamelet, out string) string {
}

func produceDoc(k camel.Kamelet, out string, image string) {
docFile := filepath.Join(out, "pages", k.Name + ".adoc")
docFile := filepath.Join(out, "pages", k.Name+".adoc")

content := "// THIS FILE IS AUTOMATICALLY GENERATED: DO NOT EDIT\n"
content += "= " + image + " " + k.Spec.Definition.Title + "\n"
Expand Down Expand Up @@ -118,7 +118,7 @@ func produceDoc(k camel.Kamelet, out string, image string) {
content += `[width="100%",cols="2,^2,3,^2,^2,^3",options="header"]` + "\n"
content += "|===\n"
content += tableLine("Property", "Name", "Description", "Type", "Default", "Example")

for _, key := range keys {
prop := k.Spec.Definition.Properties[key]
name := key
Expand Down Expand Up @@ -159,7 +159,11 @@ func produceDoc(k camel.Kamelet, out string, image string) {
content += fmt.Sprintf("=== Knative %s\n", strings.Title(tp))
content += "\n"

content += fmt.Sprintf("The `%s` Kamelet can be used as Knative %s by binding it to a Knative object.\n", k.Name, tp)
if tp != "action" {
content += fmt.Sprintf("The `%s` Kamelet can be used as Knative %s by binding it to a Knative object.\n", k.Name, tp)
} else {
content += fmt.Sprintf("The `%s` Kamelet can be used as intermediate step in a binding.\n", k.Name)
}
content += "\n"

sampleConfig := make([]string, 0)
Expand Down Expand Up @@ -200,12 +204,28 @@ func produceDoc(k camel.Kamelet, out string, image string) {
apiVersion: messaging.knative.dev/v1
name: mychannel
`

sourceRef := kameletRef
sinkRef := knativeRef
if tp == "sink" {
var sourceRef string
var sinkRef string
var steps string

switch tp {
case "source":
sourceRef = kameletRef
sinkRef = knativeRef
case "sink":
sourceRef = knativeRef
sinkRef = kameletRef
case "action":
sourceRef = ` ref:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
name: timer-source
properties:
message: "Hello"`
sinkRef = knativeRef
steps = fmt.Sprintf(`
steps:
-%s`, kameletRef[3:])
}

binding := fmt.Sprintf(`apiVersion: camel.apache.org/v1alpha1
Expand All @@ -214,9 +234,9 @@ metadata:
name: %s-binding
spec:
source:
%s sink:
%s%s sink:
%s
`, k.Name, sourceRef, sinkRef)
`, k.Name, sourceRef, steps, sinkRef)

content += fmt.Sprintf(".%s-binding.yaml\n", k.Name)
content += "[source,yaml]\n"
Expand Down
9 changes: 8 additions & 1 deletion docs/modules/ROOT/pages/pdf-action.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This section summarizes how the `pdf-action` can be used in various contexts.

=== Knative Action

The `pdf-action` Kamelet can be used as Knative action by binding it to a Knative object.
The `pdf-action` Kamelet can be used as intermediate step in a binding.

.pdf-action-binding.yaml
[source,yaml]
Expand All @@ -36,6 +36,13 @@ metadata:
spec:
source:
ref:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
name: timer-source
properties:
message: "Hello"
steps:
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
name: pdf-action
Expand Down

0 comments on commit a45e8e6

Please sign in to comment.