Skip to content

Commit

Permalink
Add Mount trait example
Browse files Browse the repository at this point in the history
  • Loading branch information
haanhvu committed Apr 14, 2022
1 parent cd0d0a1 commit c73c9e1
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/traits/mount/Consumer.java
Original file line number Diff line number Diff line change
@@ -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"));
}
}
28 changes: 28 additions & 0 deletions examples/traits/mount/Producer.java
Original file line number Diff line number Diff line change
@@ -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}"");
}
}
17 changes: 17 additions & 0 deletions examples/traits/mount/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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 (Static Volume Provisioning)**

Requirement: Persistent Volume already created.

Create the Pod and the Persistent Volume Claim:
`kubectl apply -f pod-example.yaml`
`kubectl apply -f pvc-example.yaml`

Enable the Mount trait in the integrations, mount the Persistent Volume Claim in the Pod, 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`
11 changes: 11 additions & 0 deletions examples/traits/mount/pod-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Pod
metadata:
name: pod-example
spec:
containers:
- name: nginx
image: nginx:1.14.2
volumeMounts:
- mountPath: /tmp/log
name: vm-example
11 changes: 11 additions & 0 deletions examples/traits/mount/pvc-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-example
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi

0 comments on commit c73c9e1

Please sign in to comment.