Skip to content

cub unit update

cub unit update

Update a unit

Synopsis

Update an existing unit in a space. Units can be updated with new configuration data, restored to previous revisions, or upgraded from upstream units.

Like other ConfigHub entities, Units have metadata, which can be partly set on the command line and otherwise read from stdin using the flag --from-stdin or --replace-from-stdin.

Unit configuration data can be provided in multiple ways:

  1. From a local or remote configuration file, or from stdin (by specifying "-")
  2. By restoring to a previous revision (using --restore)
  3. By upgrading from the upstream unit (using --upgrade)
  4. By performing a 3-way merge with another unit (using --merge-source, --merge-base, --merge-end)
  5. By emptying it (using --empty). The next release of its space bundles it empty, which removes what earlier releases deployed of it, and takes off the Released delete gate those releases put on it, after which it can be deleted or archived. A destroy gate on the unit refuses that release, not the emptying

Examples:

  # Update a unit from a local YAML file
  cub unit update --space my-space myunit config.yaml

  # Update a unit from a file:// URL
  cub unit update --space my-space myunit file:///path/to/config.yaml

  # Update a unit from a remote HTTPS URL
  cub unit update --space my-space myunit https://example.com/config.yaml

  # Update a unit with config from stdin
  cub unit update --space my-space myunit -

  # Combine Unit JSON metadata from stdin with config data from file
  cub unit update --space my-space myunit config.yaml --from-stdin

  # Restore a unit to revision 5
  cub unit update --space my-space myunit --restore 5

  # Restore a unit to 2 revisions ago (relative to head). A promotion or upload that walked a
  # range of upstream changes wrote one revision per change, so to undo one of those, restore
  # Before:ChangeOrder:<slug> or Before:ChangeSet:<slug> instead of counting back
  cub unit update --space my-space myunit --restore -2

  # Restore a unit using a specific revision ID
  cub unit update --space my-space myunit --restore 550e8400-e29b-41d4-a716-446655440000

  # Restore a unit to the revision last published in a Release. For a backing unit, that is
  # the revision its entity holds
  cub unit update --space my-space myunit --restore LastReleasedRevisionNum

  # Restore a unit to a tagged revision (supports space/tag syntax)
  cub unit update --space my-space myunit --restore Tag:release-v1.0
  cub unit update --space my-space myunit --restore Tag:production/hotfix-patch

  # Restore a unit to the end of a changeset (supports space/changeset syntax)
  cub unit update --space my-space myunit --restore ChangeSet:feature-rollout
  cub unit update --space my-space myunit --restore ChangeSet:dev-space/bug-fixes

  # Upgrade a unit to match its upstream unit
  cub unit update --space my-space myunit --upgrade

  # Upgrade only as far as a point in the upstream's history, leaving later changes behind
  cub unit update --space my-space myunit --upgrade --merge-end ChangeSet:upstream-space/release-42
  cub unit update --space my-space myunit --upgrade --merge-end Tag:v1.0

  # Promote a change order: it supplies the range, and units outside it are passed over
  cub unit update --patch --space my-space --where "UpstreamRevisionNum > 0" \
      --upgrade --change-order base-space/release-42 --change-desc "Take release-42"

  # Undo that promotion, however many revisions it made, recording it against the change order
  # ("cub variant demote" is this over a whole space, and selects the units for you)
  cub unit update --patch --space my-space --where "UpstreamRevisionNum > 0" \
      --restore Before:ChangeOrder:base-space/release-42 --change-order base-space/release-42 \
      --change-desc "Roll release-42 back"

  # Update with a change description
  cub unit update --space my-space myunit config.yaml --change-desc "Updated database configuration"

  # Perform a 3-way merge with another unit
  cub unit update --space my-space myunit --merge-source other-unit --merge-base LastReleasedRevisionNum --merge-end HeadRevisionNum

  # Merge with specific revisions
  cub unit update --space my-space myunit --merge-source upstream-unit --merge-base Tag:v1.0 --merge-end 42

  # Merge with the unit itself (self-merge). The range reversed, with --squash, takes a change
  # back and keeps what came after it, which "cub unit revert" and "cub variant revert" do for you
  cub unit update --space my-space myunit --merge-source Self --merge-base LastReleasedRevisionNum --merge-end HeadRevisionNum

