Skip to content

Organize and Troubleshoot Triggers

Validate Configuration and Enforce Policies covers what to check and how to write a Trigger. This guide covers running Triggers across an Organization: where to keep them, how Spaces and Targets select them and pick up changes to them, how their results are named on a Unit, when they run again, and what to look at when they don't do what you expect.

Organizing Triggers across Spaces and Targets

Dedicated Trigger Space

Rather than scattering Triggers across application Spaces, create a dedicated Space to hold Triggers, along with related entities such as Filters, Invocations, Views, Attributes, Tags, and ChangeSets. This Space should not contain Units or Targets — it serves purely as an organizational home for operational tooling:

cub space create app-common --display-name "Shared Triggers and Filters"

Use Labels on Triggers to categorize them by purpose, making it easier to select subsets with Filters:

cub trigger create --space app-common valid-k8s Mutation Kubernetes/YAML \
  --label Purpose=validation \
  vet-schemas

cub trigger create --space app-common complete-k8s Mutation Kubernetes/YAML \
  --label Purpose=validation \
  vet-placeholders

cub trigger create --space app-common check-replicas Mutation Kubernetes/YAML \
  --label Purpose=policy --label Scope=production \
  vet-celexpr 'r.kind != "Deployment" || r.spec.replicas > 1'

cub trigger create --space app-common validate-kyverno Mutation Kubernetes/YAML \
  --channel my-space/admission-bot \
  --label Purpose=policy --label Engine=kyverno \
  vet-kyverno-server

Validation on Spaces, policies on Targets

In scenarios where application teams own Units in Spaces and a platform team owns the Kubernetes clusters (along with their Targets), a useful pattern is:

  • Attach validation Triggers to Spaces — functions like vet-schemas and vet-placeholders catch mistakes in configuration authoring. These apply regardless of where the configuration is deployed.
  • Attach policy Triggers to Targets — functions like vet-kyverno-server, vet-opa-gatekeeper, and environment-specific vet-celexpr constraints enforce what is allowed on a particular cluster. The platform team controls these independently of the application teams.

This separation lets application teams manage their own validation while the platform team enforces deployment policies centrally.

Using Filters to select Triggers

Since Triggers are ToolchainType-specific, and you may want different subsets of Triggers for different Spaces or Targets, use Filters with From=Trigger to select the right Triggers. Then attach the Filter to Spaces and Targets using --trigger-filter:

# Create Filters for different purposes
cub filter create --space app-common validation-triggers Trigger \
  --where-field "Labels.Purpose = 'validation'"

cub filter create --space app-common policy-triggers Trigger \
  --where-field "Labels.Purpose = 'policy'"

cub filter create --space app-common prod-policy-triggers Trigger \
  --where-field "Labels.Purpose = 'policy' AND Labels.Scope = 'production'"

Attach Filters to Spaces and Targets:

# Application Spaces get validation Triggers
cub space create my-app --trigger-filter app-common/validation-triggers

# Production Targets get policy Triggers
cub target create --space my-app prod-cluster \
  --trigger-filter app-common/prod-policy-triggers

To update an existing Space or Target to add a Filter and remove WhereTrigger filtering to prevent conflicting filters:

cub space update --patch --trigger-filter app-common/validation-triggers --where-trigger=- my-app
cub target update --patch --space my-app --trigger-filter app-common/policy-triggers --where-trigger=- prod-cluster

When Triggers are added or modified in the Trigger Space, refresh the consuming Spaces and Targets to pick up the changes:

cub space update --patch --refresh-triggers my-app
cub target update --patch --space my-app --refresh-triggers prod-cluster

How Triggers are applied to Spaces and Targets

Triggers are associated with Spaces and Targets through WhereTrigger and TriggerFilterID fields. These fields control which Triggers from across the organization are selected for a given Space or Target.

Default behavior

A Space with neither WhereTrigger nor TriggerFilterID invokes the Triggers in it. Setting either one replaces that with the Triggers it selects from across the organization. A Space may also have a WhereTrigger of SpaceID = '<its own ID>', which earlier versions of ConfigHub set automatically; it selects the same Triggers.

