Keep a Variant's Own Values
A variant exists to differ from its base, and merging upstream changes into it raises the same question every time: which of its differences are its own to keep, and which is it only carrying until the upstream changes them? ConfigHub answers per path, from guards you set, rather than by guessing from the data. This guide covers the Override guard that keeps a variant's own value, guards for other reasons and the clearances that let a change write past them, and the conflicts a merge records for what it withheld. Use Advanced Merging Techniques covers the merge engine itself, and two rules that decide the same question without guards.
Protecting a variant's own values
Keeping a value is opt-in. An ordinary change — a hand edit, a function invocation, a needs/provides binding — writes a path without claiming it, and so does content that arrives from a clone, an upgrade, or a merge. So by default an upstream change to a path reaches the variant even if someone here had set that path to something else. That is the right default for a value the variant is carrying: a replica count copied down from the base should follow the base when the base changes its mind.
A value the variant has chosen, on the other hand, should say so, with an Override guard on its path: Override=Upstream on a unit cloned from an upstream unit, and Override=External on a unit without one, such as a base uploaded from rendered manifests. A merge — an upgrade, a promotion, a --merge-source from another unit, a --merge-external-source or upload, a --resolve of an UpgradeUnit or MergeUnits link, cub k8s refresh — is not cleared for it unless its --clearance says so, so the merge leaves the value alone and reports what it withheld as a conflict. Every other change is: cub and the UI clear Override guards by default for a change that is not a merge, so the variant's own edits to the value land without a clearance. Keep on merge in the UI sets the same guard. Two ways to set it:
As you make the change, with --guard Override=Upstream on cub unit update or cub function set. Every path the change writes gets the guard.
cub function set --space prod --unit backend-clone --guard Override=Upstream set-replicas 5
Afterwards, per path, with cub unit set-guard. Each --guard and --remove-guard names a resource type, a resource name, and a path:
# This deployment's replica count is prod's own from here on.
cub unit set-guard --space prod backend-clone \
--guard "apps/v1/Deployment:prod/backend:spec.replicas=Override=Upstream"
# Changed our mind: let the base drive it again.
cub unit set-guard --space prod backend-clone \
--remove-guard "apps/v1/Deployment:prod/backend:spec.replicas=Override"
Removing the guard lets the next upstream change to the path land. It does not bring back a change a merge already withheld; apply the conflict for that. Neither form touches the configuration data — the guard is a statement about who owns a field, not a value — and each creates a new revision only if the guards change.
Leave the guard off for a script propagating a release by any other means, such as invoking functions across variants: guarding what it wrote would turn upstream content into local overrides and block every merge after it.
To see which of a unit's values it keeps, look for the G flag in cub unit blame, and pass --verbose to see each field's guards (see seeing guards).
Guards are stored per path, so they are remembered across merges, and restoring a revision brings back the guards it had. They belong to the resource rather than to one API version of its type: when an upgrade moves a resource to a new apiVersion, such as a SecretStore from external-secrets.io/v1beta1 to external-secrets.io/v1, its guards stay, and a resource type in set-guard names the resource in any of its versions. Two mechanisms decide the same question by rule instead, on top of the guards — a WhereMutation filter over mutation history, and the subtraction step, which infers overrides from the diff at merge time.
A merge of the unit's own history (--merge-source Self), a rebase or a revert, is cleared for Override guards, since the values it puts back or takes away are the unit's own. The unit's other guards hold against it.
Releases before v0.11.6 recorded these choices as protection, with --protect and cub unit set-protection. Both are deprecated; they still work, and set the Override guard. Protection stored by earlier releases was converted to guards: Override=Upstream or Override=External, or, on a value a link or trigger wrote, the guard naming that link or trigger (Link=<UpdateType>, Trigger=<Slug>).
Guarding values against every change
A guard records why a path holds the value it does, as a KEY=VALUE pair, and every change to the unit's configuration data — a hand edit, a function invocation, a trigger, a link, an upgrade or merge, cub k8s refresh — must be cleared for that reason before it may overwrite the path. A change states what it is cleared for with a clearance. A change without a matching clearance leaves the guarded path as it was, applies the rest, and reports what it withheld as a conflict.
The mechanism is modeled on Kubernetes taints and tolerations: a guard on a path plays the part of a taint on a node, and a clearance on a change plays the part of a toleration on a pod. The difference is that a guarded value is not undesirable — it was set deliberately, and the guard is there so that a tool or person who does not know why does not change it by accident.
The Override guard that keeps a variant's own value is one such reason, which only merges are expected not to know about, so changes that are not merges are cleared for it by default. Use other keys for reasons that anyone changing the value should know about, wherever the change comes from.
Choosing guard keys and values
The key names a class of reason and is what a clearance matches on; the value distinguishes cases within that class. The reasons can be structural or functional requirements.
- Structural — the field is maintained by an automatic mechanism, such as a link or a trigger or an external "bot", and other writers should leave it alone so as not to fight with it.
Link=TransformPathson an image field that aTransformPathslink sets is a typical case. - Requirement — the value is needed for correct behavior, though it may violate a default policy, and a tool or other source of mass change that normalizes values to that policy must not undo it. For example, a container that needs to run as root due to a legacy image assuming root could be expressed as
RunAsRoot=LegacyImage. The key should represent a category and the value should convey an informative reason, ideally more specific than the path the guard is attached to. That approach enables clearances to be expressed for some reasons, but not others. For example, one may want to convert all containers running as root to more specific capabilities where possible, but without breaking containers that are running as root for other reasons.
Standardize the set of keys across your organization. A clearance is usually written by someone who has not looked at the specific unit, so it can only name reasons that mean the same thing everywhere. Keys and values are letters, digits, - and _ (values may also contain .), up to 128 characters. Keys starting with confighub- are reserved. A longer explanation can be recorded in the change description of the revision created for the guard change.
Setting guards
As you make the change, with --guard KEY=VALUE on cub unit update, cub function set, cub k8s refresh, or cub variant promote. The guard is recorded on every path the change wrote. All but cub variant promote also take --inherited-guard KEY=VALUE, which records an inherited guard instead; a key may not be given to both. The change has to be cleared for its own guards, or it is refused: a change is withheld by every guard it is not cleared for, its own included, so the next change that writes the path the same way would be withheld, and so would the second upstream revision of an upgrade that replays several. The default clearance covers an Override guard; pass a --clearance that covers any other.
cub function set --space prod --unit backend \
--guard Scale=RegionSpecific --clearance Scale=RegionSpecific set-replicas 7
Triggers, links and stored invocations take --guard too, and record it on the paths they write each time they run. A TransformPaths link that maintains a field is the natural place to say why. Give it the matching clearance as well, as for any change; a trigger, link or invocation whose guards its own clearance does not cover is refused when it is created or updated. A trigger that runs an invocation records the guards of both, the trigger's winning where both name a key. The guards these record are always local to the unit:
cub link create --space prod image-link backend images \
--update-type TransformPaths --from-stdin < image-link.yaml \
--guard Link=TransformPaths --clearance Link=TransformPaths
UpgradeUnit and MergeUnits links refuse --guard, because their guards arrive from the upstream unit.
A guard naming a link or trigger holds a hand edit to the path too, unless the edit passes --clearance Link=TransformPaths (or --clearance Trigger=<slug>). The link or trigger would write its own value back the next time it resolves or runs, so the conflict tells you now rather than after your change is overwritten.
Deleting a link or trigger removes the guards it recorded, and updating one removes those it no longer states, such as a trigger's Trigger=<slug> guard after the trigger is renamed. Each is removed only where the link's or trigger's change is still the last write to the path, and the guard still has the value it gave it. The data it wrote stays.
Afterwards, or ahead of time, per path, with cub unit set-guard. Each --guard or --inherited-guard names a resource type, a resource name, a path, and the guard; leave the path empty to guard the whole resource:
# A link maintains this image (though the link itself should set this)
cub unit set-guard --space prod backend \
--guard "apps/v1/Deployment:prod/backend:spec.template.spec.containers.?name=app.image=Link=TransformPaths"
# This pod spec needs to run on the host network, in every variant of it
cub unit set-guard --space base backend \
--inherited-guard "apps/v1/Deployment:base/backend:spec.template.spec.hostNetwork=HostNetwork=PacketMonitor"
A guard applies to the path and everything under it, including paths that do not exist yet. For example, guarding spec.template.spec covers a container added later. For the same reason, set-guard accepts a path, or a resource, that the unit does not currently have, so check the spelling — a misspelled path is accepted and guards nothing.
Setting guards changes no configuration data. It creates a new revision if the guards change, and neither --guard on a change nor set-guard --guard removes a guard. To remove one, use --remove-guard, which takes the same form without the value, together with a clearance for the guard being removed:
cub unit set-guard --space prod backend \
--remove-guard "apps/v1/Deployment:prod/backend:spec.template.spec.hostNetwork=HostNetwork" \
--clearance HostNetwork=PacketMonitor
Changing or removing the guards at a path that already has some needs a clearance for them, and so does changing whether a guard is inherited; setting the first guard on a path does not.
Clearances
A change that needs to write a guarded path says which reasons it is cleared for with --clearance, on cub unit update, cub function set, cub k8s refresh, and cub unit set-guard, and on triggers, links and invocations, which run without anyone passing a flag. A trigger that runs an invocation is cleared for what either is cleared for. The syntax follows Kubernetes set-based label selectors:
| Clearance | Clears a guard KEY=VALUE when |
|---|---|
KEY |
always, whatever the value |
KEY=A;B |
the value is A or B |
KEY!=A;B |
the value is neither A nor B |
!KEY |
never: a path carrying any KEY guard is not written, whatever else the clearance says |
--clearance is repeatable, and a guarded path is written only if every guard key on it and on its ancestors is cleared. Paths with no guards are unaffected, and a unit with no guards at all behaves exactly as if guards did not exist.
A change that passes no --clearance is cleared for Override guards, whatever their value, unless it is a merge: an upgrade, a promotion, an upload, a merge from another unit, a --resolve of an UpgradeUnit or MergeUnits link, cub k8s refresh, and applying a conflict get no default. cub, the Go client library and the UI send this default; the API itself has none. A clearance you pass replaces the default rather than adding to it, so --clearance '' is cleared for nothing, and --clearance Scale=RegionSpecific alone withholds a write to an Override-guarded path. The flags cub suggests after a withheld write include Override when the write relied on it. Links, triggers and invocations get no default either: their clearance is stored, and is all they are cleared for.
# Withheld: set-replicas is not cleared for the capacity change
cub function set --space prod --unit backend set-replicas 42
# Lands
cub function set --space prod --unit backend \
--clearance Scale=RegionSpecific set-replicas 42
# Cleared for a downstream override but not if the field is written by a link
cub function set --space prod --where "Labels.tier = 'backend'" \
--clearance Override=Upstream --clearance '!Link' set-image app registry.example.com/app:1.4
Give a trigger or a link the clearance for the guards it is meant to overwrite. Guard an image field with Link=TransformPaths, give the TransformPaths link that maintains it --clearance Link=TransformPaths, and give the UpgradeUnit link none: upgrades then stop overwriting the image, and the transform link keeps updating it. A trigger or link that should write a path a variant keeps as its own needs --clearance Override as well.
cub link update --space prod --patch image-link --guard Link=TransformPaths --clearance Link=TransformPaths
A clearance says the change knows about a reason; it does not grant permission. Currently anyone who can edit the unit can pass one. Guards exist to stop changes made without knowing why a value is what it is, and each mutation records the clearance its change was filtered with, and the guards it stated (inherited ones under InheritedGuards), so overriding a guard is visible in the unit's history. On a function invocation, the clearance recorded is the request's together with that of every trigger and invocation that wrote in the same execution; on a link's change, it is the link's.
cub mutation list --space prod backend --where "Clearance.*.Key = 'RunAsRoot'"
cub mutation list --space prod backend --where "Guards.Link = 'TransformPaths'"
cub mutation list --space base backend --where "InheritedGuards.HostNetwork = 'PacketMonitor'"
Restricting which users may clear which keys may be added in the future.
Guards on variants
A guard is either local to its unit, which is the default, or inherited. Most guards are local: a guard a link or trigger records is about that link or trigger, and an Override guard that keeps a variant's own value from being overwritten by upgrades and external merges is about that variant. An inherited guard is policy about the configuration that every variant of it has to honor, such as a value a mass change must not normalize, and is set with --inherited-guard rather than --guard.
- Clones —
cub variant create,cub unit create --upstream-unit, bulk clones, and a promotion that creates a unit its target does not have yet — copy the inherited guards along with the data. Local guards stay behind. - Upgrades, promotions and
MergeUnitslinks carry the inherited guards added, changed, or removed upstream since the last merge, including a guard change with no data change beside it. When the base drops a policy exception because the workload no longer needs it, the variants drop it too. A guard that arrives inherited stays inherited, so it travels on from there, from base to staging to prod. - Making an inherited guard local upstream, by setting it again with
--guard, removes it from the variants at their next merge; the upstream keeps it. Making a local guard inherited, by setting it again with--inherited-guard, sends it to them. Either needs a clearance for the guard. - A variant's own guards are not touched by upstream removals: if the base removes an inherited guard and the variant has set the same key itself, the variant keeps its guard. A variant can add or remove guards of its own with
set-guardat any time.
Guard changes arrive under the same rule as data: an upstream guard change lands at a path only if the merge is cleared for the guards the variant already has there. A guard change the merge was not cleared for is reported as a GuardWithheld conflict, so a variant that did not receive a base's new policy exception shows it, rather than differing silently.
Guards set before guards could be inherited are local. Copies of them that earlier releases carried into variants stay there as the variants' own guards; mark the base's guard inherited if it should keep reaching them.
Seeing guards
cub unit blame marks guarded fields G in its FLAGS column, and --verbose lists the guards on each field, with (inherited) after each inherited one:
cub unit blame --space prod backend --verbose
cub unit get --verbose prints the unit's whole guard table under Path Annotations, where the keys under GuardInherited name the inherited guards beside them. Triggers, links and invocations that set guards, or carry clearances, are selectable:
cub trigger list --where "Guards.Owner = 'platform'"
cub link list --where "Clearance.*.Key = 'Link'"
cub invocation list --where "Guards.Scale = 'RegionSpecific'"
Conflicts: what a merge could not apply
A merge that cannot apply part of what it brought does not fail, and does not apply it anyway. It applies the rest and records what it withheld on the unit, where it stays until you deal with it. On a unit with guards, any change can withhold part of what it wrote in the same way:
cub unit conflicts --space prod backend-clone
Each conflict names the resource, the path, the value that was withheld, and a reason:
Guarded— the path carries a guard the change was not cleared for, so the change's value was withheld. The conflict names the guards. This is the common one: anOverrideguard keeping a variant's own value reports the upstream change it withheld rather than working silently.ProtectedPath— the path is held by a link'sWhereMutationfilter, so the upstream's change to it was withheld. Conflicts recorded before v0.11.6 also use it for a path the variant had protected.GuardWithheld— the upstream added, changed, or removed an inherited guard at a path, and the merge was not cleared for the guards this unit already has there, so the guard change was withheld. Applying it writes the guard change rather than any configuration data.ExclusiveWithheld/ExclusiveCleared— the two sides set mutually exclusive fields (a volume with one source, a deployment strategy and its options). The downstream's choice stands and the upstream's is reported.Subtracted,DeleteShadowed— the subtraction step dropped a change, or a deletion could not be applied because the target had changed underneath it.UnresolvedPath— the path the source changed could not be located in this unit.ReplayFailed— a replayed function errored here. The step was patched instead, and the conflict carries the function name and the error.
Conflicts are queryable, so "which variants have something outstanding?" is one command:
cub unit list --where "Conflicts.*.Reason = 'Guarded'"
Deal with one by applying it — take the upstream's value after all — or dismissing it:
# What would taking the upstream's value do here? --dry-run writes nothing.
cub unit conflicts --space prod backend-clone --apply --dry-run -o mutations \
--clearance Override=Upstream
# Apply everything withheld for a given reason
cub unit conflicts --space prod backend-clone --apply --reason Guarded \
--clearance Override=Upstream
# Or drop the report without changing any data
cub unit conflicts --space prod backend-clone --dismiss --reason Guarded
--path and --resource narrow the selection further, and --resource-type tells apart resources that share a name, such as a Deployment and a Service named for their app, matching the type in any API version; with no selector, --apply and --dismiss act on everything outstanding. The Blame tab of a unit's page applies and dismisses the conflicts on the fields you select. --dry-run works with either and reports what the request would do — with -o mutations, as the same per-path list a real one records.
Applying writes the withheld value and records the path as content that came from elsewhere. Dismissing changes no data and leaves the guard in place. Applying a Guarded conflict needs a --clearance covering the guards at its path, as any change to it does — conflict apply is a merge, so it gets no default clearance — and the error names the clearance that would allow it. It leaves the guard in place, since a clearance acknowledges a reason rather than retiring it, so the next upstream change to the path is withheld again. To let merges update the path from then on, remove the guard with cub unit set-guard --remove-guard.
A conflict stays outstanding until it is applied or dismissed, or its source settles it, so a later merge that lands cleanly does not clear a conflict nobody has looked at. A merge adds its conflicts to the outstanding set, and a newer conflict about the same withheld change takes the place of the older one. Of the earlier conflicts, a merge drops those its source has since settled: the source and the unit now agree at the path, because the source took the unit's value or the unit took the source's. Conflicts another source left stay, as do those an upload left, since an external source has no revisions to settle them against.
To make outstanding conflicts block a Release rather than sit there, attach the vet-no-merge-conflicts validating function as a Trigger; it fails while anything is outstanding, which turns into a Validation Error.
Related reading
- Create and Manage Variants, for creating, uploading and promoting variants
- Use Advanced Merging Techniques, for
WhereMutationand the subtraction step, which decide by rule what a merge leaves alone - Trace Where Configuration Values Came From, for seeing a field's guards and conflicts, and applying or dismissing them in the UI