From b8a3a1784624fd9ce6a4abdca50896cd560633f2 Mon Sep 17 00:00:00 2001 From: Jorge Marey Date: Wed, 7 Aug 2024 12:52:08 +0200 Subject: [PATCH] Change nomad Config to autoscaler config to use on plugins --- agent/plugins.go | 4 ++-- sdk/helper/nomad/config.go | 42 +++++++++++++++++--------------------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/agent/plugins.go b/agent/plugins.go index 8e2e58ab..fc4dc572 100644 --- a/agent/plugins.go +++ b/agent/plugins.go @@ -65,7 +65,7 @@ func (a *Agent) setupPluginConfig(cfg map[string]string) { // Nomad config from the agent. If we do not find it, opt-in by default. val, ok := cfg[plugins.ConfigKeyNomadConfigInherit] if !ok { - nomadHelper.MergeMapWithAgentConfig(cfg, a.nomadCfg) + nomadHelper.MergeMapWithAgentConfig(cfg, a.config.Nomad) return } @@ -79,7 +79,7 @@ func (a *Agent) setupPluginConfig(cfg map[string]string) { return } if boolVal { - nomadHelper.MergeMapWithAgentConfig(cfg, a.nomadCfg) + nomadHelper.MergeMapWithAgentConfig(cfg, a.config.Nomad) } } diff --git a/sdk/helper/nomad/config.go b/sdk/helper/nomad/config.go index 75578cc1..c0f14a2b 100644 --- a/sdk/helper/nomad/config.go +++ b/sdk/helper/nomad/config.go @@ -106,7 +106,7 @@ func HTTPAuthFromString(auth string) *api.HttpBasicAuth { // with the map config taking precedence. This allows users to override only a // subset of params, while inheriting the agent configured items which are also // derived from Nomad API default and env vars. -func MergeMapWithAgentConfig(m map[string]string, cfg *api.Config) { +func MergeMapWithAgentConfig(m map[string]string, cfg *config.Nomad) { if cfg == nil { return } @@ -120,36 +120,32 @@ func MergeMapWithAgentConfig(m map[string]string, cfg *api.Config) { if cfg.Namespace != "" && m[configKeyNomadNamespace] == "" { m[configKeyNomadNamespace] = cfg.Namespace } - if cfg.SecretID != "" && m[configKeyNomadToken] == "" { - m[configKeyNomadToken] = cfg.SecretID + if cfg.Token != "" && m[configKeyNomadToken] == "" { + m[configKeyNomadToken] = cfg.Token } - if cfg.TLSConfig.CACert != "" && m[configKeyNomadCACert] == "" { - m[configKeyNomadCACert] = cfg.TLSConfig.CACert + if cfg.CACert != "" && m[configKeyNomadCACert] == "" { + m[configKeyNomadCACert] = cfg.CACert } - if cfg.TLSConfig.CAPath != "" && m[configKeyNomadCAPath] == "" { - m[configKeyNomadCAPath] = cfg.TLSConfig.CAPath + if cfg.CAPath != "" && m[configKeyNomadCAPath] == "" { + m[configKeyNomadCAPath] = cfg.CAPath } - if cfg.TLSConfig.ClientCert != "" && m[configKeyNomadClientCert] == "" { - m[configKeyNomadClientCert] = cfg.TLSConfig.ClientCert + if cfg.ClientCert != "" && m[configKeyNomadClientCert] == "" { + m[configKeyNomadClientCert] = cfg.ClientCert } - if cfg.TLSConfig.ClientKey != "" && m[configKeyNomadClientKey] == "" { - m[configKeyNomadClientKey] = cfg.TLSConfig.ClientKey + if cfg.ClientKey != "" && m[configKeyNomadClientKey] == "" { + m[configKeyNomadClientKey] = cfg.ClientKey } - if cfg.TLSConfig.TLSServerName != "" && m[configKeyNomadTLSServerName] == "" { - m[configKeyNomadTLSServerName] = cfg.TLSConfig.TLSServerName + if cfg.TLSServerName != "" && m[configKeyNomadTLSServerName] == "" { + m[configKeyNomadTLSServerName] = cfg.TLSServerName } - if cfg.TLSConfig.Insecure && m[configKeyNomadSkipVerify] == "" { - m[configKeyNomadSkipVerify] = strconv.FormatBool(cfg.TLSConfig.Insecure) + if cfg.SkipVerify && m[configKeyNomadSkipVerify] == "" { + m[configKeyNomadSkipVerify] = strconv.FormatBool(cfg.SkipVerify) } - if cfg.HttpAuth != nil && m[configKeyNomadHTTPAuth] == "" { - auth := cfg.HttpAuth.Username - if cfg.HttpAuth.Password != "" { - auth += ":" + cfg.HttpAuth.Password - } - m[configKeyNomadHTTPAuth] = auth + if cfg.HTTPAuth != "" && m[configKeyNomadHTTPAuth] == "" { + m[configKeyNomadHTTPAuth] = cfg.HTTPAuth } - if cfg.WaitTime != 0 && m[configKeyNomadBlockQueryWaitTime] == "" { - m[configKeyNomadBlockQueryWaitTime] = cfg.WaitTime.String() + if cfg.BlockQueryWaitTime != 0 && m[configKeyNomadBlockQueryWaitTime] == "" { + m[configKeyNomadBlockQueryWaitTime] = cfg.BlockQueryWaitTime.String() } }