A Space created by cloning another, such as with cub variant create, selects the Triggers its upstream Space selects: it inherits the upstream's WhereTrigger and TriggerFilterID, or, when the upstream has neither, gets a WhereTrigger of SpaceID = '<upstream Space ID>'. Every variant of a Space therefore runs the same Triggers, without the Triggers being copied.

Cross-Space Trigger selection

Triggers can be selected by Spaces and Targets other than the Space they were created in:

cub space update --patch --where-trigger "Space.Slug = 'shared-policies' AND Event = 'Mutation'" my-app-space

Refreshing Trigger lists

When a Trigger is created, updated, or deleted within its own Space, the Space's Trigger list (TriggerIDs) and hash (TriggerHash) are automatically refreshed, and affected Units are enqueued for re-evaluation. When a Trigger is moved to another Space with cub trigger move, the Space it leaves and the one it arrives in are both refreshed. The move lists the other Spaces and Targets whose selection of the Trigger changes; they keep invoking it until they are refreshed.

However, explicit refresh is needed in two main scenarios:

  1. Cross-Space Trigger changes: When Triggers are modified in one Space but consumed by another Space or Target through WhereTrigger or TriggerFilterID, the consuming Space or Target does not automatically detect the change. The manager of the consuming Space or Target must explicitly refresh:
cub space update --patch --refresh-triggers my-app-space
cub target update --patch --space my-space --refresh-triggers my-target

This is by design: since Triggers can affect many Units across many Spaces, delaying re-evaluation gives managers of consuming Spaces an opportunity to verify which Triggers match and potentially update their filters before applying the changes.

  1. Permission verification: Refreshing checks that the caller has Edit permission on the Space or Target. This ensures that only authorized users can change which Triggers are actively applied.

Trigger hashing

ConfigHub computes a TriggerHash for each Space and Target based on the combined hashes of all selected Triggers. When the hash changes (due to Trigger creation, update, deletion, or refresh), all affected Units are enqueued for asynchronous trigger re-evaluation.

Validation Errors and Validation Warnings

Validation is about the configuration itself. Who has reviewed or approved a change is recorded separately, as Attestations, and required by a ChangeWorkflow rather than by a Trigger. See review and approval.

When a validating Trigger function fails, ConfigHub records a Validation Error on the Unit. Validation Errors block publishing a Release until the issue is resolved.

Gate naming

Validation Errors use a 3-part name format: <space-slug>/<trigger-slug>/<function-name>. For example:

my-space/check-replicas/vet-celexpr

This format identifies which Trigger and function produced the gate, and from which Space the Trigger originates. A Trigger that references an Invocation with several functions produces one gate per function, numbered by the function's position in the Invocation:

my-space/checks/vet-celexpr:1
my-space/checks/vet-celexpr:2

The name records the Trigger's slugs as they were when the gate was set. Renaming or moving a Trigger does not rename its gates; they get the new name the next time the Unit's Triggers run. ValidationTriggerIDs maps each gate name to the ID of the Trigger that produced it, and can be used in filters:

cub unit list --space my-space --where "ValidationTriggerIDs.my-space/check-replicas/vet-celexpr = '<trigger-id>'"

The awaiting/triggers gate

When configuration data changes, ConfigHub sets a temporary awaiting/triggers Validation Error on the Unit. It indicates that Triggers have been enqueued for asynchronous evaluation but have not yet completed, and is automatically removed when all Triggers finish executing.

Waiting for Triggers

Many CLI commands support --wait (enabled by default) to wait for the awaiting/triggers gate to clear:

cub unit update --space my-space --wait my-unit ...

When --wait is active, the CLI polls the Unit until awaiting/triggers is removed, then reports any remaining Validation Errors or Validation Warnings.

When Triggers are re-evaluated

