Camel Components

Kubernetes Cronjob

Since Camel 4.3

Only producer is supported

The Kubernetes CronJob component is one of Kubernetes Components which provides a producer to execute kubernetes CronJob operations.

Configuring Options

Camel components are configured on two separate levels:

  • component level

  • endpoint level

Configuring Component Options

At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.

For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

You can configure components using:

  • the Component DSL.

  • in a configuration file (application.properties, *.yaml files, etc).

  • directly in the Java code.

Configuring Endpoint Options

You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

A good practice when configuring options is to use Property Placeholders.

Property placeholders provide a few benefits:

  • They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.

  • They allow externalizing the configuration from the code.

  • They help the code to become more flexible and reusable.

The following two sections list all the options, firstly for the component followed by the endpoint.

Component Options

The Kubernetes Cronjob component supports the following options which are listed below.

Name Description Default Type

kubernetesClient (producer)

Autowired An existing Kubernetes client for the endpoints of this component that do not set their own kubernetesClient option. The endpoints then do not use the options that configure the client (masterUrl, credentials, certificates, trustCerts, apiVersion, connectionTimeout).

KubernetesClient

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

Endpoint Options

The Kubernetes Cronjob endpoint is configured using URI syntax:

kubernetes-cronjob:masterUrl

With the following path and query parameters:

Path Parameters

Name Description Default Type

masterUrl (producer)

Required The URL of the Kubernetes API server, such as https://kubernetes.default.svc. Use local or client to create the Kubernetes client from the auto-detected configuration (kubeconfig file, in-cluster service account, system properties and environment variables) without applying the options that configure the client (credentials, certificates, trustCerts, apiVersion, connectionTimeout). With a URL, the client also starts from the auto-detected configuration, and these options override it. Not used when the kubernetesClient option is set.

String

Query Parameters

Name Description Default Type

apiVersion (producer)

The default API version of the Kubernetes client (the client default is v1). The client uses it only for a resource type that does not give its own version, and the resource types of these components all give theirs.

String

dnsDomain (producer)

Not used. It was the DNS domain for the ServiceCall EIP, which was removed in Camel 4.19.

String

kubernetesClient (producer)

An existing Kubernetes client to use. The options that configure the client (masterUrl, credentials, certificates, trustCerts, apiVersion, connectionTimeout) are then not used, and Camel does not close the client when the endpoint stops.

KubernetesClient

namespace (producer)

The namespace of the resources. For the producer, the CamelKubernetesNamespaceName header takes precedence. When neither is set, the list operations and the consumer cover all namespaces, and the operations on a single resource fail; openshift-deploymentconfigs then uses the namespace of the Kubernetes client, and kubernetes-custom-resources fails. Not used by kubernetes-namespaces, kubernetes-nodes and kubernetes-persistent-volumes, whose resources are cluster-scoped. When Camel creates the client from a URL, it is also the default namespace of the client.

String

operation (producer)

The producer operation to perform, such as listPods or createConfigMap; the page of each component lists its operations. When it is not set, the CamelKubernetesOperation header gives the operation; the option takes precedence over the header.

String

portName (producer)

Not used. It was the port name for the ServiceCall EIP, which was removed in Camel 4.19.

String

portProtocol (producer)

Not used. It was the port protocol for the ServiceCall EIP, which was removed in Camel 4.19.

tcp

String

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

connectionTimeout (advanced)

The timeout in milliseconds to establish a connection to the API server. When it is not set, the Kubernetes client default of 10000 applies; 0 or less leaves the timeout to the HTTP client implementation.

Integer

caCertData (security)

The certificate of the certificate authority (CA) to trust for the API server, as Base64-encoded PEM data. Takes precedence over caCertFile.

String

caCertFile (security)

The path of a PEM file with the certificate of the certificate authority (CA) to trust for the API server. caCertData takes precedence over it.

String

clientCertData (security)

The client certificate for TLS client authentication, as Base64-encoded PEM data. Takes precedence over clientCertFile, and is used only together with clientKeyData or clientKeyFile.

String

clientCertFile (security)

