From 53dbc4f1271910c12f7484626abf5175512d962a Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Thu, 2 Nov 2017 11:27:21 -0700 Subject: [PATCH 1/2] remove atlas --- client/config/config.go | 1 - command/agent/command.go | 90 +------------------- command/agent/config-test-fixtures/basic.hcl | 6 -- command/agent/config.go | 49 ----------- command/agent/config_parse.go | 42 --------- command/agent/config_parse_test.go | 6 -- command/agent/config_test.go | 13 --- command/agent/http.go | 28 ------ 8 files changed, 1 insertion(+), 234 deletions(-) diff --git a/client/config/config.go b/client/config/config.go index 39d50507c6a..eebe68723e2 100644 --- a/client/config/config.go +++ b/client/config/config.go @@ -21,7 +21,6 @@ var ( DefaultEnvBlacklist = strings.Join([]string{ "CONSUL_TOKEN", "VAULT_TOKEN", - "ATLAS_TOKEN", "AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN", "GOOGLE_APPLICATION_CREDENTIALS", }, ",") diff --git a/command/agent/command.go b/command/agent/command.go index d72b746126e..902d1cbec76 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -27,7 +27,6 @@ import ( "github.com/hashicorp/nomad/helper/gated-writer" "github.com/hashicorp/nomad/nomad/structs/config" "github.com/hashicorp/nomad/version" - "github.com/hashicorp/scada-client/scada" "github.com/mitchellh/cli" "github.com/posener/complete" ) @@ -50,9 +49,6 @@ type Command struct { logFilter *logutils.LevelFilter logOutput io.Writer retryJoinErrCh chan struct{} - - scadaProvider *scada.Provider - scadaHttp *HTTPServer } func (c *Command) readConfig() *Config { @@ -63,7 +59,6 @@ func (c *Command) readConfig() *Config { // Make a new, empty config. cmdConfig := &Config{ - Atlas: &AtlasConfig{}, Client: &ClientConfig{}, Consul: &config.ConsulConfig{}, Ports: &Ports{}, @@ -107,11 +102,6 @@ func (c *Command) readConfig() *Config { flags.StringVar(&cmdConfig.LogLevel, "log-level", "", "") flags.StringVar(&cmdConfig.NodeName, "node", "", "") - // Atlas options - flags.StringVar(&cmdConfig.Atlas.Infrastructure, "atlas", "", "") - flags.BoolVar(&cmdConfig.Atlas.Join, "atlas-join", false, "") - flags.StringVar(&cmdConfig.Atlas.Token, "atlas-token", "", "") - // Consul options flags.StringVar(&cmdConfig.Consul.Auth, "consul-auth", "", "") flags.Var((flaghelper.FuncBoolVar)(func(b bool) error { @@ -224,9 +214,6 @@ func (c *Command) readConfig() *Config { } // Ensure the sub-structs at least exist - if config.Atlas == nil { - config.Atlas = &AtlasConfig{} - } if config.Client == nil { config.Client = &ClientConfig{} } @@ -380,13 +367,6 @@ func (c *Command) setupAgent(config *Config, logOutput io.Writer, inmem *metrics } c.agent = agent - // Enable the SCADA integration - if err := c.setupSCADA(config); err != nil { - agent.Shutdown() - c.Ui.Error(fmt.Sprintf("Error starting SCADA: %s", err)) - return err - } - // Setup the HTTP server http, err := NewHTTPServer(agent, config) if err != nil { @@ -497,17 +477,11 @@ func (c *Command) Run(args []string) int { } defer c.agent.Shutdown() - // Check and shut down the SCADA listeners at the end + // Shudown the HTTP server at the end defer func() { if c.httpServer != nil { c.httpServer.Shutdown() } - if c.scadaHttp != nil { - c.scadaHttp.Shutdown() - } - if c.scadaProvider != nil { - c.scadaProvider.Shutdown() - } }() // Join startup nodes if specified @@ -767,52 +741,6 @@ func (c *Command) setupTelemetry(config *Config) (*metrics.InmemSink, error) { return inm, nil } -// setupSCADA is used to start a new SCADA provider and listener, -// replacing any existing listeners. -func (c *Command) setupSCADA(config *Config) error { - // Shut down existing SCADA listeners - if c.scadaProvider != nil { - c.scadaProvider.Shutdown() - } - if c.scadaHttp != nil { - c.scadaHttp.Shutdown() - } - - // No-op if we don't have an infrastructure - if config.Atlas == nil || config.Atlas.Infrastructure == "" { - return nil - } - - // Create the new provider and listener - c.Ui.Output("Connecting to Atlas: " + config.Atlas.Infrastructure) - - scadaConfig := &scada.Config{ - Service: "nomad", - Version: config.Version.VersionNumber(), - ResourceType: "nomad-cluster", - Meta: map[string]string{ - "auto-join": strconv.FormatBool(config.Atlas.Join), - "region": config.Region, - "datacenter": config.Datacenter, - "client": strconv.FormatBool(config.Client != nil && config.Client.Enabled), - "server": strconv.FormatBool(config.Server != nil && config.Server.Enabled), - }, - Atlas: scada.AtlasConfig{ - Endpoint: config.Atlas.Endpoint, - Infrastructure: config.Atlas.Infrastructure, - Token: config.Atlas.Token, - }, - } - - provider, list, err := scada.NewHTTPProvider(scadaConfig, c.logOutput) - if err != nil { - return err - } - c.scadaProvider = provider - c.scadaHttp = newScadaHttp(c.agent, list) - return nil -} - func (c *Command) startupJoin(config *Config) error { if len(config.Server.StartJoin) == 0 || !config.Server.Enabled { return nil @@ -1100,22 +1028,6 @@ Vault Options: -vault-tls-server-name= Used to set the SNI host when connecting over TLS. - -Atlas Options: - - -atlas= - The Atlas infrastructure name to configure. This enables the SCADA - client and attempts to connect Nomad to the HashiCorp Atlas service - using the provided infrastructure name and token. - - -atlas-token= - The Atlas token to use when connecting to the HashiCorp Atlas - service. This must be provided to successfully connect your Nomad - agent to Atlas. - - -atlas-join - Enable the Atlas join feature. This mode allows agents to discover - eachother automatically using the SCADA integration features. ` return strings.TrimSpace(helpText) } diff --git a/command/agent/config-test-fixtures/basic.hcl b/command/agent/config-test-fixtures/basic.hcl index a96a1e431b9..666bdb04a0e 100644 --- a/command/agent/config-test-fixtures/basic.hcl +++ b/command/agent/config-test-fixtures/basic.hcl @@ -106,12 +106,6 @@ enable_syslog = true syslog_facility = "LOCAL1" disable_update_check = true disable_anonymous_signature = true -atlas { - infrastructure = "armon/test" - token = "abcd" - join = true - endpoint = "127.0.0.1:1234" -} http_api_response_headers { Access-Control-Allow-Origin = "*" } diff --git a/command/agent/config.go b/command/agent/config.go index ad514b58942..5a65df2e321 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -94,9 +94,6 @@ type Config struct { // for security bulletins DisableAnonymousSignature bool `mapstructure:"disable_anonymous_signature"` - // AtlasConfig is used to configure Atlas - Atlas *AtlasConfig `mapstructure:"atlas"` - // Consul contains the configuration for the Consul Agent and // parameters necessary to register services, their checks, and // discover the current Nomad servers. @@ -135,24 +132,6 @@ type Config struct { Sentinel *config.SentinelConfig `mapstructure:"sentinel"` } -// AtlasConfig is used to enable an parameterize the Atlas integration -type AtlasConfig struct { - // Infrastructure is the name of the infrastructure - // we belong to. e.g. hashicorp/stage - Infrastructure string `mapstructure:"infrastructure"` - - // Token is our authentication token from Atlas - Token string `mapstructure:"token" json:"-"` - - // Join controls if Atlas will attempt to auto-join the node - // to it's cluster. Requires Atlas integration. - Join bool `mapstructure:"join"` - - // Endpoint is the SCADA endpoint used for Atlas integration. If - // empty, the defaults from the provider are used. - Endpoint string `mapstructure:"endpoint"` -} - // ClientConfig is configuration specific to the client mode type ClientConfig struct { // Enabled controls if we are a client @@ -584,7 +563,6 @@ func DefaultConfig() *Config { }, Addresses: &Addresses{}, AdvertiseAddrs: &AdvertiseAddrs{}, - Atlas: &AtlasConfig{}, Consul: config.DefaultConsulConfig(), Vault: config.DefaultVaultConfig(), Client: &ClientConfig{ @@ -756,14 +734,6 @@ func (c *Config) Merge(b *Config) *Config { result.AdvertiseAddrs = result.AdvertiseAddrs.Merge(b.AdvertiseAddrs) } - // Apply the Atlas configuration - if result.Atlas == nil && b.Atlas != nil { - atlasConfig := *b.Atlas - result.Atlas = &atlasConfig - } else if b.Atlas != nil { - result.Atlas = result.Atlas.Merge(b.Atlas) - } - // Apply the Consul Configuration if result.Consul == nil && b.Consul != nil { result.Consul = b.Consul.Copy() @@ -1282,25 +1252,6 @@ func (a *AdvertiseAddrs) Merge(b *AdvertiseAddrs) *AdvertiseAddrs { return &result } -// Merge merges two Atlas configurations together. -func (a *AtlasConfig) Merge(b *AtlasConfig) *AtlasConfig { - result := *a - - if b.Infrastructure != "" { - result.Infrastructure = b.Infrastructure - } - if b.Token != "" { - result.Token = b.Token - } - if b.Join { - result.Join = true - } - if b.Endpoint != "" { - result.Endpoint = b.Endpoint - } - return &result -} - func (r *Resources) Merge(b *Resources) *Resources { result := *r if b.CPU != 0 { diff --git a/command/agent/config_parse.go b/command/agent/config_parse.go index 3f42b2ae507..3b4c5a5d889 100644 --- a/command/agent/config_parse.go +++ b/command/agent/config_parse.go @@ -92,7 +92,6 @@ func parseConfig(result *Config, list *ast.ObjectList) error { "syslog_facility", "disable_update_check", "disable_anonymous_signature", - "atlas", "consul", "vault", "tls", @@ -116,7 +115,6 @@ func parseConfig(result *Config, list *ast.ObjectList) error { delete(m, "client") delete(m, "server") delete(m, "telemetry") - delete(m, "atlas") delete(m, "consul") delete(m, "vault") delete(m, "tls") @@ -178,13 +176,6 @@ func parseConfig(result *Config, list *ast.ObjectList) error { } } - // Parse atlas config - if o := list.Filter("atlas"); len(o.Items) > 0 { - if err := parseAtlas(&result.Atlas, o); err != nil { - return multierror.Prefix(err, "atlas ->") - } - } - // Parse the consul config if o := list.Filter("consul"); len(o.Items) > 0 { if err := parseConsulConfig(&result.Consul, o); err != nil { @@ -671,39 +662,6 @@ func parseTelemetry(result **Telemetry, list *ast.ObjectList) error { return nil } -func parseAtlas(result **AtlasConfig, list *ast.ObjectList) error { - list = list.Elem() - if len(list.Items) > 1 { - return fmt.Errorf("only one 'atlas' block allowed") - } - - // Get our atlas object - listVal := list.Items[0].Val - - // Check for invalid keys - valid := []string{ - "infrastructure", - "token", - "join", - "endpoint", - } - if err := helper.CheckHCLKeys(listVal, valid); err != nil { - return err - } - - var m map[string]interface{} - if err := hcl.DecodeObject(&m, listVal); err != nil { - return err - } - - var atlas AtlasConfig - if err := mapstructure.WeakDecode(m, &atlas); err != nil { - return err - } - *result = &atlas - return nil -} - func parseConsulConfig(result **config.ConsulConfig, list *ast.ObjectList) error { list = list.Elem() if len(list.Items) > 1 { diff --git a/command/agent/config_parse_test.go b/command/agent/config_parse_test.go index 1a824f93a74..9a8ef7bb610 100644 --- a/command/agent/config_parse_test.go +++ b/command/agent/config_parse_test.go @@ -129,12 +129,6 @@ func TestConfig_Parse(t *testing.T) { SyslogFacility: "LOCAL1", DisableUpdateCheck: true, DisableAnonymousSignature: true, - Atlas: &AtlasConfig{ - Infrastructure: "armon/test", - Token: "abcd", - Join: true, - Endpoint: "127.0.0.1:1234", - }, Consul: &config.ConsulConfig{ ServerServiceName: "nomad", ClientServiceName: "nomad-client", diff --git a/command/agent/config_test.go b/command/agent/config_test.go index ef4aba993a6..0324be6fdaa 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -30,7 +30,6 @@ func TestConfig_Merge(t *testing.T) { Ports: &Ports{}, Addresses: &Addresses{}, AdvertiseAddrs: &AdvertiseAddrs{}, - Atlas: &AtlasConfig{}, Vault: &config.VaultConfig{}, Consul: &config.ConsulConfig{}, Sentinel: &config.SentinelConfig{}, @@ -125,12 +124,6 @@ func TestConfig_Merge(t *testing.T) { RPC: "127.0.0.1", Serf: "127.0.0.1", }, - Atlas: &AtlasConfig{ - Infrastructure: "hashicorp/test1", - Token: "abc", - Join: false, - Endpoint: "foo", - }, HTTPAPIResponseHeaders: map[string]string{ "Access-Control-Allow-Origin": "*", }, @@ -273,12 +266,6 @@ func TestConfig_Merge(t *testing.T) { RPC: "127.0.0.2", Serf: "127.0.0.2", }, - Atlas: &AtlasConfig{ - Infrastructure: "hashicorp/test2", - Token: "xyz", - Join: true, - Endpoint: "bar", - }, HTTPAPIResponseHeaders: map[string]string{ "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "GET, POST, OPTIONS", diff --git a/command/agent/http.go b/command/agent/http.go index 84472c67498..7eda840d1c3 100644 --- a/command/agent/http.go +++ b/command/agent/http.go @@ -25,12 +25,6 @@ const ( // ErrInvalidMethod is used if the HTTP method is not supported ErrInvalidMethod = "Invalid method" - // scadaHTTPAddr is the address associated with the - // HTTPServer. When populating an ACL token for a request, - // this is checked to switch between the ACLToken and - // AtlasACLToken - scadaHTTPAddr = "SCADA" - // ErrEntOnly is the error returned if accessing an enterprise only // endpoint ErrEntOnly = "Nomad Enterprise only endpoint" @@ -113,28 +107,6 @@ func NewHTTPServer(agent *Agent, config *Config) (*HTTPServer, error) { return srv, nil } -// newScadaHttp creates a new HTTP server wrapping the SCADA -// listener such that HTTP calls can be sent from the brokers. -func newScadaHttp(agent *Agent, list net.Listener) *HTTPServer { - // Create the mux - mux := http.NewServeMux() - - // Create the server - srv := &HTTPServer{ - agent: agent, - mux: mux, - listener: list, - logger: agent.logger, - Addr: scadaHTTPAddr, - } - srv.registerHandlers(false) // Never allow debug for SCADA - - // Handle requests with gzip compression - go http.Serve(list, gziphandler.GzipHandler(mux)) - - return srv -} - // tcpKeepAliveListener sets TCP keep-alive timeouts on accepted // connections. It's used by NewHttpServer so // dead TCP connections eventually go away. From 0d3a476c7b6a8639462972de30ed33c6e516c9ef Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Thu, 2 Nov 2017 13:38:50 -0700 Subject: [PATCH 2/2] deprecation notice --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dce8cf2c5f..bcf8b485aee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## 0.7.1 (Unreleased) +__BACKWARDS INCOMPATIBILITIES:__ + * config: Nomad no longer parses Atlas configuration stanzas. Atlas has been + deprecated since earlier this year. If you have an Atlas stanza in your + config file it will have to be removed. + IMPROVEMENTS: * api: Allocations now track and return modify time in addition to create time. * cli: Allocation create and modify times are displayed in a human readable relative format like `6 h ago`.