Skip to content

cub unit set-guard

cub unit set-guard

Record the reasons a path's value is what it is

Synopsis

Set or remove guards on a unit's path annotations.

A guard names a class of reason a path holds the value it does, so that a later operation can be asked to know about that reason before overwriting it. The key names the class and is the matchable part; the value gives the specific reason. Two examples of the shape:

Link=TransformPaths this field is maintained by a link RunAsRoot=LegacyImage this value breaks a default policy because the image needs it

A guard is enforced on every change to the unit's configuration data -- an edit, a function invocation, a trigger, a link, a merge: a change that is not cleared for the reasons at a path does not overwrite it, and reports what it withheld as a conflict. Editing the guards at a path that already carries some needs --clearance for those, on the same rule -- a clearance is the statement that the reasons are understood. Setting the first guard on a path needs none, since there is nothing yet to understand. Without --clearance, an edit is cleared for Override guards, which hold values against merges rather than edits.

A guard set with --guard stays with this unit. One set with --inherited-guard travels: a clone of the unit receives it, including a variant created with cub variant create, and a merge carries it, and any later change to it, to the units downstream. Use it for policy about the configuration that every variant has to honor, such as a value a mass change must not normalize away. Setting a guard again with the other flag changes whether it is inherited, which needs --clearance for it as changing its value does: it decides whether the units downstream have it.

A guard may name a path -- or a resource -- the unit does not have. A guard is policy about the configuration rather than a statement about its current contents: guarding spec.template.spec.containers is as much about containers added next year as about the ones there now, and each of those inherits it.

Each --guard and --inherited-guard takes RESOURCE_TYPE:RESOURCE_NAME:PATH=KEY=VALUE and each --remove-guard takes RESOURCE_TYPE:RESOURCE_NAME:PATH=KEY. Leave PATH empty to guard the resource as a whole. RESOURCE_TYPE may be left empty when the name alone picks out one of the unit's resources, and it matches in any API version; a resource the unit does not have yet is named by both. RESOURCE_NAME is the whole name, or a name the resource had before a rename; a name without a namespace (myapp) matches that name in any namespace, and has to match only one resource. PATH names a list element by merge key or by position, and * stands for every element or key there is; for --remove-guard it also matches the guarded paths the data no longer has. Repeat either flag to edit several paths or resources at once, and combine them to add some guards and retire others in one revision. Setting guards creates a new revision only if they change; pass --change-desc to record why on it.

A change can state its own reasons instead, without naming where: cub unit update --guard and --inherited-guard, cub function do --guard and --inherited-guard, and the Guards field on a link or a trigger take a bare KEY=VALUE and record it on the paths that change wrote. Use this command to guard a path no change of yours is writing, and to remove a guard, which no change can do.

It prints the unit's PathAnnotations with -o json, yaml, jq or yq, or after its confirmation with --verbose.

Examples:

  # Say why this image is what it is: a link maintains it
  cub unit set-guard my-unit \
    --guard "apps/v1/Deployment:default/myapp:spec.template.spec.containers.?name=app.image=Link=TransformPaths"

  # Record on a base that its pod spec needs the host network, for every variant of it
  cub unit set-guard my-unit \
    --inherited-guard "apps/v1/Deployment:default/myapp:spec.template.spec.hostNetwork=HostNetwork=PacketMonitor" \
    --change-desc "The packet monitor needs the host network"

  # Say every container's image is maintained by a link, naming the resource by name alone
  cub unit set-guard my-unit \
    --guard ":myapp:spec.template.spec.containers.*.image=Link=TransformPaths"

  # Stop an inherited guard reaching the units downstream, keeping it on this one
  cub unit set-guard my-unit \
    --guard "apps/v1/Deployment:default/myapp:spec.template.spec.hostNetwork=HostNetwork=PacketMonitor" \
    --clearance "HostNetwork=PacketMonitor"

  # Retire a guard whose reason no longer applies, saying the reason is understood
  cub unit set-guard my-unit \
    --remove-guard "apps/v1/Deployment:default/myapp:spec.template.spec.hostNetwork=HostNetwork" \
    --clearance "HostNetwork=PacketMonitor"
cub unit set-guard <unit-slug> --guard <spec> [--inherited-guard <spec> ...] [--remove-guard <spec> ...] [flags]

Options

      --change-desc string            change description recorded on the revision the edit creates
      --changeset string              changeset open on the unit, as <slug> or <space>/<slug>; a changeset locks the units it is open on, so a write that creates a revision of one has to name it
      --clearance stringArray         class of guarded reason this edit is cleared for, as KEY, KEY=VALUE[;VALUE...], KEY!=VALUE[;VALUE...], or !KEY (repeatable). Required to edit a path that already carries guards. Without it the change is cleared for Override guards, whatever their value, as a merge is not; a clearance given replaces that, and --clearance '' clears nothing
      --guard stringArray             guard to set on this unit alone, as RESOURCE_TYPE:RESOURCE_NAME:PATH=KEY=VALUE (repeatable)
  -h, --help                          help for set-guard
      --inherited-guard stringArray   inherited guard to set, which clones receive and merges carry downstream, as RESOURCE_TYPE:RESOURCE_NAME:PATH=KEY=VALUE (repeatable)
  -o, --output string                 Output format. One of: json, yaml, name, wide, mutations, jq=<expr>, yq=<expr>, custom-columns=<spec>
      --quiet                         No default output.
      --remove-guard stringArray      guard to remove, as RESOURCE_TYPE:RESOURCE_NAME:PATH=KEY (repeatable)
      --verbose                       Detailed output, additive with default output

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