Skip to content

feat: overrides config with environment variables#16

Merged
jwnx merged 2 commits intofly-apps:masterfrom
jwnx:jwnx/fix-increase-etcd-max-storage-to-5gib
Mar 2, 2026
Merged

feat: overrides config with environment variables#16
jwnx merged 2 commits intofly-apps:masterfrom
jwnx:jwnx/fix-increase-etcd-max-storage-to-5gib

Conversation

@jwnx
Copy link
Contributor

@jwnx jwnx commented Feb 10, 2026

This patch adds support for overriding selected config params with
environment variables. If unset, they are loaded with sane default
values.

Signed-off-by: Juliana Oliveira juliana@fly.io

This patch adds support for overriding selected config params with
environment variables. If unset, they are loaded with sane default
values.

Signed-off-by: Juliana Oliveira <juliana@fly.io>
@jwnx jwnx force-pushed the jwnx/fix-increase-etcd-max-storage-to-5gib branch from d306d8f to 61e6813 Compare February 10, 2026 23:26
@jwnx jwnx changed the title fix: increase etcd max storage to 5GiB feat: overrides config with environment variables Feb 10, 2026
@jwnx jwnx requested a review from jphenow February 10, 2026 23:27
Copy link

@jphenow jphenow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth adding a test or two but not a hill I'd die on - it's pretty straight-forward looking

cfg, err := loadConfig()
// NewConfig provides sane defaults for fields that may not be present in
// older config files. The config file will overlay on top of these defaults.
cfg, err := NewConfig()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notably NewConfig() calls SetAuthToken(), which looks to have side effects — it creates a certs/ directory and writes JWT key files to disk.

This runs every boot now instead of just on missing config - idk if we care about that it just is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running on every boot is not a problem, IMO. But I fixed the order a bit to make precedence clearer.
Now, reload will:

  1. fetch default values (no side effect)
  2. overlay config file (if present)
  3. overlay env vars (if present)
  4. finally, call SetAuthToken (always does it)

MaxWals: 10,
SnapshotCount: 10000, // Default
SnapshotCount: 10000, // Default
QuotaBackendBytes: 2147483648, // 2GiB
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe overkill but I wonder if we should have it match size of the available volume?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and prefer the value passed in via env or config or whatever

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I prefer the 2 * 1024 * 1024 * 1024, // 2GiB style but I don't care that much

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

return fallback
}
result = n
case bool:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to be unused - could remove maybe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed (I started with big plans for this function and then decided we should leave for some other time)

@@ -36,9 +37,10 @@ type Config struct {
AutoCompactionRetention string `yaml:"auto-compaction-retention"`
AuthToken string `yaml:"auth-token"`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth adding var handling for the aboves as well?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps separate PR if it matters. we have a more specific need right now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added for AutoCompactionMode and AutoCompactionRetention, they could prove useful (:

- Moves defaults to DefaultConfig
- Removes bool type from getEnvOrDefault
- Adds tests

Signed-off-by: Juliana Oliveira <juliana@fly.io>
@jwnx jwnx merged commit b6b2f93 into fly-apps:master Mar 2, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants