Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 762bf6f9b8 | |||
| aa8b74dcf0 |
@@ -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:
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
+4
-7
@@ -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")
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user