Triggers run asynchronously in the background. They are re-evaluated when:

  • Unit data changes — any mutation to a Unit's configuration data (create, update, function invocations, link resolution, clone)
  • Links are added or removed — resolved data from linked Units may affect Trigger results
  • A Release is published with outstanding Validation Errors — the Unit is re-enqueued for Trigger re-evaluation so that the errors can be re-checked with the current Trigger configuration
  • Trigger configuration changes — creating, updating, or deleting a Trigger in the Space automatically re-evaluates all affected Units
  • Space or Target Trigger list is refreshed — after --refresh-triggers, all Units in the Space (or with the Target) are re-evaluated
  • A Unit a Trigger reads changes or is deleted — the Units the Trigger applies to in the Spaces that read the changed Unit are re-evaluated

When a Channel's bot is unavailable

A Trigger on a Channel fails closed. While no bot holds the Channel, or a run on it goes unanswered:

  • Other Triggers continue to execute — only Triggers on that Channel are affected
  • The Unit keeps its awaiting/triggers gate — ConfigHub retries with back-off until the Trigger has run, and the Unit cannot be released past the gate in the meantime
  • The Trigger is never disabled for being unavailable, and a Channel that a Trigger names cannot be deleted

When the bot is back, the waiting Units are evaluated without any action on your part.

Invoking Triggers imperatively

Triggers can be invoked on demand with the --trigger flag, using the verb that matches the kind of function the Trigger runs — cub function vet for a validating Trigger, cub function set for one that mutates:

cub function vet --space my-space --where "Slug = 'my-unit'" --trigger my-space/check-replicas

The verb is checked against the Trigger's function, so invoking a mutating Trigger with vet is an error rather than an unintended write. Use cub function do only to invoke several Triggers of differing kinds in one request.

Updating validation results imperatively

Add --update-validation-results to selectively update a Unit's Validation Errors and Warnings from the Trigger results:

cub function vet --space my-space --where "Slug = 'my-unit'" \
  --trigger my-space/check-replicas \
  --update-validation-results

This is useful when you want to re-evaluate Triggers and update the results without waiting for the next automatic re-evaluation. Unlike automatic trigger evaluation, imperative --update-validation-results only modifies the entries for the invoked Triggers — it does not clear those from other Triggers.

(--update-apply-gates is the former name of this flag. It still works, and warns that it is deprecated.)

Permissions

  • Creating a Trigger requires CreateChildren permission on the Space it is created in, and updating or deleting one requires Edit permission on the Trigger, which EditChildren on its Space grants. No permission on the Spaces and Targets that select the Trigger is required: the Space the Trigger is in is refreshed with the change, and any other Space or Target that selects it takes the change when it is refreshed.
  • Refreshing Triggers on a Space or Target requires Edit permission on that Space or Target.
  • Invoking Triggers with --update-validation-results requires Edit permission on the affected Units.

Troubleshooting

Units have unexpected Validation Errors

Use cub trigger list to see which Triggers are active in a Space:

cub trigger list --space my-space

Check the validation results on a specific Unit:

cub unit get --space my-space -o jq=".Unit.ValidationResults" my-unit

Triggers are not running

  • Check that the Trigger is not disabled: cub trigger get --space my-space my-trigger
  • Check whether any Triggers are selected: cub space get my-space -o "jq=.Space | {Space: .Slug, TriggerIDs: .TriggerIDs}"
  • Check that the Space's WhereTrigger or TriggerFilterID selects the Trigger: cub space get -o jq=".Space.TriggerIDs" my-space
  • If both WhereTrigger and TriggerFilterID are set, they are ANDed, and may conflict. Remove WhereTrigger with cub space update my-space --patch --where-trigger=-. Remove TriggerFilterID with cub space update my-space --patch --trigger-filter=-.
  • If using cross-Space Triggers, ensure the consuming Space has been refreshed: cub space update --patch --refresh-triggers my-space
  • Perform similar steps for Target Triggers if the expected Triggers are attached to the Target.

Re-evaluating Units

To re-evaluate existing Units against a Trigger now, invoke it with --update-validation-results:

cub function vet --space my-space --trigger my-space/policy-check --update-validation-results

Or refresh the Space's Triggers to enqueue all Units:

cub space update --patch --refresh-triggers my-space