Camel K Modeline
Integration files can contain modeline hooks that allow to customize the way integrations are executed via command line. For example:
// camel-k: dependency=mvn:org.my:application:1.0 (1)
import org.apache.camel.builder.RouteBuilder;
public class Hello extends RouteBuilder {
@Override
public void configure() throws Exception {
from("timer:java?period=1000")
.bean(org.my.BusinessLogic) (2)
.log("${body}");
}
}
1 | Modeline import of Maven library |
2 | Usage of a business logic class from the external library |
When the integration code above is executed using the kamel run
CLI command, the modeline options declared in the file are appended to
the list of arguments that are passed to the command.
The kamel
CLI will alert you, printing the full command in the shell:
$ kamel run Hello.java
Modeline options have been loaded from source files
Full command: kamel run Hello.java --dependency mvn:org.my:application:1.0
Multiple options can be specified for an integration. For example, the following modeline options enables 3scale and limits the integration container memory:
// camel-k: trait=3scale.enabled=true trait=container.limit-memory=256Mi (1)
import org.apache.camel.builder.RouteBuilder;
public class ThreeScaleRest extends RouteBuilder {
@Override
public void configure() throws Exception {
rest().get("/")
.route()
.setBody().constant("Hello");
}
}
1 | Enables both the container and 3scale traits, to expose the route via 3scale and limit the container memory. |
All options that are available for the kamel run
command can be specified as modeline options.
The following is a partial list of useful options:
Option | Description |
---|---|
|
Add a build time property or properties file (syntax: [my-key=my-value|file:/path/to/my-conf.properties] |
|
Add a runtime configuration from a Configmap, Secret or file (syntax: [configmap|secret|file]:name[/key], where name represents the local file path or the configmap/secret name and key optionally represents the configmap/secret key to be filtered) |
|
An external library that should be included, e.g. for Maven dependencies |
|
Set an environment variable in the integration container, e.g. |
|
Add a label to the integration pod, e.g., |
|
The integration name |
|
Add an OpenAPI v2 spec (file path) |
|
Trait profile used for deployment |
|
Add a runtime property or properties file (syntax: [my-key=my-value|file:/path/to/my-conf.properties]) |
|
Add a runtime resource from a Configmap, Secret or file (syntax: [configmap|secret|file]:name[/key][@path], where name represents the local file path or the configmap/secret name, key optionally represents the configmap/secret key to be filtered and path represents the destination path) |
|
Configure a trait, e.g. |