mirror of
https://github.com/skoelle/kctl-tui.git
synced 2026-09-18 04:20:25 +00:00
Add separate k8s_secret_name_template, since Kubernetes secret names follow a different pattern than AWS secret names
This commit is contained in:
@@ -41,6 +41,12 @@ type Config struct {
|
||||
// namespace and env, e.g. "tf-{namespace}-{env}-secrets".
|
||||
SecretNameTemplate string `yaml:"secret_name_template"`
|
||||
|
||||
// K8sSecretNameTemplate builds the Kubernetes secret name from a
|
||||
// namespace, e.g. "{namespace}-common-secrets". Kept separate from
|
||||
// SecretNameTemplate because the two sides commonly follow different
|
||||
// naming conventions.
|
||||
K8sSecretNameTemplate string `yaml:"k8s_secret_name_template"`
|
||||
|
||||
// ContextTemplate builds the actual kubectl context name/ARN from
|
||||
// region, account_id, env, and context, e.g.
|
||||
// "arn:aws:eks:{region}:{account_id}:cluster/tf-{env}-{context}-1".
|
||||
@@ -96,6 +102,22 @@ func (c Config) ResolveSecretName(namespace, env string) string {
|
||||
})
|
||||
}
|
||||
|
||||
// ResolveK8sSecretName builds the Kubernetes secret name for a given
|
||||
// namespace using K8sSecretNameTemplate. Falls back to
|
||||
// SecretNameTemplate resolved without an env placeholder if
|
||||
// K8sSecretNameTemplate is not configured, so existing configs keep
|
||||
// working, though setting it explicitly is recommended since the two
|
||||
// naming conventions usually differ.
|
||||
func (c Config) ResolveK8sSecretName(namespace string) string {
|
||||
template := c.K8sSecretNameTemplate
|
||||
if template == "" {
|
||||
template = c.SecretNameTemplate
|
||||
}
|
||||
return kctl.ResolveTemplate(template, map[string]string{
|
||||
"namespace": namespace,
|
||||
})
|
||||
}
|
||||
|
||||
// DefaultPath returns the default config file location: ~/.kctl-tui/config.yaml
|
||||
func DefaultPath() (string, error) {
|
||||
home, err := os.UserHomeDir()
|
||||
|
||||
Reference in New Issue
Block a user