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.
The steps:
- Name the clusters once.
- Write a values file for each target cluster. It holds its own addresses, URLs and the variables that hold its secrets.
- Compare them with
hourctl diff. - Promote with
hourctl promote.
What belongs to each environment
Section titled “What belongs to each environment”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.
| Item | Promoted | Belongs to each environment |
|---|---|---|
| Package line | the active revision, by content hash | |
| Policy package line (the tenant’s) | the active revision, by content hash | |
| Shared policy package version | the exact bundle published, by content hash | |
| Adoption of a shared package | the version it takes | |
| Listener | type | listen, broker, username, password, allow_from, deny_from, proxy_protocol |
| Endpoint | listener, path, topic, reply_topic, package, policy, routes, back_after_minutes, sinks, new_devices, options, sync_group, labels | allow_from, deny_from |
| Sink | type, events | url, secret |
| Sync group, an endpoint’s own group included | domains, sinks, the domains’ settings, placement rules, routes | |
| Settings | retention_days, the limits | trusted_proxies, tenant_destinations |
| Var | its value, per scope, where the target lacks it | its value, where the target has one |
| Secret | never; hourctl diff compares names only | the value |
| Devices, people, sync data | never; not compared | all of it |
API tokens are never promoted either.
Named clusters
Section titled “Named clusters”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.
-
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 promotehourctl --admin https://gw.example.com:9090 token create promote -
Add the clusters:
Terminal window hourctl cluster add test https://test-gw.example.com:9090 --token-env HOURADVANTAGE_TEST_TOKENhourctl cluster add production https://gw.example.com:9090 --token-env HOURADVANTAGE_PROD_TOKEN -
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_..." -
Use a cluster with
--cluster NAMEon any command, or make one current:Terminal window hourctl --cluster production statushourctl cluster use testhourctl 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:
| System | File |
|---|---|
| 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:
--admin URL. It cannot be given with--cluster.--cluster NAME.HOURADVANTAGE_ADMIN_URL.- The current cluster (
hourctl cluster use). 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.
Compare two clusters
Section titled “Compare two clusters”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.
hourctl diff test productionKIND ID FIELD TEST PRODUCTIONpackage [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 30var site_code value HQ-01 -secret api_key exists yes -
differs by design (each environment's own, kept by promote):KIND ID FIELD TEST PRODUCTIONsink payroll url https://test.example.com https://payroll.example.comendpoint office allow_from 10.0.0.0/8 192.0.2.0/24setting trusted_proxies value - 10.0.0.5var 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 | |
|---|---|
| KIND | package, policy package, shared package, adoption, listener, sink, sync group, endpoint, setting, var or secret |
| ID | The line, id or name. A package var or secret is NAME (package PACKAGE). |
| FIELD | The field that differs. It is exists when only one cluster has the item, and active for a package line’s active revision. |
| FROM, TO | each 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 status | Meaning |
|---|---|
| 0 | No differences. What differs by design does not count. |
| 1 | The clusters differ. |
| 2 | The comparison could not be made: a cluster is not named, does not answer, or refuses the token. |
Promote
Section titled “Promote”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.
| Option | Promotes |
|---|---|
--all | All configuration, as above. |
--package LINE | A package line, [email protected] ([email protected]): the exact bundle of its active revision on FROM, pushed to TO and activated there. |
--policy LINE | A 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 LINE | A 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 NAME | A shared package the tenant adopted, with the version it takes on FROM. |
--listener ID | A listener. |
--endpoint ID | An endpoint, with its sync group and what it names that TO lacks. |
--sink ID | A sink. |
--group NAME | A sync group, with the sinks it names that TO lacks. |
--var NAME | A var: NAME for the tenant’s, PACKAGE/NAME for a package’s. A var named here replaces the value TO has. |
--settings | retention_days and the limits. |
--values FILE | TO’s own values for items new on TO (the values file). |
--yes | Make 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.
What comes along
Section titled “What comes along”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.
What each item gets
Section titled “What each item gets”- 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
Section titled “The values file”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-pushcloud_url = "https://zk.example.com"| Table | Fields | Needed for a new item |
|---|---|---|
[listeners.ID] | listen, broker, username, password_env, allow_from, deny_from, proxy_protocol | listen (http) or broker (mqtt); username and password_env when FROM’s listener has them |
[sinks.ID] | url, secret_env | url; secret_env when FROM’s sink has a secret |
[endpoints.ID] | allow_from, deny_from | none: without them a new endpoint lets in every address its listener does |
[vars] | NAME = "value"; [vars.PACKAGE] for a package’s vars | none: 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: listenMake the change
Section titled “Make the change”-
Print the plan:
Terminal window hourctl promote test production --all --values production-values.tomlpromote 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: createvar cloud_url: setvar 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_daysSecrets, device registrations, people and sync data are never promoted.Nothing was changed. Run it again with --yes to make these changes on production. -
Make it:
Terminal window hourctl promote test production --all --values production-values.toml --yeshourctlnames 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_keyerror: 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.
JSON output
Section titled “JSON output”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 | |
|---|---|
kind | package, policy package, shared package, adoption, listener, sink, sync group, endpoint, var or settings |
id | the line, id or var (PACKAGE/NAME for a package’s var); null for the settings |
action | push 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) |
fields | the fields created or changed, by name; never their values |
kept | the fields that stay as TO has them |
needed_by | the item that brought it into the plan; null when it was chosen |
from_values | for create: the fields taken from the values file |
hash | for a package, policy package or shared package line: the content hash of the bundle promoted |
version | for adopt: the shared package version adopted |
Promote from CI
Section titled “Promote from CI”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.
hourctl cluster add test https://test-gw.example.com:9090 --token-env HOURADVANTAGE_TEST_TOKENhourctl 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=0hourctl 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 --yeshourctl cluster add test https://test-gw.example.com:9090 --token-env HOURADVANTAGE_TEST_TOKENhourctl cluster add production https://gw.example.com:9090 --token-env HOURADVANTAGE_PROD_TOKEN
hourctl diff test production --json > drift.jsonswitch ($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 --yesif ($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.