Skip to content

cub link create

Create a new link or bulk create (copy) links

Synopsis

Create a new link between two units or bulk create links by copying existing links.

SINGLE LINK CREATION:

Create a single link between two units. Links define relationships between units and can be used to establish dependencies or connections between resources.

A link can be created:

  1. Between units in the same space
  2. Between units across different spaces (by naming the to unit as /, or by specifying the to space)

BULK LINK CREATION (COPY):

When no positional arguments are provided with --where or --filter plus one of --reverse, --from-downstream-where, or --dest-space, --where-space or --filter-space, bulk create mode is activated. This mode copies existing links and retargets their From and/or To units: through downstream UpgradeUnit links, by reversing them, or to the units of the same slugs in other spaces.

--dest-space, --where-space and --filter-space copy each link to every space they select, from the unit there with the slug of the link's from unit. A link between two units of its space connects the units of those slugs there; a link to a unit in another space still leads to that unit. A copy fails when its space has no unit of a slug it needs, and UpgradeUnit links are not copied, since a variant's upstream is set by cloning or upgrading it. A copy of a link that was itself copied from an upstream link records that upstream, as the link's other copies do.

A copy has its source link's slug, as a link copied by unit clone or variant promote does, unless its space has a link of that slug already; then it is named for the units it connects. A reversed copy is always named for its units, since the source's slug names the other direction.

A copy starts with no merge history and no delete gates of its own: the source link's merged-revision pointers name revisions of the units it connects, which a retargeted copy does not share. An UpgradeUnit copy is set to its new units' current revisions instead. --make-current is rejected here because its values are per-link; pass --upstream-last-merged-revision / --downstream-last-merged-revision if the copies need specific pointers, or run cub link update --make-current on them afterward.

Single Link Examples:

  # Create a link between a deployment and its namespace in the same space
  cub link create --space my-space -o json to-ns my-deployment my-ns --wait

  # Create a link for a complex application to its namespace
  cub link create --space my-space -o json headlamp-to-ns headlamp my-ns --wait

  # Create a link between a cloned unit and a namespace
  cub link create --space my-space -o json clone-to-ns my-clone my-ns --wait

  # Create a link to a namespace in another space, spelled either way. The link is created in
  # --space, where the from unit is
  cub link create --space my-space dep-to-ns my-deployment platform/my-ns
  cub link create --space my-space dep-to-ns my-deployment my-ns platform

  # Roll a workload when its ConfigMap changes: hash the ConfigMap's data, and write the hash
  # to an annotation of the pod template. A place in a unit is <resource-type>:<resource-name>:<path>
  cub link create --space my-space config-hash my-deployment my-configmap \
    --update-type TransformPaths --auto-update \
    --upstream-getter 'configHash=get-hash data' \
    --downstream-path 'apps/v1/Deployment:default/web:spec.template.metadata.annotations.confighub~1com/Hash={{.Params.configHash}}'

  # Copy a value from the upstream unit, as an integer computed with CEL
  cub link create --space my-space replicas my-canary my-deployment --update-type TransformPaths \
    --upstream-path 'replicas=apps/v1/Deployment:default/web:spec.replicas' \
    --downstream-path 'apps/v1/Deployment:default/web-canary:spec.replicas=int:cel:params.replicas / 10'

  # Set an image tag from a value in the upstream unit by running a function on the downstream
  # unit. An argument that uses an upstream value is prefixed template: or cel:; here the prefix
  # is followed by an image reference, which begins with its own ':'
  cub link create --space my-space app-image my-deployment registry/my-image --update-type TransformPaths \
    --upstream-path 'tag=registrybot.confighub.com/v1alpha3:my-image:streams.stable.tag' \
    --downstream-setter 'set-image-reference-by-uri ghcr.io/example/app template::{{.Params.tag}}'

  # State the binding of a NeedsProvides link: where the downstream unit needs a value, then
  # where the upstream unit provides it
  cub link create --space my-space subnet-to-rt subnet route-table --auto-update \
    --manual-binding 'example.com/v1/Subnet:/public-2:spec.routeTableRef.name=example.com/v1/RouteTable:/public-rt:metadata.name'

BULK LINK CREATION FROM REFERENCES:

