Skip to content

Choose a config route

Agent Kourier reads its ChatConnection, AgentBackend and Binding resources from one of two places, chosen when the broker starts. This page says what each route does and how they differ when something is wrong, so that you can choose. Both are supported. Move the config between a ConfigMap and custom resources is the how-to.

The two routes

Files (the quick route) Custom resources (the chart's default)
Set with AGENTKOURIER_CONFIG_SOURCE=files, or unset in the broker's environment (the chart's config.source: files) AGENTKOURIER_CONFIG_SOURCE=crds (the chart's config.source: crds, which is its default)
Where the resources are YAML files in AGENTKOURIER_CONFIG_DIR, usually a mounted ConfigMap Binding, AgentBackend and ChatConnection objects of the group agentkourier.dev in the cluster
Who writes them Whoever edits the ConfigMap or the values Whoever Kubernetes RBAC lets write the objects in each namespace
One bad object The whole config is refused That object is refused; the others carry on
What a Binding's owner sees The broker's log and metrics Binding.status, in kubectl get akbinding
ChatConnections Exactly one in the directory Many in the cluster; the broker serves its own, if it has one (AGENTKOURIER_CHAT_CONNECTION), and those of the namespaces it admits: a list (AGENTKOURIER_CONNECTION_NAMESPACES), a label selector (AGENTKOURIER_CONNECTION_NAMESPACE_SELECTOR), or every namespace when none of the three is set; at most 16 in all
Kubernetes No minimum 1.33 or later, which the chart checks
Extra grants A Role for the Secrets in each namespace A ClusterRole to read the three kinds and write bindings/status (and to list and watch namespaces with a label selector other than {}), and Roles that name the Secrets
Unknown fields The loader refuses the file The API server refuses them at apply, or drops them; the broker ignores one its own types lack (see below)
A change is read At the next check of the files, every 10 seconds, and the chart rolls the pod when its ConfigMap changes At the next check, every 10 seconds

A change that is read is not always applied then. The broker builds the platform of its own ChatConnection when it starts and when a replica takes the lead, so an edit to that connection's spec.teams or spec.webhook applies when Agent Kourier restarts: on files that is the chart's roll (unless config.existingConfigMap is set or config.rollOnChange is false), and on custom resources a restart of the Deployment. Until then the leader logs, once for each edit of spec.webhook or spec.teams it reads that leaves the spec other than the one the connection runs on, a WARN that names the connection in its connection attribute: chat connection: its spec.webhook was edited, and the running connection still uses the spec.webhook it started with; a restart of the broker applies the edit for spec.webhook, and chat connection: its spec.teams was edited, and the running connection still uses the spec.teams it started with; a restart of the broker applies the edit for spec.teams, where mode: http written out or taken out is the same mode and no edit. A team connection restarts by itself when its ChatConnection changes.

The two are never merged and there is no fallback. A broker on files ignores any custom resources in the cluster, and a broker on crds has no config directory. The route is chosen at start: a reload cannot change it, so moving is an upgrade of the release.

Which to choose

Use custom resources for an install that is meant to last on Kubernetes, and when several teams each write their own Bindings. This is the chart's default. One team's typo then leaves the others serving, each team can see what became of its Binding without the operator's log, and RBAC decides who may write what. The price is the grants above, a Kubernetes of 1.33 or later, and the need to think about who may write which object (see What the people who write these objects can do).

Use files for a proof of concept, or when one team writes all the config. One reviewed ConfigMap is one artifact, a mistake is caught before anything serves it, and nothing needs a cluster-scoped grant or a Kubernetes version. It is the quick route, and you set it in the chart with config.source: files.

What a bad object does

Both routes run the same code on each object: the same defaults, the same validation, the same checks between objects. They differ on a field that the broker's types do not have (the files refuse it, the broker ignores it on custom resources: see Unknown fields), and in what they do with a failure.

Files are all or nothing. One resource that does not load fails the config. At start the broker exits with code 2 and names the file and field. On a reload it keeps the last good config, logs config reload failed; keeping the last good snapshot and sets agentkourier_config_stale to 1. A reload whose directory no longer holds just the ChatConnection the broker started with is refused in the same way (Which ChatConnections a broker serves). One owner and one reviewed artifact make that an honest rule.

Custom resources are judged one at a time, because different teams own them and one team's typo must not freeze everyone:

Event What the broker does
An invalid edit of an object that had a good generation Keeps serving the last good generation. A Binding's status says which: Accepted=False with the reason InvalidSpec, and the generation being served in the message.
An invalid new object Does not serve it. A Binding has Accepted=False.
An object is deleted Removes it.
A Binding names an AgentBackend or ChatConnection that does not exist, or that does not allow its namespace Drops the Binding from routing, with a condition (BackendNotFound, ConnectionNotFound, NamespaceNotAllowed).
A Binding names an agent namespace that its AgentBackend's agents field does not allow Drops the Binding from routing, with AgentNamespaceNotAllowed.
A Binding names a chat ID that its ChatConnection's platform does not have (a Microsoft Teams channel on a Slack connection, a Slack channel on a teams connection), or asks for a feature the platform does not serve (approver groups on a teams connection) Refuses that generation as it refuses an invalid one: keeps serving the last good generation, or does not serve a Binding that has none. The status says InvalidPlatformID or UnsupportedOnPlatform, and the generation being served (What each platform supports). Slack serves every feature that the broker checks.
A Binding names an AgentBackend that is invalid Serves the AgentBackend's last good generation, or drops the Binding if it has none, with BackendRejected.
The broker's own ChatConnection is edited into something invalid Keeps serving its last good generation, and each of its Bindings says ConnectionRejected.
A Binding names a ChatConnection that exists and that this broker does not serve If the broker served the connection before and does not now (its namespace is no longer admitted: it was taken off the list, it lost the label the selector matches, the selector changed, or a broker that admitted every namespace was narrowed to a list, a selector or its own connection alone; or it was the broker's own and the setting now names another or none, and its namespace is not admitted), or the connection is past the 16, or it is a second connection of a Slack or Microsoft Teams app, and in all three cases the connection admits the Binding's namespace, the leader writes Accepted=False with ConnectionNotServed, once, and does not put it back, so that a broker that serves the connection has the last word. Otherwise (a connection in a namespace that was never admitted, or a Binding the connection does not admit) nothing reads the Binding and nothing writes its status: READY stays empty. Point connectionRef at a connection that a broker serves.
A Binding's Secret is missing, unreadable or lacks the key Keeps the Binding served. BackendReachable says CredentialsUnreadable.
Two Bindings on one channel The older holds it. The other has ChannelConflict.
An object is edited again and again Serves each read as it was when the read began, and reads again at the next check, so an edit is served within one check (10 seconds) plus up to two reads: the one that is running when it lands, then its own. One team editing its Binding in a loop does not hold back another's. But each read that finds a change moves the config's revision, so the Binding verification pass, which probes every Binding of the connection, runs at most every 30 seconds for as long as the loop lasts, where it would run every 5 minutes (see Binding verification). Measured only in a test against a fake API server in the test process, not against a real API server: a Binding of about 0.4 MiB, edited with a 10 ms pause between edits (50 to 85 edits a second in the runs), took 35 to 50 ms to read, or about 0.5 s under the race detector, and a Binding that another team added during the loop was served 50 to 150 ms later with the test's 100 ms check (1.1 to 1.2 s under the race detector).
The caches have not synced, or the API server is out Publishes nothing new. An empty or failed cache never reads as "everything was removed".
The CRDs are not installed at start The broker exits with code 2.
The broker's own ChatConnection is missing or invalid at start The broker exits with code 2. While it runs, it keeps the last good one and says so in its log and in a metric, including after the object is deleted. A broker with no own connection has no such start failure, and a deleted team connection is dropped when the deletion settles.

Only a Binding has a status. An invalid AgentBackend or ChatConnection shows in the status of each Binding that uses it, in the log (config: an object is refused) and in agentkourier_config_invalid_objects. The reasons are in Binding status and what to do about each is in Troubleshoot an install.

Who holds a channel

On both routes one channel of a ChatConnection takes one Binding. On files two claims fail the whole config: the broker will not start, or a reload is refused, and the error names the Binding that already holds the channel. On custom resources the older Binding, by creationTimestamp and then by namespace and name, holds the channel, and the other is not served and says ChannelConflict. A later Binding cannot take a channel from an older one.

Age alone decides. An older Binding that is edited onto a younger one's channel displaces it, and so does an older Binding whose broken reference heals. A reply in a thread that the displaced Binding started, or one already queued, gets "This thread's agent is no longer set up, so I can't pass your messages on." A new mention in the channel is answered by the Binding that holds it now.

What the custom resource route does not promise

  • The last good generation is kept in memory. A broker that starts during an invalid generation never saw the good one, so it leaves that Binding out until it is fixed. With two replicas the replicas can then disagree: the one that has run since before the edit serves the last good generation, and the other serves nothing for it. A failover during such a time takes the Binding out of routing, and can change which Binding holds a channel.
  • An AgentBackend has no status. Its owner is not told when an edit is refused by the broker, only the Bindings that use it. An edit that narrows allowedNamespaces and is refused leaves the old, wider list in force. A schema refusal comes back at apply; a refusal that only the broker makes does not, so read the log or agentkourier_config_invalid_objects after changing an AgentBackend or a ChatConnection.
  • A Binding that is not served keeps its sessions. Retention skips the sessions of a Binding that exists and was refused, until it is served again or deleted, so a Binding left broken keeps its sessions indefinitely.
  • Deleting a ChatConnection does not stop routing, if it is the broker's own. A broker holds its own ChatConnection at its last good generation after it is deleted, and with it the Bindings of it that are gone and the AgentBackends they use, until the connection returns or the broker restarts. That is what lets a move back to the ConfigMap keep the old pods routing while they end (the how-to has the details, and agentkourier_config_held_objects says what is held). A Binding deleted alone, while its connection exists, stops in about 10 to 20 seconds, behind a stream of other deletions in about 80 at most; one deleted while its connection is held stays held, so bring the connection back first. A held Binding keeps its channel against a newer one, and a Binding that was just deleted keeps it for up to about 20 seconds, longer behind a stream of other deletions.
  • Deleting a CRD deletes every object of the kind. Deleting the Bindings CRD alone stops the Bindings within about 20 seconds (longer behind a stream of other deletions), and a new mention gets no answer. Deleting all three takes the own connection with them, and a broker that has one holds the rest and keeps routing. In both the broker sets agentkourier_config_stale to 1, and a restart exits with code 2.

What is checked, and where

A custom resource is checked twice: by the API server when it is applied, and by the broker when it reads it. The broker's check is the authority. The CRDs carry a copy of most of its rules, as OpenAPI schema (types, enums, patterns, lengths and counts) and CEL rules, so that kubectl apply fails fast, naming the field. A test holds the copy to the broker on a real API server: an object that the schema refuses is one that the broker refuses too, so nothing is accepted on the file route that the schema refuses.

$ kubectl apply -f bad.yaml
The Binding "bad" is invalid:
* spec.chat.channel: Invalid value: "general": spec.chat.channel in body should match '^(?:[CG][A-Z0-9]+|19:[A-Za-z0-9._-]+@thread\.(?:tacv2|skype))$'
* spec.identity: Invalid value: "object": set userId, tokenSecretRef, or both

Refused at apply by the schema or a CEL rule: the wrong type, a value outside an enum, a pattern or a length, a missing required field, a count over a cap, and most of the rules between the fields of one object.

Left to the broker, which reports them as Accepted=False after the object is stored: a regex in a trigger's match, exclude or extract that does not compile, or compiles to more than 2000 instructions, or takes the regexes of a Binding past 5000 instructions together; a trigger's promptTemplate that does not parse, names an extract the trigger lacks, or fails when it runs; a duplicate trigger; the parts of a URL that only Go's parser refuses (a bad percent escape, port or bracket); a match or exclude value of 512 characters or fewer that is over 512 bytes; and every rule that spans objects: that the AgentBackend and ChatConnection exist and allow the namespace, that the AgentBackend's agents field allows the agent namespace, that the dialect has an adapter, that one Binding holds the channel, that a Secret has its key, and that each chat ID has the shape of the IDs of the ChatConnection's platform and the platform serves what the Binding asks for. The schema takes the shape of either platform's ID, Slack's or Microsoft Teams', so a channel's name such as general, or a bot's name such as alertmanager as a sender, is refused at apply and never stored; a Slack connection's Binding with a Microsoft Teams channel is stored and then refused by the broker: a new one is not served, and an edit of a served one does not take (What each platform supports).

The caps (50 triggers in a Binding, 32 extract entries in a trigger, 32 headers and 256 bytes of a header's name in an AgentBackend) apply on both routes, because the schema and the broker's own validation both have them. Upgrade says how to find a config over one before you upgrade.

Unknown fields

A field that the schema does not have is refused by default when you use kubectl or Helm 4, and the API server drops it when the client does not ask it to refuse. For a Binding with spec.chat.bogusField, with kubectl 1.37.1 and Helm 4 (another kubectl may differ):

Client Result
kubectl apply, kubectl create Refused: strict decoding error: unknown field "spec.chat.bogusField"
kubectl apply --server-side Refused: .spec.chat.bogusField: field not declared in schema
kubectl apply --validate=warn Stored without the field, with Warning: unknown field "spec.chat.bogusField"
kubectl apply --validate=false Stored without the field, and no message
helm upgrade, with the field in a config.* value Refused: field not declared in schema, and the release goes to failed, after Helm has applied the objects ahead of it: on the move to custom resources that includes the Deployment (what to do)

On the files route the loader refuses a file with a field it does not know, and so the whole config. On the custom resource route the API server's schema decides what an object may hold, and a client that asks it to refuse unknown fields is refused (the table); one that does not, such as --validate=false, has the field dropped silently, and the object runs without it, so a field that a release removed is ignored without an error. What Argo CD does with an unknown field is not covered here.

A broker older than its CRDs ignores a field it does not know. The broker does not refuse an object on the custom resource route because of a field that its own types lack, in the spec, the status or the metadata of a Binding, an AgentBackend or a ChatConnection: the field is ignored and the object is read as the rest of it says. This is what lets an older broker keep serving under newer CRDs. The CRDs are applied before an upgrade, and rolling back only the image leaves them new; a later release can add a field with a default, and the API server then adds that field to every stored object it returns, without a change of the object's generation. If the broker refused such a field it would serve no Binding at all, and a broker that cannot read its own ChatConnection, if it has one, would not start. A field that the broker's types do have, with a value that they cannot read or that fails validation, is still refused.

The broker says what it ignored: one warning for each object, for each generation of it, a custom resource has fields this broker does not know, and ignores them, with the kind, namespace, name and generation of the object and the path of each field (spec.chat.futureField, at most ten of them, and their count as unknown_fields), and never a value. What tells an operator that the CRDs and the broker differ is agentkourier_crd_schema_state, which reads mismatch for a CRD whose annotation agentkourier.dev/schema-sha256 is not the hash of the schema the broker was built with, as when the CRDs come from a newer chart release than the image. It cannot see every difference: a CRD that was edited by hand keeps its annotation and reads match, and one that has no annotation reads unannotated. To end the mismatch, bring the CRDs and the image to the same chart release.

Which ChatConnections a broker serves

On files the directory holds exactly one ChatConnection: the broker refuses to start with none or with more, and AGENTKOURIER_CHAT_CONNECTION, AGENTKOURIER_CONNECTION_NAMESPACES and AGENTKOURIER_CONNECTION_NAMESPACE_SELECTOR are refused. While it runs it serves the connection it started with, by namespace and name, until it restarts: a reload whose directory renames that connection, adds a second or takes it away is refused, so the broker keeps the last good config, its Bindings included, sets agentkourier_config_stale to 1 and logs config reload failed; keeping the last good snapshot with the error the directory holds the ChatConnections [acme-webhooks/github2], and the files route serves the ChatConnection it started with, acme-webhooks/github, until the broker restarts. A restart reads the directory as it is then: the chart's roll does it when the ConfigMap changes (unless config.existingConfigMap is set or config.rollOnChange is false). An edit of the connection under the same name is taken, and applies at a restart, or when another replica takes the lead.

On custom resources a cluster can hold many connections. A broker may have an own connection, named as namespace/name in AGENTKOURIER_CHAT_CONNECTION; if it has one, it always serves it. It also serves the ChatConnections of the namespaces it admits, except a second connection of a Slack or Microsoft Teams app that it already serves, which it refuses, so that a team can bring its own chat app without running a broker (Let a team bring its own Slack app). It admits:

AGENTKOURIER_CHAT_CONNECTION AGENTKOURIER_CONNECTION_NAMESPACES AGENTKOURIER_CONNECTION_NAMESPACE_SELECTOR The broker serves the ChatConnections of
unset unset unset every namespace
any any {} every namespace, and its own, if it has one
any a list unset the listed namespaces, and its own, if it has one
any unset a selector the namespaces whose labels match it, and its own, if it has one
any a list a selector the listed namespaces and those whose labels match, and its own, if it has one
set unset unset none: its own alone

The list is read at start, so a change to it is a restart. The selector is read at start too, but the namespaces' labels are followed live, with an informer on namespaces: a namespace that gains a matching label is admitted at the next read, every 10 seconds, and one that loses it stops being admitted at the next read, with no restart. While the broker cannot reach the API server it keeps the labels it last read. Only a selector other than {} reads namespaces, and so needs list and watch on them; every namespace and a list read none. The first line of the log, config route, names the admission in connection_admission (all, list, selector, list+selector, or own for none besides the own connection), with connection_namespaces when there is a list and connection_namespace_selector when there is a selector other than {}.

Every namespace is a setting for a cluster with one broker. A broker that admits every namespace serves a second broker's connections too, that broker's own included, and the two open Socket Mode on the same Slack apps, so each event goes to one of them and the other misses it. Both serve the same Bindings, and where their words differ each puts back the status the other writes: the leader logs binding status: something else keeps changing the status of a Binding, and this broker keeps putting it back once it has put one back three times in a row, and counts each in agentkourier_binding_status_writes_total{result="put_back"} (Troubleshoot). With two brokers in a cluster, give each its own connections and admit with a list or a selector that the other's do not overlap.

With no own connection the broker serves only the teams' connections (A broker with no connection of its own). What an own connection has that a team connection does not: a token Slack rejects ends the process with code 1, where a team connection stops alone; its ChatConnection is held when it is deleted; and it takes the first of the 16 places and the first claim of its Slack app. A broker with no own connection stays up, and ready, when every token is rejected, and serves the 16 oldest connections, the oldest claiming a Slack app first. It serves at most 16 connections, its own included: the own one, if there is one, counts first, the others are taken oldest first (then by namespace and name), and a connection past the limit is not served. With every namespace admitted the 16 places are shared by every ChatConnection of the cluster. No setting changes the limit (Limits). A broker serves the Bindings whose connectionRef names a connection it serves, and no others, so two releases can share a cluster when neither admits the other's connections. A Binding whose connectionRef names a connection that does not exist is reported by the leader of every broker that sees it, as ConnectionNotFound, since none owns it. A Binding that names a connection that exists and that this broker does not serve is told ConnectionNotServed by its leader in three cases: the broker served the connection before (its namespace is no longer admitted: it was taken off the list, it lost the label the selector matches, the selector changed, or a broker that admitted every namespace was narrowed to a list, a selector or its own connection alone; or it was the broker's own and AGENTKOURIER_CHAT_CONNECTION now names another or is unset, and its namespace is not admitted), the connection is past the limit, or it is a second connection of a Slack or Microsoft Teams app. Only a Binding that the connection admits is told, and a connection in a namespace that was never admitted tells nobody (Binding status). A broker that does serve the connection writes its own status over it.