Skip to content

Promoting the setup

Build and try the setup on one cluster (test). Then copy it to another (production) with one command, so nothing is set up by hand twice. hourctl diff shows what differs. hourctl promote makes the target match. Each cluster keeps its own addresses, URLs and secrets.

Clusters never talk to each other. hourctl, on your machine or in CI, reads one cluster’s admin API and changes the other’s.

Test cluster the setup you tried hourctl your machine or CI Production cluster changed through its API Values file production's own values read change addresses, URLs keeps its own secrets, devices, people and data
Each cluster is reached with an API token of its own. Test is only read.

The steps:

  1. Name the clusters once.
  2. Write a values file for each target cluster. It holds its own addresses, URLs and the variables that hold its secrets.
  3. Compare them with hourctl diff.
  4. Promote with hourctl promote.

Most of the setup is the same in every environment. Some fields belong to one environment only. hourctl diff lists those apart, as differing by design. hourctl promote keeps the target’s own where the target has the item. It takes them from the values file where the item is new there.

ItemPromotedBelongs to each environment
Package linethe active revision, by content hash
Policy package line (the tenant’s)the active revision, by content hash
Shared policy package versionthe exact bundle published, by content hash
Adoption of a shared packagethe version it takes
Listenertypelisten, broker, username, password, allow_from, deny_from, proxy_protocol
Endpointlistener, path, topic, reply_topic, package, policy, routes, back_after_minutes, sinks, new_devices, options, sync_group, labelsallow_from, deny_from
Sinktype, eventsurl, secret
Sync group, an endpoint’s own group includeddomains, sinks, the domains’ settings, placement rules, routes
Settingsretention_days, the limitstrusted_proxies, tenant_destinations
Varits value, per scope, where the target lacks itits value, where the target has one
Secretnever; hourctl diff compares names onlythe value
Devices, people, sync datanever; not comparedall of it

API tokens are never promoted either.

hourctl knows clusters by name. Each name stands for an admin URL and the environment variable that holds an API token for it. The token itself is never written down. hourctl reads it from the variable, or from the file that <VAR>_FILE names, each time it talks to the cluster.

  1. Create a token on each cluster, for the person or CI job that promotes:

    Terminal window
    hourctl --admin https://test-gw.example.com:9090 token create promote
    hourctl --admin https://gw.example.com:9090 token create promote
  2. Add the clusters:

    Terminal window
    hourctl cluster add test https://test-gw.example.com:9090 --token-env HOURADVANTAGE_TEST_TOKEN
    hourctl cluster add production https://gw.example.com:9090 --token-env HOURADVANTAGE_PROD_TOKEN
  3. Put each token in its variable:

    Terminal window
    export HOURADVANTAGE_TEST_TOKEN=hadv_...
    export HOURADVANTAGE_PROD_TOKEN=hadv_...
    Terminal window
    $env:HOURADVANTAGE_TEST_TOKEN = "hadv_..."
    $env:HOURADVANTAGE_PROD_TOKEN = "hadv_..."
  4. Use a cluster with --cluster NAME on any command, or make one current:

    Terminal window
    hourctl --cluster production status
    hourctl cluster use test
    hourctl status # talks to test

hourctl cluster list shows each cluster, its URL, its token variable and whether that is set, and which cluster is current. hourctl cluster remove NAME forgets one. A name is letters, digits, -, _ and ., up to 64 characters. cluster add refuses a name that is taken.

The clusters are kept in hourctl.toml in your config folder:

SystemFile
Windows%APPDATA%\houradvantage\hourctl.toml
Linux, macOS$XDG_CONFIG_HOME/houradvantage/hourctl.toml, else ~/.config/houradvantage/hourctl.toml
current = "test"
[cluster.production]
admin = "https://gw.example.com:9090"
token_env = "HOURADVANTAGE_PROD_TOKEN"
[cluster.test]
admin = "https://test-gw.example.com:9090"
token_env = "HOURADVANTAGE_TEST_TOKEN"

Which cluster a command talks to, first match wins:

  1. --admin URL. It cannot be given with --cluster.
  2. --cluster NAME.
  3. HOURADVANTAGE_ADMIN_URL.
  4. The current cluster (hourctl cluster use).
  5. http://127.0.0.1:9090.