Patch Mode Examples:
  # Individual patch with labels
  cub unit update --patch --space my-space myunit --label version=1.2

  # Patch with data from file plus metadata changes
  cub unit update --patch --space my-space myunit --filename patch.json --change-desc "Updated annotations" --label patched=true

  # Bulk patch with change description and labels
  cub unit update --space my-space --patch --where "Slug LIKE 'app-%'" --change-desc "Metadata review" --label reviewed=2024-01

  # Bulk patch across all spaces with metadata
  cub unit update --patch --where "UpstreamUnitID IS NOT NULL" --change-desc "Upgrade all" --upgrade

  # Bulk restore with change description
  cub unit update --space my-space --patch --where "Slug IN ('unit1', 'unit2')" --restore LastReleasedRevisionNum --change-desc "Restored to last released revision"

  # Empty a unit, so that the next release removes what it deployed
  cub unit update --space my-space myunit --empty --change-desc "The cache moved to the platform cluster"

  # Empty every unit in a space, to take the whole deployment down at its next release
  cub unit update --space my-space --patch --where "Slug != ''" --empty

  # Leave units out of their space's releases
  cub unit update --space my-space --patch --where "Labels.Tier = 'scratch'" --unreleasable

  # Bulk patch with data from stdin plus metadata (just an example; use --unreleasable for this case)
  echo '{"Unreleasable": false}' | cub unit update --patch --unit unit1,unit2,unit3 --from-stdin --change-desc "Released again"
cub unit update <slug or id> [config-file] [flags]

