mirror of
https://github.com/mulgadc/spinifex.git
synced 2026-10-20 11:21:49 +00:00
ac069d8f37
cmd/eks-token-webhook keeps the -addr flag, environment-derived config, logging setup and exits; agents/eks/tokenwebhook owns Config and Run. The handlers/eks TokenReview result type stays as recorded temporary debt.
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// The CP VM launches on an instance profile, so cloud-init omits the static
|
|
// EKS_ACCESS_KEY/EKS_SECRET_KEY and eksgw.New signs with IMDS creds. loadConfig
|
|
// must accept absent static keys; gating on them aborts every IMDS-mode boot,
|
|
// leaving the apiserver webhook kubeconfig unwritten.
|
|
func TestLoadConfig_AcceptsAbsentStaticCreds(t *testing.T) {
|
|
setEnv := func(t *testing.T, kv map[string]string) {
|
|
t.Helper()
|
|
for _, k := range []string{
|
|
"EKS_GATEWAY_URL", "EKS_ACCESS_KEY", "EKS_SECRET_KEY",
|
|
"EKS_ACCOUNT_ID", "EKS_CLUSTER_NAME",
|
|
} {
|
|
t.Setenv(k, "")
|
|
}
|
|
for k, v := range kv {
|
|
t.Setenv(k, v)
|
|
}
|
|
}
|
|
|
|
// IMDS mode: required vars set, static creds absent → accepted.
|
|
setEnv(t, map[string]string{
|
|
"EKS_GATEWAY_URL": "https://gw:9999",
|
|
"EKS_ACCOUNT_ID": "000000000001",
|
|
"EKS_CLUSTER_NAME": "toc",
|
|
})
|
|
cfg, err := loadConfig()
|
|
require.NoError(t, err)
|
|
assert.Empty(t, cfg.AccessKey)
|
|
assert.Empty(t, cfg.SecretKey)
|
|
|
|
// Genuinely-required vars are still enforced.
|
|
setEnv(t, map[string]string{
|
|
"EKS_ACCOUNT_ID": "000000000001",
|
|
"EKS_CLUSTER_NAME": "toc",
|
|
})
|
|
_, err = loadConfig()
|
|
require.Error(t, err)
|
|
}
|