From aa8b74dcf044b6bea37ca65c84110bd11fef2ef3 Mon Sep 17 00:00:00 2001 From: unkin-agent Date: Mon, 9 Nov 2026 07:17:49 +1100 Subject: [PATCH] fix: drop legacy /etc/encapic/encapic.conf --- .goreleaser.yaml | 7 ------- README.md | 12 +++--------- config.go | 6 ++---- config_test.go | 11 ++++------- main.go | 2 +- packaging/encapic-enc | 8 +++----- packaging/encapic.conf | 4 ---- 7 files changed, 13 insertions(+), 37 deletions(-) delete mode 100644 packaging/encapic.conf diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 471e899..dabfc91 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -47,13 +47,6 @@ nfpms: dst: /usr/bin/encapic-enc file_info: mode: 0755 - # noreplace: puppet manages this file's contents (hiera-driven URL), so an - # upgrade must not overwrite it. - - src: packaging/encapic.conf - dst: /etc/encapic/encapic.conf - type: "config|noreplace" - file_info: - mode: 0644 - src: completions/encapic.bash dst: /usr/share/bash-completion/completions/encapic file_info: diff --git a/README.md b/README.md index 4d37a52..25980f1 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,7 @@ The encapi base URL comes from the first of: 1. the `ENCAPI_URL` environment variable; 2. `${XDG_CONFIG_HOME:-~/.config}/encapi/encapic.conf`; 3. `/etc/encapi/encapic.conf`; -4. `/etc/encapic/encapic.conf` (legacy, shipped by the RPM); -5. the compiled-in default `http://encapi.encapi.svc.cluster.local`. +4. the compiled-in default `http://encapi.encapi.svc.cluster.local`. Conf files are shell-sourceable `KEY=VALUE` (`ENCAPI_URL=https://...`). `encapic init` prompts for the URL (default @@ -148,11 +147,6 @@ It ships: - `/usr/bin/encapic` — the binary; - `/usr/bin/encapic-enc` — the ENC entrypoint. Puppet's exec `node_terminus` invokes `external_nodes` with a certname and no environment, so the shim - sources the URL before exec'ing the binary. Point `external_nodes` at this, - not at `/usr/bin/encapic`; -- `/etc/encapic/encapic.conf` — `ENCAPI_URL=...`, defaulting to the external - address `https://encapi.k8s.syd1.au.unkin.net` because a VM cannot resolve - the in-cluster default. Shipped `%config(noreplace)` so puppet may own its - contents without an upgrade reverting them. A `/etc/encapi/encapic.conf`, when - present, takes precedence in both the shim and the binary; + sources the puppet-managed `/etc/encapi/encapic.conf` before exec'ing the + binary. Point `external_nodes` at this, not at `/usr/bin/encapic`; - bash and zsh completion scripts. diff --git a/config.go b/config.go index 5b6d37c..0382e9a 100644 --- a/config.go +++ b/config.go @@ -13,9 +13,7 @@ import ( const initDefaultURL = "https://encapi.k8s.syd1.au.unkin.net" -// systemConfPaths follow the user conf in precedence; the legacy path is a -// read-only fallback for hosts whose puppet still manages it. -var systemConfPaths = []string{"/etc/encapi/encapic.conf", "/etc/encapic/encapic.conf"} +var systemConfPath = "/etc/encapi/encapic.conf" func xdgDir(env, fallback string) string { if d := os.Getenv(env); d != "" { @@ -42,7 +40,7 @@ func resolveBaseURL() (string, bool) { if u := os.Getenv("ENCAPI_URL"); u != "" { return u, true } - for _, p := range append([]string{userConfPath()}, systemConfPaths...) { + for _, p := range []string{userConfPath(), systemConfPath} { if u := readConfURL(p); u != "" { return u, true } diff --git a/config_test.go b/config_test.go index b943f7c..6b8583c 100644 --- a/config_test.go +++ b/config_test.go @@ -13,7 +13,7 @@ func TestMain(m *testing.M) { if err != nil { panic(err) } - systemConfPaths = nil + systemConfPath = "" _ = os.Unsetenv("ENCAPI_URL") _ = os.Setenv("XDG_CONFIG_HOME", filepath.Join(dir, "config")) _ = os.Setenv("XDG_DATA_HOME", filepath.Join(dir, "data")) @@ -37,10 +37,9 @@ func TestResolveBaseURLPrecedence(t *testing.T) { t.Setenv("XDG_CONFIG_HOME", filepath.Join(dir, "user")) user := filepath.Join(dir, "user", "encapi", "encapic.conf") system := filepath.Join(dir, "etc", "encapi", "encapic.conf") - legacy := filepath.Join(dir, "etc", "encapic", "encapic.conf") - old := systemConfPaths - systemConfPaths = []string{system, legacy} - t.Cleanup(func() { systemConfPaths = old }) + old := systemConfPath + systemConfPath = system + t.Cleanup(func() { systemConfPath = old }) check := func(want string, wantFound bool) { t.Helper() @@ -52,8 +51,6 @@ func TestResolveBaseURLPrecedence(t *testing.T) { t.Setenv("ENCAPI_URL", "") check(defaultBaseURL, false) - writeConf(t, legacy, "ENCAPI_URL=https://legacy\n") - check("https://legacy", true) writeConf(t, system, "# comment\nENCAPI_URL=\"https://system\"\n") check("https://system", true) writeConf(t, user, "OTHER=x\nexport ENCAPI_URL='https://user'\n") diff --git a/main.go b/main.go index 060fadd..bc93601 100644 --- a/main.go +++ b/main.go @@ -54,7 +54,7 @@ const usage = `usage: encapic -v | --version show the version ENCAPI_URL is read from the environment, then ~/.config/encapi/encapic.conf, -/etc/encapi/encapic.conf, /etc/encapic/encapic.conf, else the in-cluster default. +/etc/encapi/encapic.conf, else the in-cluster default. ` func main() { diff --git a/packaging/encapic-enc b/packaging/encapic-enc index 81e1b68..bffe747 100755 --- a/packaging/encapic-enc +++ b/packaging/encapic-enc @@ -3,11 +3,9 @@ # environment, so the encapi URL cannot be inherited; source it here instead. set -eu -for conf in /etc/encapic/encapic.conf /etc/encapi/encapic.conf; do - if [ -r "$conf" ]; then - . "$conf" - fi -done +if [ -r /etc/encapi/encapic.conf ]; then + . /etc/encapi/encapic.conf +fi if [ -n "${ENCAPI_URL:-}" ]; then export ENCAPI_URL fi diff --git a/packaging/encapic.conf b/packaging/encapic.conf deleted file mode 100644 index 1dd2ac7..0000000 --- a/packaging/encapic.conf +++ /dev/null @@ -1,4 +0,0 @@ -# Base URL of the encapi service, read by encapic and /usr/bin/encapic-enc. -# The binary's compiled-in default is the in-cluster address, which VM puppet -# masters cannot resolve. -ENCAPI_URL=https://encapi.k8s.syd1.au.unkin.net -- 2.47.3