Skip to content

cub k8s appconfig extract

cub k8s appconfig extract

Move files held in a ConfigMap into AppConfig units that are written back into it

Synopsis

Move each file a ConfigMap holds in its data into an AppConfig unit of its own, and link the ConfigMap's unit to it so that the file is written back into the ConfigMap whenever the AppConfig unit changes.

For each data key, extract:

  1. Creates an AppConfig unit in the ConfigMap unit's space holding the file exactly as the ConfigMap holds it. Its toolchain is the one the key's extension names (.json is AppConfig/JSON, .yaml and .yml AppConfig/YAML, .toml, .ini, .properties, .env), and AppConfig/Text for any other key; --toolchain picks one instead.
  2. Guards the data key in the ConfigMap's unit with Link=Insert, which says a link maintains it. Another change to that key has to be cleared for Link=Insert: an upgrade from the unit's upstream, for one, no longer overwrites it unless its link carries that clearance.
  3. Creates an Insert link from the ConfigMap's unit to the AppConfig unit, which writes the AppConfig unit's content to that data key, stating the same guard on what it writes and cleared for it. Nothing else in the ConfigMap is touched: its name, namespace, labels and annotations stay what they are, so whatever finds the ConfigMap by them -- a Grafana dashboard sidecar looking for grafana_dashboard: "1", a pod mounting it by name -- keeps finding it.

The ConfigMap's data is not changed: the AppConfig unit starts with the content the ConfigMap already has, and the guard is the unit's only new revision. A data key that already carries guards, its own or the ConfigMap's, is extracted only with a --clearance covering them, which the guard edit and the link are both given. Edit the file from then on in the AppConfig unit; the link writes the change into the ConfigMap's unit, and the next release of that unit carries it to the cluster.

Every data key is extracted unless --key names some. --slug names the AppConfig unit when one key is extracted; otherwise each is named after its key without the extension (dashboard.json becomes dashboard).

A ConfigMap annotated confighub.com/ConfigMapFormat: KeyValue holds variables rather than files, and is refused.

When the ConfigMap's unit is a variant of an upstream unit, its upgrades carry the upstream ConfigMap's changes to the extracted keys, which the guard now withholds. Extract the upstream ConfigMap too, then replace the unit's UpgradeUnit link with one from each AppConfig unit to the one extracted upstream, so the file is upgraded as a file. Extract prints a warning saying so.

Examples:

  # Move a Grafana dashboard's JSON out of its ConfigMap
  cub k8s appconfig extract --space observability dashboard-confighub-app

  # The same, naming the AppConfig unit
  cub k8s appconfig extract observability/dashboard-confighub-app --slug confighub-app-dashboard

  # One key of a ConfigMap holding several, from a unit holding several ConfigMaps
  cub k8s appconfig extract --space app app-config --configmap app/settings --key application.properties
cub k8s appconfig extract <unit> [flags]

Options

      --change-desc string      change description
      --changeset string        changeset open on the unit, as <slug> or <space>/<slug>, which the AppConfig units are created in and the guard is recorded in; open it on the unit first with cub unit update --patch --changeset
      --clearance stringArray   class of guarded reason the guard edit and the link are cleared for, as KEY, KEY=VALUE[;VALUE...], KEY!=VALUE[;VALUE...], or !KEY (repeatable); needed when a data key already carries guards. The link is cleared for Link=Insert as well
      --component string        the Component of --variant, when that names the variant alone; --variant <component>/<variant> says the same in one flag
      --configmap string        the ConfigMap to extract from, by name or namespace/name; needed when the unit holds more than one
  -h, --help                    help for extract
      --key strings             data key to extract (repeatable); every key when omitted
      --slug string             slug of the AppConfig unit, when one key is extracted; by default the key without its extension
      --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
      --toolchain string        AppConfig toolchain of the extracted files, such as AppConfig/JSON; by default the one each key's extension names
      --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

Options inherited from parent commands

      --context string   The context to use for this command
      --debug            Debug output

SEE ALSO