= Master Trait

// Start of autogenerated code - DO NOT EDIT! (badges)
[.badges]
[.badge-key]##Deprecated since##[.badge-unsupported]##2.9.0##
// End of autogenerated code - DO NOT EDIT! (badges)
// Start of autogenerated code - DO NOT EDIT! (description)
The Master trait allows to configure the integration to automatically leverage Kubernetes resources for doing
leader election and starting *master* routes only on certain instances.

It's activated automatically when using the master endpoint in a route, e.g. `from("master:lockname:telegram:bots")...`.

NOTE: this trait adds special permissions to the integration service account in order to read/write configmaps and read pods.
It's recommended to use a different service account than "default" when running the integration.

WARNING: The Master trait is **deprecated** and will be removed in future release versions.
This trait requires the operator to manage RBAC explicitly, which should be avoided for security
and simplicity reasons. Users should manually create the required Role and RoleBinding, then configure
Quarkus properties directly:

	-p quarkus.camel.cluster.kubernetes.resource-name=<integration>-lock
	-p quarkus.camel.cluster.kubernetes.resource-type=Lease
	-p quarkus.camel.cluster.kubernetes.labels."camel.apache.org/integration"=<integration-name>


This trait is available in the following profiles: **Kubernetes, Knative, OpenShift**.

// End of autogenerated code - DO NOT EDIT! (description)
// Start of autogenerated code - DO NOT EDIT! (configuration)
== Configuration

Trait properties can be specified when running any integration with the CLI:
[source,console]
----
$ kamel run --trait master.[key]=[value] --trait master.[key2]=[value2] integration.yaml
----
The following configuration options are available:

[cols="2m,1m,5a"]
|===
|Property | Type | Description

| master.enabled
| bool
| Can be used to enable or disable a trait. All traits share this common property.

| master.auto
| bool
| Enables automatic configuration of the trait.

| master.include-delegate-dependencies
| bool
| When this flag is active, the operator analyzes the source code to add dependencies required by delegate endpoints.
E.g. when using `master:lockname:timer`, then `camel:timer` is automatically added to the set of dependencies.
It's enabled by default.

| master.resource-name
| string
| Name of the configmap that will be used to store the lock. Defaults to "<integration-name>-lock".
Name of the configmap/lease resource that will be used to store the lock. Defaults to "<integration-name>-lock".

| master.resource-type
| string
| Type of Kubernetes resource to use for locking ("ConfigMap" or "Lease"). Defaults to "Lease".

| master.label-key
| string
| Label that will be used to identify all pods contending the lock. Defaults to "camel.apache.org/integration".

| master.label-value
| string
| Label value that will be used to identify all pods contending the lock. Defaults to the integration name.

|===

// End of autogenerated code - DO NOT EDIT! (configuration)

== Migration Guide

The Master trait is deprecated and will be removed in a future release. This trait requires the operator to manage RBAC explicitly, which should be avoided for security and simplicity reasons.

=== Why Migrate?

* **Reduced Operator Permissions**: The operator no longer needs permissions to create Role and RoleBinding resources
* **Explicit RBAC Control**: Users have full control over the RBAC configuration
* **Simplified Security Model**: Better separation of concerns between integration and infrastructure

=== Migration Steps

==== Step 1: Create RBAC Resources Manually

Apply the following RBAC resources to your namespace:

[source,yaml]
----
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: <integration-name>-master
rules:
  - apiGroups:
      - coordination.k8s.io
    resources:
      - leases
    verbs:
      - create
      - delete
      - deletecollection
      - get
      - list
      - patch
      - update
      - watch
  - apiGroups:
      - ""
    resources:
      - pods
    verbs:
      - get
      - list
      - watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: <integration-name>-master
subjects:
  - kind: ServiceAccount
    name: <service-account-name>
roleRef:
  kind: Role
  name: <integration-name>-master
  apiGroup: rbac.authorization.k8s.io
----

==== Step 2: Configure Quarkus Properties

Instead of using the trait properties, configure the equivalent Quarkus properties directly:

[cols="2m,2m,3a"]
|===
|Master Trait Property | Quarkus Property | Description

| master.resource-name
| quarkus.camel.cluster.kubernetes.resource-name
| Name of the lock resource

| master.resource-type
| quarkus.camel.cluster.kubernetes.resource-type
| Type of Kubernetes resource (Lease or ConfigMap)

| master.label-key / master.label-value
| quarkus.camel.cluster.kubernetes.labels."<key>"
| Labels for pod identification

|===

==== Example Migration

**Before (using deprecated trait):**
[source,console]
----
$ kamel run MyRoute.java \
  -t master.resource-name=my-lock \
  -t master.resource-type=Lease \
  -t master.label-key=leader-group \
  -t master.label-value=my-group
----

**After (using Quarkus properties):**
[source,console]
----
# First apply the RBAC resources
$ kubectl apply -f master-rbac.yaml

# Then run with Quarkus properties
$ kamel run MyRoute.java \
  --service-account my-integration-sa \
  -p quarkus.camel.cluster.kubernetes.resource-name=my-lock \
  -p quarkus.camel.cluster.kubernetes.resource-type=Lease \
  -p quarkus.camel.cluster.kubernetes.labels."leader-group"=my-group
----

=== Notes

* The `master:` component in Camel routes continues to work; only the automatic RBAC creation is removed
* Ensure the service account used by the integration has the necessary permissions
* For existing integrations, create the RBAC resources before removing the trait configuration