With --from-refs, links are not copied but inferred, as upload infers them, from the configuration of the Kubernetes/YAML units --where-unit, --filter-unit and --space select: from the references a resource makes to another (a ConfigMap a Deployment mounts, the ServiceAccount a RoleBinding names), the Namespace a resource is in, the CRD that defines a resource's type, and the label selectors that select a workload's pods. Links are inferred among the units of one space, and among those of spaces released to the same target. A resource that names no namespace, or names the placeholder, is taken to be in its space's Namespace label; in a space without one, it is taken to share a namespace only with the other resources of its space.

Each link is a NeedsProvides link with --auto-update, created in its from unit's space. The other flags set its labels, annotations, delete gates and auto-update, but not its update type. No link is created between two units that have a NeedsProvides link between them already, in either direction, so running it again creates only the links that are missing.

Bulk Create From References Examples:

  # Link the units of a space to one another
  cub link create --space my-app --from-refs

  # Link the units of every space released to the target prod-east, labeled for later selection
  cub link create --from-refs --where-unit "Target.Slug = 'prod-east'" --label linked-by=refs

Bulk Create (Copy) Examples:

  # Copy outgoing links from prod-v1 units to their downstream copies in prod-v2
  cub link create --where "Space.Slug = 'prod-v1' AND ToSpaceID != SpaceID AND UpdateType != 'UpgradeUnit'" \
    --from-downstream-where "UpdateType = 'UpgradeUnit' AND Space.Slug = 'prod-v2'"

  # Also retarget the To units to their downstream copies
  cub link create --where "Space.Slug = 'prod-v1' AND ToSpaceID != SpaceID" \
    --from-downstream-where "UpdateType = 'UpgradeUnit' AND Space.Slug = 'prod-v2'" \
    --to-downstream-where "UpdateType = 'UpgradeUnit' AND Space.Slug = 'prod-v2'"

  # Reverse cross-space UpgradeUnit links (create the link in the To unit's space)
  cub link create --where "Space.Slug = 'prod-v2' AND UpdateType = 'UpgradeUnit'" --reverse

  # Copy prod-east's links, other than its UpgradeUnit links, to the units of the same slugs in prod-west
  cub link create --where "Space.Slug = 'prod-east' AND UpdateType != 'UpgradeUnit'" --dest-space prod-west