The path of a PEM file with the client certificate for TLS client authentication. Used only together with clientKeyData or clientKeyFile; clientCertData takes precedence over it.

String

clientKeyAlgo (security)

The algorithm of the client private key: RSA (the default of the Kubernetes client) or EC.

String

clientKeyData (security)

The private key for TLS client authentication, as Base64-encoded unencrypted PEM data. Takes precedence over clientKeyFile.

String

clientKeyFile (security)

The path of a file with the private key for TLS client authentication, as unencrypted PEM. clientKeyData takes precedence over it.

String

clientKeyPassphrase (security)

The password with which the Kubernetes client protects the client private key in the key store that it builds in memory (the client default is changeit). It does not decrypt the key, which must be unencrypted.

String

oauthToken (security)

The bearer token to authenticate to the API server, such as a service account token or an OAuth access token. When it is set, username and password are not used.

String

password (security)

The password for HTTP basic authentication to the API server. Used only together with username, and not when oauthToken is set.

String

trustCerts (security)

Whether to trust any certificate of the API server without checking it. This is insecure: set caCertData or caCertFile instead. Setting it to false does not override true from the auto-detected configuration.

Boolean

username (security)

The username for HTTP basic authentication to the API server. Used only together with password, and not when oauthToken is set.

String

Message Headers

The Kubernetes Cronjob component supports the following message header(s), which is/are listed below:

Name Description Default Type

CamelKubernetesOperation (producer)

Constant: KUBERNETES_OPERATION

The operation of the producer, such as listPods or createConfigMap. Used only when the operation option of the endpoint is not set; one of the two is required.

String

CamelKubernetesCronJobLabels (producer)

Constant: KUBERNETES_CRON_JOB_LABELS

The labels, as a map of label keys to values: listCronJobByLabels (where they are required) lists only the CronJobs that have all of them, and createCronJob and updateCronJob set them as the labels of the CronJob.

Map

CamelKubernetesCronJobName (producer)

Constant: KUBERNETES_CRON_JOB_NAME

The name of the CronJob for getCronJob, createCronJob, updateCronJob and deleteCronJob, where it is required.

String

CamelKubernetesCronJobSpec (producer)

Constant: KUBERNETES_CRON_JOB_SPEC

The CronJobSpec of the CronJob to create or update; required for createCronJob and updateCronJob.

CronJobSpec

CamelKubernetesCronJobAnnotations (producer)

Constant: KUBERNETES_CRON_JOB_ANNOTATIONS

The annotations, as a map of keys to values, that createCronJob and updateCronJob set on the CronJob.

Map

Message Body

The message body at each side of the Kubernetes Cronjob component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.

Side Body Description

Producer input

any

Not used: the operations take their input from headers, such as the name of the CronJob in CamelKubernetesCronJobName and its CronJobSpec in CamelKubernetesCronJobSpec.

Producer output

list, pojo, null or unchanged

A List of the CronJobs for the list operations, the CronJob of get, create and update (null when getCronJob finds none), and the body as it was after deleteCronJob.

  • With operation=listCronJob: list

  • With operation=listCronJobByLabels: list

  • With operation=getCronJob: pojo or null

  • With operation=createCronJob: pojo (io.fabric8.kubernetes.api.model.batch.v1.CronJob)

  • With operation=updateCronJob: pojo (io.fabric8.kubernetes.api.model.batch.v1.CronJob)

  • With operation=deleteCronJob: unchanged

The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.

Supported producer operation

  • listCronJob

  • listCronJobByLabels

  • getCronJob

  • createCronJob

  • updateCronJob

  • deleteCronJob

Example

The following route lists the cron jobs of the cluster every minute. The kubernetesClient bean is the client of the cluster, as in the other Kubernetes components:

- route:
    from:
      uri: timer:cronjobs
      parameters:
        period: 60000
      steps:
        - to:
            uri: kubernetes-cronjob:///
            parameters:
              kubernetesClient: "#kubernetesClient"
              operation: listCronJob
        - log:
            message: "The cluster has ${body.size()} cron jobs"