cub trigger create
cub trigger create
Create a new trigger or bulk create triggers
Synopsis
Create a new trigger or bulk create multiple triggers by cloning existing ones.
SINGLE TRIGGER CREATION:
Create a new trigger: a function that runs automatically on units when an event happens.
A trigger runs on the units of every space that selects it, and on the units whose Target selects it. A space with neither WhereTrigger nor TriggerFilterID selects the triggers in it; one with either selects the triggers those match (cub space update --where-trigger or --trigger-filter), and a Target selects triggers the same way (cub target update). Within a selecting space, narrow which units a trigger runs on with --unit-filter or --where-unit-field. Instead of a single function, a trigger can run a stored invocation (--invocation).
A trigger's function runs on the space's builtin executor, or on the client of a channel that serves it (--channel). A trigger on a channel fails closed: while no client holds the channel's lease, or the client does not answer, the unit keeps its awaiting/triggers gate and is retried with back-off until the trigger has run.
A validating trigger whose function fails records a ValidationError on the unit, which blocks publishing a Release of it, promoting past a stage that requires Validated, and closing a ChangeSet whose workflow requires it, until the configuration or the trigger is fixed. With --warn, a failure records a ValidationWarning instead, which blocks nothing. A validating trigger created without --warn is enforced from its creation, which is recorded in its EnforcedAt annotation.
Events:
- Mutation: Triggered when a resource is being modified
- PostClone: Triggered after a resource is cloned
- Release: Triggered when a space publishes a Release. Its validating functions run once, over the documents of every unit the Release bundles that the trigger selects, so a check can see several resources at once. A failure refuses the Release unless the trigger is --warn, and what it found is recorded on the Release ("cub release get"), not on the units. It runs on the Releases of the spaces and targets that select it, and takes no other-unit data.
Toolchain Types:
- Kubernetes/YAML: For Kubernetes YAML configurations
- ConfigHub/YAML: For ConfigHub YAML configurations
- AppConfig/Properties: For application Java Properties configurations
- AppConfig/YAML: For application YAML configurations
- AppConfig/TOML: For application TOML configurations
- AppConfig/INI: For application INI configurations
- AppConfig/Env: For application Env configurations
- AppConfig/JSON: For application JSON configurations
- AppConfig/Text: For application plain-text configurations
Example Functions:
- vet-cel: Validate resources using CEL expressions
- vet-placeholders: Ensure no placeholders exist
- vet-schemas: Validate resources against their OpenAPI schemas
- vet-no-merge-conflicts: Fail while a merge has changes still withheld on the unit
- set-default-names: Set default names for cloned resources
- set-annotation: Set annotations on resources
Function arguments can be provided as positional arguments or as named arguments using --argumentname=value syntax. Once a named argument is used, all subsequent arguments must be named. Use "--" to separate command flags from function arguments when using named function arguments.
BULK TRIGGER CREATION:
When no positional arguments are provided, bulk create mode is activated. This mode clones existing triggers based on filters and creates multiple new triggers with optional modifications.
Single Trigger Examples:
# Create a trigger to validate replicas > 1 for Deployments
cub trigger create --space my-space -o json replicated Mutation Kubernetes/YAML vet-cel 'r.kind != "Deployment" || r.spec.replicas > 1'
# Create a trigger to enforce low resource usage (replicas < 10)
cub trigger create --space my-space -o json lowcost Mutation Kubernetes/YAML vet-cel 'r.kind != "Deployment" || r.spec.replicas < 10'
# Create a trigger to ensure no placeholders exist in resources
cub trigger create --space my-space -o json complete Mutation Kubernetes/YAML vet-placeholders
# Create a trigger to label every resource with its owning team
cub trigger create --space my-space -o json label-team Mutation Kubernetes/YAML set-label team payments
# Refuse a Release in which a multi-replica Deployment has no PodDisruptionBudget
cub trigger create --space my-space pdb-covered Release Kubernetes/YAML vet-starlark "$(cat pdb.star)"
# Create a trigger to set default names for cloned resources
cub trigger create --space my-space -o json rename PostClone Kubernetes/YAML set-default-names
# Create a trigger to add a "cloned=true" annotation after cloning
cub trigger create --space my-space -o json stamp PostClone Kubernetes/YAML set-annotation cloned true
# Using named arguments for clarity (note the "--" separator)
cub trigger create --space my-space -o json stamp PostClone Kubernetes/YAML -- set-annotation --annotation-key=cloned --annotation-value=true
Bulk Create Examples:
# Clone all triggers matching a pattern with name prefixes
cub trigger create --where "Slug LIKE 'app-%'" --name-prefix dev-,staging- --dest-space dev-space
# Clone specific triggers to multiple spaces
cub trigger create --trigger my-trigger --dest-space dev-space,staging-space
# Clone triggers using a where expression for destination spaces
cub trigger create --where "Slug LIKE 'app-%'" --where-space "Labels.Environment IN ('dev', 'staging')"
# Clone triggers with modifications via JSON patch
echo '{"Disabled": false}' | cub trigger create --where "Event = 'Mutation'" --name-prefix active- --from-stdin
# Clone triggers matching specific criteria
cub trigger create --where "ToolchainType = 'Kubernetes/YAML' AND FunctionName = 'vet-cel'" --name-prefix v2-
cub trigger create [<slug> <event> <config type> <function> [<arg1> ...]] [flags]
Options
--allow-exists Allow creation of resources that already exist
--annotation strings annotations in key=value format; can separate by commas and/or use multiple instances of the flag
--channel string channel whose client executes the trigger function; a trigger that runs an invocation runs it where the invocation says
--clearance stringArray class of guarded reason this trigger's function is cleared for, as KEY, KEY=VALUE[;VALUE...], KEY!=VALUE[;VALUE...], or !KEY to refuse any path carrying KEY (repeatable). Part of the trigger's Hash: changing it changes what a re-run lands
--delete-gate strings delete gates in key[=true] format; can separate by commas and/or use multiple instances of the flag
--description string description explaining the trigger's purpose and how to fix failures
--dest-space strings destination spaces for bulk create (can be repeated or comma-separated)
--disable Disable trigger
--display-name string friendly name for the entity, which need not be unique or URL-safe; an entity without one is shown by its slug
--dry-run report what the command would write, and write nothing
--enforced-by string when a validating trigger is due to be enforced (made blocking with --unwarn), recorded in its EnforcedBy annotation: RFC 3339, or a date such as 2026-12-31; - removes it
--filename string Read the ConfigHub entity's fields, as YAML or JSON, from file, URL (https://), or stdin (-), as --from-stdin does; mutually exclusive with --from-stdin
--filter string Filter entity to apply to the list. Specify as 'space/filter' for cross-space filters or just 'filter' for current space. Supports both slugs and UUIDs. The filter will be combined with any --where clause using AND logic. Examples: "production-filters/security-check", "my-filter-uuid", "validation-rules"
--filter-space string filter entity containing WHERE expression to select destination spaces for bulk create (slug or UUID)
--filter-unit string filter, by slug or UUID, over Units selecting those to create from, with --from-backing-units
--from-backing-units create a Trigger from each ConfigHub/YAML Unit --where-unit, --filter-unit and --space select that describes one, in the Unit's space, with the Unit as its backing Unit
--from-stdin Read the ConfigHub entity's fields, as YAML or JSON, from stdin; merged with command arguments on create, and merged with command arguments and existing entity on update. A field the entity does not have, or one only the server sets, is refused; cub <entity> explain lists the fields
--guard stringArray reason to record on the paths this trigger's function writes, as KEY=VALUE (repeatable). A later operation must be cleared for it before overwriting those paths, the trigger's next run included, so --clearance has to cover it. Part of the trigger's Hash: changing it changes what a re-run leaves behind
-h, --help help for create
--hidden-reason string hide the entity, giving the reason as a name such as Retired: lists and bulk operations leave it out unless --include-hidden names the reason (use '-' to clear, which shows the entity again). Archived is not one a client sets: delete --archive archives an entity
--include-hidden string[="*"] Also select hidden entities, to list or to act on: those hidden for the given HiddenReasons, comma-separated, as in --include-hidden=BackingUnit, or for any reason but Archived when given no value or "*". ConfigHub/YAML Units, which hold the configuration of other entities, are hidden with the reason BackingUnit. Archived entities are selected only when the reasons name Archived, as in --include-hidden=Archived or --include-hidden='*,Archived'. A --where naming entities by Slug or ID lists them whether hidden or not, but a bulk operation acts on archived ones only when --include-hidden names Archived
--invocation string invocation to execute (alternative to specifying function and arguments)
--label strings labels in key=value format; can separate by commas and/or use multiple instances of the flag
--name-pattern string a pattern string for name generation of clones, prefix 'template:' to use a Go template with .SourceEntitySlug to access the original Trigger and .Labels to access variant labels, example: 'template:{{.SourceEntitySlug}}-{{.Labels.env}}'
--name-prefix strings name prefixes for bulk create (can be repeated or comma-separated)
--other-unit stringArray another unit to pass the trigger's functions, as key=unit, where the functions read it under key (e.g. policy=my-policy for vet-validating-admission-policy) and unit is a slug, space/slug or UUID; can be repeated
--other-unit-selection-filter stringArray a filter (From=Unit) the units selected under a key must also match, as key=filter, where filter is a slug, space/slug or UUID; - clears it; can be repeated
--other-unit-selection-where stringArray select other units to pass the trigger's function under a key, as key=where, for each space and target that selects the trigger: a unit where expression, which may name that space as EvaluatingSpace or that target as EvaluatingTarget, e.g. "policies=Space.ReleaseTargetID = EvaluatingSpace.ReleaseTargetID" for spaces, "policies=Space.ReleaseTargetID = EvaluatingTarget.TargetID" for targets; - clears it; can be repeated
--other-unit-selection-where-resource stringArray select the units holding a resource a WhereResource expression matches under a key, and pass the function only the resources it matches, as key=expression, e.g. "policies=ConfigHub.ResourceType = 'networking.k8s.io/v1/NetworkPolicy'"; - clears it; can be repeated
-o, --output string Output format. One of: json, yaml, name, wide, mutations, jq=<expr>, yq=<expr>, custom-columns=<spec>
--patch-existing with --from-backing-units, patch a Trigger a selected Unit already backs with what the Unit holds that it has not taken yet, rather than report that the Unit backs it
--permission strings permission in format Action:UserIDOrUsername, Action:group:GroupSlugOrID for a group you belong to, or Action:serviceaccount:ServiceAccountSlugOrID (e.g., Manage:user@example.com, View:group:platform, View:serviceaccount:deploy-bot, can be repeated)
--priority string priority of the policy a validating trigger checks, recorded in its Priority annotation: High, Medium or Low; - (or Unspecified) removes it
--quiet No default output.
--set stringArray set a field of the Trigger by its path, as <path>=<value> (repeatable). A path is field names separated by dots; a list element is addressed as ?<key>=<value> or by position, as in Stages.?Name=prod.WhereSpace, and is added if it is not there. A list of plain values separates them with ';'; an object or a list of objects is given as YAML or JSON. A reference is given as it is elsewhere, by slug, <space>/<slug> or ID. With --patch, only a path with no list element in it
--trigger strings target specific triggers by slug or UUID for bulk create (can be repeated or comma-separated)
--unit-filter string filter entity (slug or UUID) to restrict which Units this trigger applies to
--unset stringArray clear a field of the Trigger by its path, or remove the list element the path ends at (repeatable)
--variant-labels strings labels for bulk create in the format of key1=value1|value2,key2=value1|value2|value3
--verbose Detailed output, additive with default output
--warn Set trigger to produce ValidationWarnings instead of ValidationErrors
--where string Filter expression using SQL-inspired syntax. Supports conjunctions with AND. String operators: =, !=, <, >, <=, >=, LIKE, NOT LIKE, ILIKE, ~~, !~~, ~, ~*, !~, !~*. Pattern matching with LIKE/ILIKE uses % and _ wildcards. Regex operators (~, ~*, !~, !~*) support POSIX regular expressions. A related entity is referenced by prefix, as in "UpstreamUnit.Slug = 'base'"; when the reference names a list, a * segment matches any element, as in "FromLink.*.Slug = 'upgrade-app'". Examples: "Slug LIKE 'app-%'", "DisplayName ILIKE '%backend%'", "Slug ~ '^[a-z]+-[0-9]+$'". 'cub <entity> explain --where' lists the attributes an entity's expressions can name
--where-resource string metadata path expression to restrict which resources the trigger operates on
--where-space string where expression to select destination spaces for bulk create
--where-unit string where expression over Units selecting those to create from, with --from-backing-units
--where-unit-field string filter expression to restrict which Units this trigger applies to (its WhereUnit). It takes what --where does on unit list, attributes of what a unit refers to included, as in "Space.Labels.Environment = 'prod'"
--with-backing-units give each Trigger the bulk operation writes a backing Unit if it has none: a ConfigHub/YAML Unit holding its configuration, kept in step with it
Options inherited from parent commands
--component string the Component of --variant, when that names the variant alone; --variant <component>/<variant> says the same in one flag
--context string The context to use for this command
--debug Debug output
--space string space to operate in, by slug or UUID. Omitted, a list or bulk operation spans the organization and a single entity is named as <space>/<slug>; "*" means the same as omitting it
--variant string variant to operate in, as <component>/<variant>, or as <variant> with --component: the space naming that Component whose Variant label is <variant>. The same scope as --space, named by what it is rather than by the space's slug; the two cannot be combined
SEE ALSO
- cub trigger - Trigger commands