cub link create [<link slug> <from unit slug> <to unit slug> [<to space slug>]] [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
      --auto-update                           enable automatic downstream unit updates when upstream changes; a link created with no --update-type gets this without asking
      --clearance stringArray                 class of guarded reason this link's resolve is cleared for, as KEY, KEY=VALUE[;VALUE...], KEY!=VALUE[;VALUE...], or !KEY to refuse any path carrying KEY (repeatable). Pass an empty value to clear
      --delete-gate strings                   delete gates in key[=true] format; can separate by commas and/or use multiple instances of the flag
      --dest-space strings                    spaces to copy links to, between the units of the same slugs there (can be repeated or comma-separated)
      --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
      --downstream-last-merged-revision int   set DownstreamLastMergedRevisionNum explicitly: the downstream revision the last merge produced
      --downstream-path stringArray           value a TransformPaths link writes to the downstream unit, as [<key>=]<resource-type>:<resource-name>:<path>=[<data-type>:][<evaluator>:]<expression> (repeatable). The evaluator is template, the default, or cel; the data type is string, the default, int or bool. The upstream values the expression refers to are recorded as its parameters. The key identifies the entry when two versions of the link are merged
      --downstream-setter stringArray         function a TransformPaths link runs on the downstream unit, as [<key>=]<function> [<argument>...] (repeatable), the function written as on the cub function do command line. An argument prefixed template: or cel: is evaluated before the function runs, and may refer to the upstream values, as in template:{{.Params.tag}}; those it refers to are recorded as the setter's parameters
      --dry-run                               report what the command would write, and write nothing
      --fail-on-timeout                       exit with status 4 rather than 0 when the wait for Triggers runs out before they finish, or cannot read a unit to tell. The changes are saved either way, so do not make them again
      --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 spaces to copy links to (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 Link 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-downstream-where string          where expression to find downstream UpgradeUnit links from each source link's FromUnit; creates one copy per match
      --from-refs                             create the NeedsProvides links between the Kubernetes/YAML units --where-unit, --filter-unit and --space select that their resources' references, namespaces, CRDs and label selectors call for, as upload infers them
      --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 link's resolve writes, as KEY=VALUE (repeatable). A later operation must be cleared for it before overwriting those paths, the link's next resolve included, so --clearance has to cover it; refused on UpgradeUnit and MergeUnits links, whose inherited guards propagate from upstream. Pass an empty value to clear
  -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
      --label strings                         labels in key=value format; can separate by commas and/or use multiple instances of the flag
      --link strings                          target specific links by slug or UUID for bulk create (can be repeated or comma-separated)
      --make-current                          set link revision numbers to current unit revisions; on create this skips the initial merge, on update it re-points the link at what the units now hold
      --manual-binding stringArray            binding stated for the link, as [<key>[:<attribute-name>]=]<needed <resource-type>:<resource-name>:<path>>[=[<data-type>:]<provided <resource-type>:<resource-name>:<path>>] (repeatable): the place in the downstream unit that needs a value, then the place in the upstream unit that provides it. The data type is string by default. An Insert link's one binding gives only the needed place, optionally followed by =<data-type>
      --merge-enable-subtraction              also subtract the downstream unit's local differences from the patch when resolving this link, on top of the Override guards that hold its local overrides
      --no-auto-update                        disable automatic downstream unit updates; a link that does not update itself instead reports Stale when its upstream moves past it
      --no-merge-enable-subtraction           return this link to the default: no subtraction step
      --no-squash                             return this link to the default: its resolve walks the range
  -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 Link 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)
      --quiet                                 No default output.
      --reverse                               swap FromUnit and ToUnit directions of copied links (for cross-space link reversal)
      --set stringArray                       set a field of the Link 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
      --squash                                merge this link's range as one rebased diff in one revision instead of walking it: by default a resolve re-runs the upstream's recorded function invocations against the downstream unit where it can, and records one revision per upstream revision that has an effect; only meaningful for UpgradeUnit and MergeUnits links
      --timeout duration                      how long to wait for the Triggers of the units the command writes, as a duration such as 30s or 2m. The changes are saved whether or not the Triggers finish in time; when they do not, the command names the units and exits 0, unless --fail-on-timeout (default 2m0s)
      --to-downstream-where string            where expression to find downstream UpgradeUnit link from each source link's ToUnit; exactly one match required; only with --from-downstream-where
      --transform-invocation string           Invocation slug (or space/slug, or UUID) whose function transforms upstream data before it is inserted or upserted; only valid with --update-type Insert or Upsert
      --unset stringArray                     clear a field of the Link by its path, or remove the list element the path ends at (repeatable)
      --update-type string                    link update type (NeedsProvides, MergeUnits, UpgradeUnit, None, Insert, Upsert, or TransformPaths); the default is a NeedsProvides link that updates itself
      --upstream-getter stringArray           function a TransformPaths link runs on the upstream unit for a value, as <name>=<function> [<argument>...] (repeatable), the function written as on the cub function do command line. An argument prefixed template: or cel: is evaluated before the function runs; the getter runs before there are upstream values, so it cannot refer to them
      --upstream-last-merged-revision int     set UpstreamLastMergedRevisionNum explicitly: the upstream revision the link is treated as merged through
      --upstream-path stringArray             value a TransformPaths link reads from the upstream unit, as <name>=<resource-type>:<resource-name>:<path> (repeatable). The name is what an expression or a setter refers to it by, as .Params.<name> in a template and params.<name> in CEL
      --verbose                               Detailed output, additive with default output
      --wait                                  wait for the Triggers of the units the command writes to finish (default true)
      --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-mutation string                 where expression selecting mutations of the downstream unit whose paths this link's merges must not overwrite; on top of the unit's guards, so it holds more and never re-opens a guarded path
      --where-resource string                 where expression to select upstream resources for propagation
      --where-space string                    where expression selecting spaces to copy links to, between the units of the same slugs there
      --where-unit string                     where expression over Units selecting those to create from, with --from-backing-units
      --with-backing-units                    give each Link 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