Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: add native service discovery admin boolean parameter. #12190

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ type Config struct {

// ReservableCores if set overrides the set of reservable cores reported in fingerprinting.
ReservableCores []uint16

// NomadServiceDiscovery determines whether the Nomad native service
// discovery client functionality is enabled.
NomadServiceDiscovery bool
}

// ClientTemplateConfig is configuration on the client specific to template
Expand Down
4 changes: 4 additions & 0 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,10 @@ func convertClientConfig(agentConfig *Config) (*clientconfig.Config, error) {
conf.ReservableCores = cores.ToSlice()
}

if agentConfig.Client.NomadServiceDiscovery != nil {
conf.NomadServiceDiscovery = *agentConfig.Client.NomadServiceDiscovery
}

return conf, nil
}

Expand Down
8 changes: 8 additions & 0 deletions command/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,14 @@ func TestAgent_ClientConfig(t *testing.T) {
if c.Node.HTTPAddr != expectedHttpAddr {
t.Fatalf("Expected http addr: %v, got: %v", expectedHttpAddr, c.Node.HTTPAddr)
}

// Test the default, and then custom setting of the client service
// discovery boolean.
require.True(t, c.NomadServiceDiscovery)
conf.Client.NomadServiceDiscovery = helper.BoolToPtr(false)
c, err = a.clientConfig()
require.NoError(t, err)
require.False(t, c.NomadServiceDiscovery)
}

func TestAgent_ClientConfig_ReservedCores(t *testing.T) {
Expand Down
15 changes: 15 additions & 0 deletions command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@ type ClientConfig struct {
// doest not exist Nomad will attempt to create it during startup. Defaults to '/nomad'
CgroupParent string `hcl:"cgroup_parent"`

// NomadServiceDiscovery is a boolean parameter which allows operators to
// enable/disable to Nomad native service discovery feature on the client.
// This parameter is exposed via the Nomad fingerprinter and used to ensure
// correct scheduling decisions on allocations which require this.
NomadServiceDiscovery *bool `hcl:"nomad_service_discovery"`

// ExtraKeysHCL is used by hcl to surface unexpected keys
ExtraKeysHCL []string `hcl:",unusedKeys" json:"-"`
}
Expand Down Expand Up @@ -915,6 +921,7 @@ func DevConfig(mode *devModeConfig) *Config {
DisableSandbox: false,
}
conf.Client.BindWildcardDefaultHostNetwork = true
conf.Client.NomadServiceDiscovery = helper.BoolToPtr(true)
conf.Telemetry.PrometheusMetrics = true
conf.Telemetry.PublishAllocationMetrics = true
conf.Telemetry.PublishNodeMetrics = true
Expand Down Expand Up @@ -966,6 +973,7 @@ func DefaultConfig() *Config {
BindWildcardDefaultHostNetwork: true,
CNIPath: "/opt/cni/bin",
CNIConfigDir: "/opt/cni/config",
NomadServiceDiscovery: helper.BoolToPtr(true),
},
Server: &ServerConfig{
Enabled: false,
Expand Down Expand Up @@ -1763,6 +1771,13 @@ func (a *ClientConfig) Merge(b *ClientConfig) *ClientConfig {
if b.BindWildcardDefaultHostNetwork {
result.BindWildcardDefaultHostNetwork = true
}

// This value is a pointer, therefore if it is not nil the user has
// supplied an override value.
if b.NomadServiceDiscovery != nil {
result.NomadServiceDiscovery = b.NomadServiceDiscovery
}

return &result
}

Expand Down
2 changes: 2 additions & 0 deletions command/agent/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func TestConfig_Merge(t *testing.T) {
DiskMB: 10,
ReservedPorts: "1,10-30,55",
},
NomadServiceDiscovery: helper.BoolToPtr(false),
},
Server: &ServerConfig{
Enabled: false,
Expand Down Expand Up @@ -314,6 +315,7 @@ func TestConfig_Merge(t *testing.T) {
GCParallelDestroys: 6,
GCDiskUsageThreshold: 71,
GCInodeUsageThreshold: 86,
NomadServiceDiscovery: helper.BoolToPtr(false),
},
Server: &ServerConfig{
Enabled: true,
Expand Down