From e974fb33381b0a2b63d21932f98832605dda3782 Mon Sep 17 00:00:00 2001 From: haanhvu Date: Wed, 20 Apr 2022 13:22:59 +0700 Subject: [PATCH] Add Mount trait example --- examples/traits/mount/Consumer.java | 26 ++++++++++++++++++++++++ examples/traits/mount/Producer.java | 28 ++++++++++++++++++++++++++ examples/traits/mount/README.md | 14 +++++++++++++ examples/traits/mount/pvc-example.yaml | 11 ++++++++++ 4 files changed, 79 insertions(+) create mode 100644 examples/traits/mount/Consumer.java create mode 100644 examples/traits/mount/Producer.java create mode 100644 examples/traits/mount/README.md create mode 100644 examples/traits/mount/pvc-example.yaml diff --git a/examples/traits/mount/Consumer.java b/examples/traits/mount/Consumer.java new file mode 100644 index 0000000000..d525e9fc6b --- /dev/null +++ b/examples/traits/mount/Consumer.java @@ -0,0 +1,26 @@ +/* + * 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. + */ + +import org.apache.camel.builder.RouteBuilder; + +public class Consumer extends RouteBuilder { + @Override + public void configure() throws Exception { + from("file:/tmp/log/example.log") + .filter(simple("${exchangeProperty.CamelTimerCounter} == 10")); + } +} diff --git a/examples/traits/mount/Producer.java b/examples/traits/mount/Producer.java new file mode 100644 index 0000000000..9156cefc8f --- /dev/null +++ b/examples/traits/mount/Producer.java @@ -0,0 +1,28 @@ +/* + * 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. + */ + +import org.apache.camel.builder.RouteBuilder; + +public class Producer extends RouteBuilder { + @Override + public void configure() throws Exception { + from("timer:tick") + .setBody() + .simple("Hello Camel K! #${exchangeProperty.CamelTimerCounter}") + .log("${body}"); + } +} diff --git a/examples/traits/mount/README.md b/examples/traits/mount/README.md new file mode 100644 index 0000000000..9756b03137 --- /dev/null +++ b/examples/traits/mount/README.md @@ -0,0 +1,14 @@ +# Camel K Mount Trait + + +In this section you will find examples about fine tuning your `Integration` using **Mount** `trait` capability. + + +**Example 1: Mount Persistent Volume Claim on the Integration Pod in a Kubernetes platform** + +Create the Persistent Volume Claim: +`kubectl apply -f pvc-example.yaml` + +Enable the Mount trait in the integrations, mount the Persistent Volume Claim, and log to an external volume: +`kamel run --trait mount.enabled=true --trait mount.volumes=["pvc-example:/tmp/log"] Producer.java -p quarkus.log.file.path=/tmp/log/example.log -p quarkus.log.file.enable=true` +`kamel run --trait mount.enabled=true --trait mount.volumes=["pvc-example:/tmp/log"] Consumer.java` \ No newline at end of file diff --git a/examples/traits/mount/pvc-example.yaml b/examples/traits/mount/pvc-example.yaml new file mode 100644 index 0000000000..5176d1b523 --- /dev/null +++ b/examples/traits/mount/pvc-example.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: pvc-example +spec: + storageClassName: manual + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi \ No newline at end of file