A cluster added without --token-env signs in as hourctl does without one. That is with HOURADVANTAGE_ADMIN_TOKEN, else the admin login. A cluster whose token variable is not set is refused. The error names the variable.

hourctl diff FROM TO reads both clusters and prints what differs. It changes nothing. It never reads a secret’s value, because the admin API gives secrets’ names only.

Terminal window
hourctl diff test production
KIND ID FIELD TEST PRODUCTION
package [email protected] active 2.4.1 (5c2d8f0e9a7b) 2.4.0 (0a1b2c3d4e5f)
sink audit exists yes -
endpoint office labels {"site":"north"} -
endpoint office sinks payroll -
setting retention_days value 14 30
var site_code value HQ-01 -
secret api_key exists yes -
differs by design (each environment's own, kept by promote):
KIND ID FIELD TEST PRODUCTION
sink payroll url https://test.example.com https://payroll.example.com
endpoint office allow_from 10.0.0.0/8 192.0.2.0/24
setting trusted_proxies value - 10.0.0.5
var cloud_url value https://test.example.com https://cloud.example.com
Device registrations, people and sync data belong to each environment and are not compared.
Column
KINDpackage, policy package, shared package, adoption, listener, sink, sync group, endpoint, setting, var or secret
IDThe line, id or name. A package var or secret is NAME (package PACKAGE).
FIELDThe field that differs. It is exists when only one cluster has the item, and active for a package line’s active revision.
FROM, TOeach cluster’s value; - for none. A package line shows its version and the start of its content hash.

An empty list, an empty object, false and no value count as the same.

Package lines, policy package lines and shared versions are compared by the content hash of their active (or published) revisions, not by revision number. The same bundle has a different revision number in each cluster. An adoption differs when it takes another version.

With --json, hourctl diff prints:

{
"from": "test",
"to": "production",
"differences": [
{ "kind": "endpoint", "id": "office", "field": "sinks", "from": ["payroll"], "to": [] },
{ "kind": "secret", "id": "api_key", "field": "exists", "from": true, "to": false }
],
"by_design": [
{ "kind": "endpoint", "id": "office", "field": "allow_from", "from": ["10.0.0.0/8"], "to": ["192.0.2.0/24"] }
]
}
Exit statusMeaning
0No differences. What differs by design does not count.
1The clusters differ.
2The comparison could not be made: a cluster is not named, does not answer, or refuses the token.

hourctl promote FROM TO makes the items you choose on TO as FROM has them. With --all that is all configuration. That means:

  • every package line, policy package line and shared version active on FROM;
  • every adoption of the tenant’s;
  • every listener, sink, sync group (each endpoint’s own group too), endpoint and var;
  • the settings.
OptionPromotes
--allAll configuration, as above.
--package LINEA package line, [email protected] ([email protected]): the exact bundle of its active revision on FROM, pushed to TO and activated there.
--policy LINEA policy package line of the tenant’s, [email protected] ([email protected]), from the tenant’s packages on FROM to the same tenant’s on TO.
--shared LINEA shared policy package’s published version, NAME@VERSION ([email protected]): the exact bundle, published on TO. Refused when TO has that version published with other content.
--adoption NAMEA shared package the tenant adopted, with the version it takes on FROM.
--listener IDA listener.
--endpoint IDAn endpoint, with its sync group and what it names that TO lacks.
--sink IDA sink.
--group NAMEA sync group, with the sinks it names that TO lacks.
--var NAMEA var: NAME for the tenant’s, PACKAGE/NAME for a package’s. A var named here replaces the value TO has.
--settingsretention_days and the limits.
--values FILETO’s own values for items new on TO (the values file).
--yesMake the changes. Without it, hourctl prints the plan and changes nothing.

Repeat --package, --policy, --shared, --adoption, --listener, --endpoint, --sink, --group and --var for several. Name at least one item, or --all. --all takes --var too, to replace those vars’ values on TO.

An item brings what it needs, and the plan says which item needed it:

  • An endpoint brings its sync group. The group is created, or updated where TO has it. The endpoint also brings the listener, sinks, package line and policy package line it names that TO does not have. An endpoint whose policy is an adopted shared package brings the adoption, and an adoption brings the version it takes.
  • A sync group brings the sinks it names that TO does not have.
  • A package line brings the vars it requires that TO does not have, in either scope.

A listener or sink TO already has is left as it is when it only comes along. Name it, or use --all, to update it.

  • Package line, policy package line, shared version. The exact bundle of FROM’s active (or published) revision is pushed to TO and activated there. It is checked on TO as every push is, scenarios included. It has the same content hash. A shared version goes only with an install token on both clusters.
  • Listener, endpoint, sink, sync group. Created on TO, or updated where TO has it. The fields that belong to each environment stay as TO has them. An item new on TO takes them from the values file.
  • Var. One TO lacks is set to the value in the values file, else to FROM’s. One TO has with another value is kept, unless you name it with --var. Then it is set to the value in the values file, else to FROM’s.
  • Settings. retention_days and the limits. trusted_proxies and tenant_destinations stay as TO has them.
  • Secret. Never copied. The plan is refused while a promoted package line requires a secret TO does not have. Set it there first with hourctl --cluster production secret set NAME.

The values file holds TO’s own values for the items that are new on TO. These are the values that would point production at test systems if they were copied. Keep one per target cluster, next to your packages. It holds no secret. A *_env field names the environment variable hourctl reads the secret from.

[listeners.devices]
listen = "0.0.0.0:8080"
[listeners.cloud]
broker = "mqtts://broker.example.com:8883"
username = "houradvantage"
password_env = "PROD_BROKER_PASSWORD"
[sinks.payroll]
url = "https://payroll.example.com/houradvantage/events"
secret_env = "PAYROLL_SECRET"
[endpoints.office]
allow_from = ["192.0.2.0/24"]
[vars]
cloud_url = "https://cloud.example.com"
[vars.zk-push] # vars of the package zk-push
cloud_url = "https://zk.example.com"
TableFieldsNeeded for a new item
[listeners.ID]listen, broker, username, password_env, allow_from, deny_from, proxy_protocollisten (http) or broker (mqtt); username and password_env when FROM’s listener has them
[sinks.ID]url, secret_envurl; secret_env when FROM’s sink has a secret
[endpoints.ID]allow_from, deny_fromnone: without them a new endpoint lets in every address its listener does
[vars]NAME = "value"; [vars.PACKAGE] for a package’s varsnone: without one a var TO lacks gets FROM’s value

Values for an item TO already has are not used: TO keeps its own. A file with a table or field it does not take stops hourctl promote before either cluster is read. One that gives values for an item or var FROM does not have refuses the plan.

The plan is refused before anything changes when a new item needs a value the file does not give. It is refused the same way when a *_env field names a variable that is not set. Every missing value is named at once:

refused: production needs its own values for what is new there; give them in the --values file: sink payroll: url; sink payroll: secret_env; listener devices: listen
  1. Print the plan:

    Terminal window
    hourctl promote test production --all --values production-values.toml
    promote test -> production (production at gw.example.com:9090):
    sink payroll: create (secret, url from the values file)
    listener devices: create (listen from the values file)
    sync group office: create
    var cloud_url: set
    var site_code: kept as production has it, with another value (name it with --var site_code to replace it)
    package [email protected]: push and activate 2.4.1 (5c2d8f0e9a7b)
    endpoint office: create (allow_from from the values file)
    settings: update retention_days
    Secrets, device registrations, people and sync data are never promoted.
    Nothing was changed. Run it again with --yes to make these changes on production.
  2. Make it:

    Terminal window
    hourctl promote test production --all --values production-values.toml --yes

    hourctl names the environment it changes. Then it makes each change in an order where every item exists before anything names it. It waits for every instance of TO to run each promoted revision, and for every instance to apply the setup changes. It does not give up after a time: it says who it is waiting for, and an instance that refuses a change says why. It says how far they got.

An item TO already has as FROM has it shows as unchanged. When nothing needs to change, hourctl says so. Run the same command again after any change on FROM: only what differs changes.

hourctl promote checks the whole plan before it changes anything. It refuses the plan, changes nothing, names every reason and exits 1 when:

  • a named item or var does not exist on FROM, or a named package line has no active revision there;
  • an endpoint’s package is served by no package line active on FROM or TO;
  • a new item needs a value the values file does not give;
  • a promoted package line requires a secret TO does not have;
  • the values file gives values for an item or var FROM does not have.
refused: package [email protected] requires secret api_key, which production does not have (secrets are never copied); set it there first: hourctl --cluster production secret set api_key
error: the plan is refused, and nothing was changed on production: package [email protected] requires secret api_key, ...

A change TO refuses while the plan is being carried out stops the promotion, with TO’s error and exit status 1. The changes made before it stay made.

Every change goes through TO’s admin API under TO’s token, so TO’s audit trail (hourctl audit) records it as token:NAME. FROM is only read.

With --json, hourctl promote prints the plan, what was refused, and whether it was applied:

{
"from": "test",
"to": "production",
"plan": [
{ "kind": "sink", "id": "payroll", "action": "create", "fields": ["events", "secret", "type", "url"],
"kept": [], "needed_by": "endpoint office", "from_values": ["secret", "url"] },
{ "kind": "package", "id": "[email protected]", "action": "push and activate", "fields": [], "kept": [],
"needed_by": null, "hash": "sha256:5c2d8f0e9a7b6c4d3e2f1a0b9c8d7e6f0a1b2c3d4e5f60718293a4b5c6d7e8f9" },
{ "kind": "endpoint", "id": "office", "action": "update", "fields": ["labels", "sinks"],
"kept": ["allow_from"], "needed_by": null }
],
"refused": [],
"applied": true
}
Field
kindpackage, policy package, shared package, adoption, listener, sink, sync group, endpoint, var or settings
idthe line, id or var (PACKAGE/NAME for a package’s var); null for the settings
actionpush and activate, adopt (a shared package’s version), create, update, set (a var), none (already as wanted) or kept (a var TO keeps; reason says why)
fieldsthe fields created or changed, by name; never their values
keptthe fields that stay as TO has them
needed_bythe item that brought it into the plan; null when it was chosen
from_valuesfor create: the fields taken from the values file
hashfor a package, policy package or shared package line: the content hash of the bundle promoted
versionfor adopt: the shared package version adopted

A CI job does the same with a token per cluster. The tokens are kept in the CI system’s secret store and handed to the job as the variables the clusters name. Commit the values file with the rest of your setup. The secrets it names come from the CI system’s secret store too.

Terminal window
hourctl cluster add test https://test-gw.example.com:9090 --token-env HOURADVANTAGE_TEST_TOKEN
hourctl cluster add production https://gw.example.com:9090 --token-env HOURADVANTAGE_PROD_TOKEN
# Exit status 1 means the clusters differ; 2 means the comparison failed.
status=0
hourctl diff test production --json > drift.json || status=$?
case $status in
0) echo "no differences" ;;
1) echo "the clusters differ; see drift.json" ;;
*) exit 1 ;;
esac
# PAYROLL_SECRET and PROD_BROKER_PASSWORD come from the CI secret store.
hourctl promote test production --all --values production-values.toml --yes
Terminal window
hourctl cluster add test https://test-gw.example.com:9090 --token-env HOURADVANTAGE_TEST_TOKEN
hourctl cluster add production https://gw.example.com:9090 --token-env HOURADVANTAGE_PROD_TOKEN
hourctl diff test production --json > drift.json
switch ($LASTEXITCODE) {
0 { "no differences" }
1 { "the clusters differ; see drift.json" }
default { exit 1 }
}
# PAYROLL_SECRET and PROD_BROKER_PASSWORD come from the CI secret store.
hourctl promote test production --all --values production-values.toml --yes
if ($LASTEXITCODE -ne 0) { exit 1 }

A refused plan exits 1 and changes nothing, so the job fails before production is touched. The clusters the job adds go into the runner’s own config folder. Give the CI job tokens of its own (hourctl token create ci-promote), so you can revoke them alone.