Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding s3 bucket sink #5

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 176 additions & 0 deletions aws-s3-sink/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
= Knative connector aws-s3-sink

Knative eventing connector based on https://camel.apache.org/camel-kamelets/[Apache Camel Kamelets].
The connector project creates a container image that is pushed into a registry so the image can be referenced in a Kubernetes deployment.

== Kamelet properties

The kn-connector source images provides these properties that you can set (e.g. via environment properties on the deployment).

.Kamelet properties
include::properties.adoc[]

== Kubernetes manifest

The build produces a Kubernetes manifest in (`target/kubernetes/kubernetes.yml`).
This manifest holds all resources required to run the application on your Kubernetes cluster.

You can customize the Kubernetes resources in link:src/main/kubernetes/kubernetes.yml[src/main/kubernetes/kubernetes.yml].
This is being used as a basis and Quarkus will generate the final manifest in `target/kubernetes/kubernetes.yml` during the build.

The final Kubernetes manifest includes:

* Service
* Deployment
* Trigger

== Kamelet sink Pipe

The sink consumes events from the Knative broker.
It uses an Apache Camel Pipe resource as the central piece of code to define how the Knative events are consumed and where the events get forwarded to.

The Pipe is a YAML file located in link:src/main/resources/camel/kn-connector-sink.yaml[src/main/resources/camel/kn-connector-sink.yaml]

.kn-connector-sink.yaml
[source,yaml]
----
apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
name: kn-connector-aws-s3-sink
spec:
source:
ref:
kind: Broker
apiVersion: eventing.knative.dev/v1
name: default
properties:
type: ""
sink:
ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: aws-s3-sink
----

This connector uses the https://camel.apache.org/camel-kamelets/aws-s3-sink.html[aws-s3-sink] Kamelet and consumes events from the Knative broker.

The Pipe references a Knative broker as a source and connects to a Kamelet as a sink.

The name of the broker is always `default` because the Knative Trigger resource is responsible for connecting the application to the Knative broker.
The Trigger decides when to call the application as it provides the events to the application based on the trigger configuration.

This way the same container image can be used with different brokers and events (e.g. by adding filter criteria to the Trigger).
It is only a matter of configuring the Trigger resource that connects the application with the Knative broker.

You can find a sample Trigger in link:src/main/kubernetes/kubernetes.yml[src/main/kubernetes/kubernetes.yml]

[source,yaml]
----
apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
annotations:
eventing.knative.dev/creator: kn-connectors
labels:
eventing.knative.dev/connector: aws-s3-sink
eventing.knative.dev/broker: default
name: kn-connector-aws-s3-sink
spec:
broker: default
subscriber:
ref:
apiVersion: v1
kind: Service
name: kn-connector-aws-s3-sink
uri: /events
----

== Configuration

Each Kamelet defines a set of properties.
The user is able to customize these properties when running a connector deployment.

=== Environment variables

You can customize the properties via environment variables on the deployment:

.Environment variables
include::properties.adoc[]

The environment variables that overwrite properties on the Kamelet sink follow a naming convention:

* CAMEL_KAMELET_{{KAMELET_NAME}}_{{PROPERTY_NAME}}={{PROPERTY_VALUE}}

The name represents the name of the Kamelet sink as defined in the https://camel.apache.org/camel-kamelets/[Kamelet catalog].

The environment variables may be set as part of the Kubernetes deployment or as an alternative on the Knative ContainerSource:

[source,yaml]
----
apiVersion: sources.knative.dev/v1
kind: ContainerSource
metadata:
name: kamelet-sink
namespace: knative-samples
spec:
template:
spec:
containers:
- image: quay.io/openshift-knative/kn-connector-aws-s3-sink:1.0
name: log
env:
- name: CAMEL_KAMELET_{{KAMELET_NAME}}_{{PROPERTY_NAME}}
value: "true"
- name: CAMEL_KAMELET_{{KAMELET_NAME}}_{{PROPERTY_NAME}}
value: "INFO"
sink:
ref:
apiVersion: eventing.knative.dev/v1
kind: Broker
name: default
----

You can also set the environment variable on the running deployment:

[source,shell]
----
kubectl set env deployment/kn-connector-{{sink-name}} CAMEL_KAMELET_{{KAMELET_NAME}}_{{PROPERTY_NAME}}="true"
----

=== ConfigMap and Secret

You may also mount a configmap/secret to overwrite Kamelet properties with values from the configmap/secret resource.

As the Kamelet properties are configured viw environment variables on the ContainerSource you can also use values referencing a configmap or secret.

[source,yaml]
----
apiVersion: sources.knative.dev/v1
kind: ContainerSource
metadata:
name: kamelet-sink
spec:
template:
spec:
containers:
- image: quay.io/openshift-knative/kn-connector-aws-s3-sink:1.0
name: log
env:
- name: CAMEL_KAMELET_{{KAMELET_NAME}}_{{PROPERTY_NAME}}
valueFrom:
secretKeyRef:
name: my-secret
key: my-property-value
sink:
ref:
apiVersion: eventing.knative.dev/v1
kind: Broker
name: default
----

The example above references a secret called `my-secret` and loads the key `my-property-value`.

== More configuration options

For more information about Apache Camel Kamelets and their individual properties see https://camel.apache.org/camel-kamelets/.
140 changes: 140 additions & 0 deletions aws-s3-sink/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>dev.knative.eventing</groupId>
<artifactId>kn-connectors</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>kn-connector-aws-s3-sink</artifactId>
<name>Knative Connectors :: aws-s3 Sink</name>

<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-platform-http</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-microprofile-health</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-kubernetes</artifactId>
</dependency>

<!-- Kubernetes extension -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-jib</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes</artifactId>
</dependency>

<!-- Kamelet -->
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-kamelet</artifactId>
</dependency>

<!-- Camel components -->
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-aws2-s3</artifactId>
</dependency>

<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-yaml-dsl</artifactId>
</dependency>

<!-- Camel Knative -->
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-knative</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-knative-producer</artifactId>
</dependency>

<dependency>
<groupId>org.apache.camel.kamelets</groupId>
<artifactId>camel-kamelets-utils</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.kamelets</groupId>
<artifactId>camel-kamelets</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-quarkus</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-http</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>dev.knative.eventing</groupId>
<artifactId>kn-connector-maven-plugin</artifactId>
<version>${project.version}</version>
<configuration>
<kameletName>aws-s3-sink</kameletName>
</configuration>
<executions>
<execution>
<id>generate-connector-spec</id>
<phase>process-classes</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
</plugin>
</plugins>
</build>
</project>
4 changes: 4 additions & 0 deletions aws-s3-sink/properties.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
|===
|Property |Required |EnvVar |Description
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider running mvn package once before the PR, so the docs get generated


|===
Loading