Skip to content

Commit

Permalink
config: add native service discovery admin boolean parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasell committed Mar 4, 2022
1 parent 5e1e85c commit 9bab962
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
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

// NativeServiceDiscovery determines whether the Nomad native service
// discovery client functionality is enabled.
NativeServiceDiscovery 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.NativeServiceDiscovery != nil {
conf.NativeServiceDiscovery = *agentConfig.Client.NativeServiceDiscovery
}

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.NativeServiceDiscovery)
conf.Client.NativeServiceDiscovery = helper.BoolToPtr(false)
c, err = a.clientConfig()
require.NoError(t, err)
require.False(t, c.NativeServiceDiscovery)
}

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"`

// NativeServiceDiscovery 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.
NativeServiceDiscovery *bool `hcl:"native_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.NativeServiceDiscovery = 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",
NativeServiceDiscovery: 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.NativeServiceDiscovery != nil {
result.NativeServiceDiscovery = b.NativeServiceDiscovery
}

return &result
}

Expand Down
10 changes: 6 additions & 4 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",
},
NativeServiceDiscovery: helper.BoolToPtr(false),
},
Server: &ServerConfig{
Enabled: false,
Expand Down Expand Up @@ -310,10 +311,11 @@ func TestConfig_Merge(t *testing.T) {
DiskMB: 15,
ReservedPorts: "2,10-30,55",
},
GCInterval: 6 * time.Second,
GCParallelDestroys: 6,
GCDiskUsageThreshold: 71,
GCInodeUsageThreshold: 86,
GCInterval: 6 * time.Second,
GCParallelDestroys: 6,
GCDiskUsageThreshold: 71,
GCInodeUsageThreshold: 86,
NativeServiceDiscovery: helper.BoolToPtr(false),
},
Server: &ServerConfig{
Enabled: true,
Expand Down

0 comments on commit 9bab962

Please sign in to comment.