Options

      --annotation strings             annotations in key=value format; can separate by commas and/or use multiple instances of the flag
      --change-desc string             change description
      --change-order string            change order to promote, with --upgrade or --resolve: it supplies both ends of the range, so --merge-end is not accepted alongside it; units its source doesn't cover are passed over, a unit that has merged past where it starts takes what of the change its link has not merged, and one short of it is handled as --prior-revisions says. With --restore Before:ChangeOrder:<slug> it is the change order being undone instead: it must have an AbortedReason, the restore must name the same change order, the revisions restored are marked with the change order's restore tag, a unit already carrying that tag is passed over, and the merge pointers of the links that follow each restored unit are advanced onto the restored revision. "cub variant demote" is that over a whole space
      --changeset string               changeset to associate the unit with (use '-' to remove in patch mode)
      --clearance stringArray          class of guarded reason this change is cleared for, as KEY, KEY=VALUE[;VALUE...], KEY!=VALUE[;VALUE...], or !KEY to refuse any path carrying KEY (repeatable). A guarded path this does not cover is not written, and the withheld change is reported as a conflict. Without it, an update that does not merge -- an edit, a restore, or a --resolve that reaches no UpgradeUnit or MergeUnits link of the units updated -- is cleared for Override guards, whatever their value; --upgrade, --merge-source, --merge-external-source, and a --resolve that reaches such a link are cleared for nothing. A clearance given replaces that, and --clearance '' clears nothing
      --delete-gate strings            delete gates in key[=true] format; can separate by commas and/or use multiple instances of the flag
      --destroy-gate strings           destroy gate for the unit, which refuses a release that would remove what the latest release deployed of it, and the withdrawal of the latest release when that would (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
      --dry-run                        report what the command would write, and write nothing
      --empty                          replace the unit's configuration with nothing; the next release of its space removes what earlier releases deployed of it, unless a destroy gate on the unit refuses that release
      --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-mutation string         filter selecting this unit's mutations whose paths the merge must not overwrite, on top of the unit's guards (only used with --merge-source)
      --force-close                    with --changeset -, close a changeset its ChangeWorkflow governs although the gates of the workflow's Final do not hold; requires --force-reason, and is recorded on the changeset
      --force-reason string            why the changeset's gates are overridden; required with --force-close
      --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 change writes, as KEY=VALUE (repeatable). A later operation must be cleared for it before overwriting those paths, this one included, so --clearance has to cover it. Adds and overwrites only; retiring a guard is cub unit set-guard --remove-guard
  -h, --help                           help for update
      --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
      --if-match string                write the config data given only if the unit's configuration is still the one with this DataHash (as cub unit get shows it), so that a change made since it was read is not overwritten; refused, writing nothing, when it is not
      --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
      --inherited-guard stringArray    inherited guard to record on the paths this change writes, as KEY=VALUE (repeatable): unlike --guard, a clone of the unit receives it and a merge carries it to the units downstream. --clearance has to cover it, as it covers --guard, and a key may not be given to both
      --label strings                  labels in key=value format; can separate by commas and/or use multiple instances of the flag
      --merge-base string              base revision for 3-way merge (uses same format as --restore); with --merge-external-source, overrides the default selection of the latest MergeExternal revision
      --merge-enable-subtraction       also subtract the target's local differences from the patch during --upgrade and --merge-source, on top of the stored path protection that preserves overrides by default (no effect on --merge-source Self)
      --merge-end string               end revision of the source, for a 3-way merge, an --upgrade, or a --resolve (uses same format as --restore)
      --merge-external-source string   external source identifier for merge-on-update
      --merge-revisions stringArray    with --upgrade or --resolve, the upstream revisions to take instead of everything pending, which is cherry-picking: a revision as --restore takes one, which names that revision or for a changeset its revisions, or a range <from>..<to>; repeatable. A skipped revision named is taken and its skip removed, but a declined one is held until "cub link skip --decline=false" makes it an ordinary skip. The link's merge pointer stays where it is, and what was taken is listed as merged above it
      --merge-source string            source unit for 3-way merge (slug or UUID)
  -o, --output string                  Output format. One of: json, yaml, name, wide, mutations, jq=<expr>, yq=<expr>, custom-columns=<spec>
      --patch                          use patch API instead of update API
      --permission strings             permission in format Action:UserIDOrUsername, Action:group:GroupSlugOrID or Action:serviceaccount:ServiceAccountSlugOrID to add, or the same prefixed with - to remove (e.g., Manage:user@example.com, View:group:platform, View:serviceaccount:deploy-bot, -View:user@example.com, can be repeated)
      --prior-revisions string         with --change-order and --upgrade or --resolve, what to do for a unit that has not merged as far as the change order's start on its source -- typically because a link in the source's space, such as a TransformPaths link, wrote revisions after the unit last merged: Include (the default) merges those revisions first, as revisions that do not carry the change order, and puts the start tag after them; Skip merges only the change order's range, as though the unit had already merged as far as its start, and those revisions do not arrive later; Error refuses, naming the unit, the link, and the revisions; All merges them as Include does; Defer merges only the change order's range and leaves those revisions pending, to be taken or skipped later, with the link's merge pointer where it was and the range marked merged above it. Defaults to the change order's PriorRevisions
      --quiet                          No default output.
      --replace                        Replace entity instead of merging when using --from-stdin or --filename
      --resolve string                 resolve links from this unit: Link:* for every link that can resolve, Link:<uuid> or Link:<slug> for one, just <slug> (e.g. space/link-name), or Link:<where expression> to select among them (e.g. "Link:UpdateType = 'MergeUnits'") -- the form to use in a bulk operation, where a uuid cannot be. An AutoUpdate link can be resolved by hand and does nothing when it is already level with its source
      --restore string                 restore to a revision: a tag slug, Tag:slug, ChangeSet:slug, ChangeOrder:slug, Release:number, Revision:uuid, an integer (revision number), a negative delta from head, or one of HeadRevisionNum/LastReleasedRevisionNum, optionally prefixed with Before:
      --squash                         merge the range as one rebased diff in one revision instead of walking it: by default a merge re-runs the upstream's recorded function invocations against this unit where it can, so each change lands where this unit's own structure puts it, and records one revision per upstream revision that has an effect here; only valid with --upgrade, --merge-source, or --resolve
      --tag string                     UUID of tag to attach to (new) head revision
      --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)
  -t, --toolchain string               toolchain type to change the unit to, for a unit created with the wrong one; the unit's data is not converted
      --unit strings                   target specific units by slug or UUID (can be repeated or comma-separated)
      --unreleasable                   leave the unit out of its space's releases, so it is delivered to no target; --unreleasable=false releases it again
      --upgrade                        upgrade the unit to the latest version of its upstream unit
      --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 this unit's mutations whose paths the merge must not overwrite, on top of the unit's guards (only used with --merge-source). On a --merge-source Self revert, which is cleared for Override guards, it and the other guards are what the revert leaves alone

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