Skip to content

Commit

Permalink
Merge pull request #3493 from hashicorp/f-remove-atlas
Browse files Browse the repository at this point in the history
Remove Atlas and Scada from codebase
  • Loading branch information
dadgar authored Nov 2, 2017
2 parents 4bca2cd + 0d3a476 commit 52598bf
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 234 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.[GH-3446]
* cli: Allocation create and modify times are displayed in a human readable
Expand Down
1 change: 0 additions & 1 deletion client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}, ",")
Expand Down
90 changes: 1 addition & 89 deletions command/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 {
Expand All @@ -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{},
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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{}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1100,22 +1028,6 @@ Vault Options:
-vault-tls-server-name=<token>
Used to set the SNI host when connecting over TLS.
Atlas Options:
-atlas=<infrastructure>
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=<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)
}
6 changes: 0 additions & 6 deletions command/agent/config-test-fixtures/basic.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "*"
}
Expand Down
49 changes: 0 additions & 49 deletions command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -584,7 +563,6 @@ func DefaultConfig() *Config {
},
Addresses: &Addresses{},
AdvertiseAddrs: &AdvertiseAddrs{},
Atlas: &AtlasConfig{},
Consul: config.DefaultConsulConfig(),
Vault: config.DefaultVaultConfig(),
Client: &ClientConfig{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down
42 changes: 0 additions & 42 deletions command/agent/config_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ func parseConfig(result *Config, list *ast.ObjectList) error {
"syslog_facility",
"disable_update_check",
"disable_anonymous_signature",
"atlas",
"consul",
"vault",
"tls",
Expand All @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 0 additions & 6 deletions command/agent/config_parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 0 additions & 13 deletions command/agent/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down Expand Up @@ -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": "*",
},
Expand Down Expand Up @@ -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",
Expand Down
Loading

0 comments on commit 52598bf

Please sign in to comment.