func (a *Agent) clientConfig() (*clientconfig.Config, error) {
	// Setup the configuration
	conf := a.config.ClientConfig
	if conf == nil {
		conf = clientconfig.DefaultConfig()
	}
	if a.server != nil {
		conf.RPCHandler = a.server
	}
	conf.LogOutput = a.logOutput
	conf.LogLevel = a.config.LogLevel
	conf.DevMode = a.config.DevMode
	if a.config.Region != "" {
		conf.Region = a.config.Region
	}
	if a.config.DataDir != "" {
		conf.StateDir = filepath.Join(a.config.DataDir, "client")
		conf.AllocDir = filepath.Join(a.config.DataDir, "alloc")
	}
	if a.config.Client.StateDir != "" {
		conf.StateDir = a.config.Client.StateDir
	}
	if a.config.Client.AllocDir != "" {
		conf.AllocDir = a.config.Client.AllocDir
	}
	conf.Servers = a.config.Client.Servers
	if a.config.Client.NetworkInterface != "" {
		conf.NetworkInterface = a.config.Client.NetworkInterface
	}
	conf.ChrootEnv = a.config.Client.ChrootEnv
	conf.Options = a.config.Client.Options
	// Logging deprecation messages about consul related configuration in client
	// options
	var invalidConsulKeys []string
	for key := range conf.Options {
		if strings.HasPrefix(key, "consul") {
			invalidConsulKeys = append(invalidConsulKeys, fmt.Sprintf("options.%s", key))
		}
	}
	if len(invalidConsulKeys) > 0 {
		a.logger.Printf("[WARN] agent: Invalid keys: %v", strings.Join(invalidConsulKeys, ","))
		a.logger.Printf(`Nomad client ignores consul related configuration in client options.
		Please refer to the guide https://www.nomadproject.io/docs/agent/configuration/consul.html
		to configure Nomad to work with Consul.`)
	}

	if a.config.Client.NetworkSpeed != 0 {
		conf.NetworkSpeed = a.config.Client.NetworkSpeed
	}
	if a.config.Client.CpuCompute != 0 {
		conf.CpuCompute = a.config.Client.CpuCompute
	}
	if a.config.Client.MaxKillTimeout != "" {
		dur, err := time.ParseDuration(a.config.Client.MaxKillTimeout)
		if err != nil {
			return nil, fmt.Errorf("Error parsing max kill timeout: %s", err)
		}
		conf.MaxKillTimeout = dur
	}
	conf.ClientMaxPort = uint(a.config.Client.ClientMaxPort)
	conf.ClientMinPort = uint(a.config.Client.ClientMinPort)

	// Setup the node
	conf.Node = new(structs.Node)
	conf.Node.Datacenter = a.config.Datacenter
	conf.Node.Name = a.config.NodeName
	conf.Node.Meta = a.config.Client.Meta
	conf.Node.NodeClass = a.config.Client.NodeClass

	// Set up the HTTP advertise address
	conf.Node.HTTPAddr = a.config.AdvertiseAddrs.HTTP

	// Reserve resources on the node.
	r := conf.Node.Reserved
	if r == nil {
		r = new(structs.Resources)
		conf.Node.Reserved = r
	}
	r.CPU = a.config.Client.Reserved.CPU
	r.MemoryMB = a.config.Client.Reserved.MemoryMB
	r.DiskMB = a.config.Client.Reserved.DiskMB
	r.IOPS = a.config.Client.Reserved.IOPS
	conf.GloballyReservedPorts = a.config.Client.Reserved.ParsedReservedPorts

	conf.Version = fmt.Sprintf("%s%s", a.config.Version, a.config.VersionPrerelease)
	conf.Revision = a.config.Revision

	if *a.config.Consul.AutoAdvertise && a.config.Consul.ClientServiceName == "" {
		return nil, fmt.Errorf("client_service_name must be set when auto_advertise is enabled")
	}

	conf.ConsulConfig = a.config.Consul
	conf.VaultConfig = a.config.Vault
	conf.StatsCollectionInterval = a.config.Telemetry.collectionInterval
	conf.PublishNodeMetrics = a.config.Telemetry.PublishNodeMetrics
	conf.PublishAllocationMetrics = a.config.Telemetry.PublishAllocationMetrics

	// Set the TLS related configs
	conf.TLSConfig = a.config.TLSConfig
	conf.Node.TLSEnabled = conf.TLSConfig.EnableHTTP

	// Set the GC related configs
	conf.GCInterval = a.config.Client.GCInterval
	conf.GCParallelDestroys = a.config.Client.GCParallelDestroys
	conf.GCDiskUsageThreshold = a.config.Client.GCDiskUsageThreshold
	conf.GCInodeUsageThreshold = a.config.Client.GCInodeUsageThreshold
	conf.GCMaxAllocs = a.config.Client.GCMaxAllocs
	if a.config.Client.NoHostUUID != nil {
		conf.NoHostUUID = *a.config.Client.NoHostUUID
	} else {
		// Default no_host_uuid to true
		conf.NoHostUUID = true
	}

	return conf, nil
}
// clientConfig is used to generate a new client configuration struct
// for initializing a Nomad client.
clientConfig is used to generate a new client configuration struct
for initializing a Nomad client.
// clientConfig is used to generate a new client configuration struct // for initializing a Nomad client .
func (a *Agent) clientConfig() (*clientconfig.Config, error) {
	conf := a.config.ClientConfig
	if conf == nil {
		conf = clientconfig.DefaultConfig()
	}
	if a.server != nil {
		conf.RPCHandler = a.server
	}
	conf.LogOutput = a.logOutput
	conf.LogLevel = a.config.LogLevel
	conf.DevMode = a.config.DevMode
	if a.config.Region != "" {
		conf.Region = a.config.Region
	}
	if a.config.DataDir != "" {
		conf.StateDir = filepath.Join(a.config.DataDir, "client")
		conf.AllocDir = filepath.Join(a.config.DataDir, "alloc")
	}
	if a.config.Client.StateDir != "" {
		conf.StateDir = a.config.Client.StateDir
	}
	if a.config.Client.AllocDir != "" {
		conf.AllocDir = a.config.Client.AllocDir
	}
	conf.Servers = a.config.Client.Servers
	if a.config.Client.NetworkInterface != "" {
		conf.NetworkInterface = a.config.Client.NetworkInterface
	}
	conf.ChrootEnv = a.config.Client.ChrootEnv
	conf.Options = a.config.Client.Options
	var invalidConsulKeys []string
	for key := range conf.Options {
		if strings.HasPrefix(key, "consul") {
			invalidConsulKeys = append(invalidConsulKeys, fmt.Sprintf("options.%s", key))
		}
	}
	if len(invalidConsulKeys) > 0 {
		a.logger.Printf("[WARN] agent: Invalid keys: %v", strings.Join(invalidConsulKeys, ","))
		a.logger.Printf(`Nomad client ignores consul related configuration in client options.
		Please refer to the guide https://www.nomadproject.io/docs/agent/configuration/consul.html
		to configure Nomad to work with Consul.`)
	}
	if a.config.Client.NetworkSpeed != 0 {
		conf.NetworkSpeed = a.config.Client.NetworkSpeed
	}
	if a.config.Client.CpuCompute != 0 {
		conf.CpuCompute = a.config.Client.CpuCompute
	}
	if a.config.Client.MaxKillTimeout != "" {
		dur, err := time.ParseDuration(a.config.Client.MaxKillTimeout)
		if err != nil {
			return nil, fmt.Errorf("Error parsing max kill timeout: %s", err)
		}
		conf.MaxKillTimeout = dur
	}
	conf.ClientMaxPort = uint(a.config.Client.ClientMaxPort)
	conf.ClientMinPort = uint(a.config.Client.ClientMinPort)
	conf.Node = new(structs.Node)
	conf.Node.Datacenter = a.config.Datacenter
	conf.Node.Name = a.config.NodeName
	conf.Node.Meta = a.config.Client.Meta
	conf.Node.NodeClass = a.config.Client.NodeClass
	conf.Node.HTTPAddr = a.config.AdvertiseAddrs.HTTP
	r := conf.Node.Reserved
	if r == nil {
		r = new(structs.Resources)
		conf.Node.Reserved = r
	}
	r.CPU = a.config.Client.Reserved.CPU
	r.MemoryMB = a.config.Client.Reserved.MemoryMB
	r.DiskMB = a.config.Client.Reserved.DiskMB
	r.IOPS = a.config.Client.Reserved.IOPS
	conf.GloballyReservedPorts = a.config.Client.Reserved.ParsedReservedPorts
	conf.Version = fmt.Sprintf("%s%s", a.config.Version, a.config.VersionPrerelease)
	conf.Revision = a.config.Revision
	if *a.config.Consul.AutoAdvertise && a.config.Consul.ClientServiceName == "" {
		return nil, fmt.Errorf("client_service_name must be set when auto_advertise is enabled")
	}
	conf.ConsulConfig = a.config.Consul
	conf.VaultConfig = a.config.Vault
	conf.StatsCollectionInterval = a.config.Telemetry.collectionInterval
	conf.PublishNodeMetrics = a.config.Telemetry.PublishNodeMetrics
	conf.PublishAllocationMetrics = a.config.Telemetry.PublishAllocationMetrics
	conf.TLSConfig = a.config.TLSConfig
	conf.Node.TLSEnabled = conf.TLSConfig.EnableHTTP
	conf.GCInterval = a.config.Client.GCInterval
	conf.GCParallelDestroys = a.config.Client.GCParallelDestroys
	conf.GCDiskUsageThreshold = a.config.Client.GCDiskUsageThreshold
	conf.GCInodeUsageThreshold = a.config.Client.GCInodeUsageThreshold
	conf.GCMaxAllocs = a.config.Client.GCMaxAllocs
	if a.config.Client.NoHostUUID != nil {
		conf.NoHostUUID = *a.config.Client.NoHostUUID
	} else {
		conf.NoHostUUID = true
	}
	return conf, nil
}
func ( a * Agent ) clientConfig ( ) ( * clientconfig . Config , error ) { conf := a . config . ClientConfig if conf == nil { conf = clientconfig . DefaultConfig ( ) } if a . server != nil { conf . RPCHandler = a . server } conf . LogOutput = a . logOutput conf . LogLevel = a . config . LogLevel conf . DevMode = a . config . DevMode if a . config . Region != " " { conf . Region = a . config . Region } if a . config . DataDir != " " { conf . StateDir = filepath . Join ( a . config . DataDir , " " ) conf . AllocDir = filepath . Join ( a . config . DataDir , " " ) } if a . config . Client . StateDir != " " { conf . StateDir = a . config . Client . StateDir } if a . config . Client . AllocDir != " " { conf . AllocDir = a . config . Client . AllocDir } conf . Servers = a . config . Client . Servers if a . config . Client . NetworkInterface != " " { conf . NetworkInterface = a . config . Client . NetworkInterface } conf . ChrootEnv = a . config . Client . ChrootEnv conf . Options = a . config . Client . Options var invalidConsulKeys [ ] string for key := range conf . Options { if strings . HasPrefix ( key , " " ) { invalidConsulKeys = append ( invalidConsulKeys , fmt . Sprintf ( " " , key ) ) } } if len ( invalidConsulKeys ) > 0 { a . logger . Printf ( " " , strings . Join ( invalidConsulKeys , " " ) ) a . logger . Printf ( `Nomad client ignores consul related configuration in client options.
		Please refer to the guide https://www.nomadproject.io/docs/agent/configuration/consul.html
		to configure Nomad to work with Consul.` ) } if a . config . Client . NetworkSpeed != 0 { conf . NetworkSpeed = a . config . Client . NetworkSpeed } if a . config . Client . CpuCompute != 0 { conf . CpuCompute = a . config . Client . CpuCompute } if a . config . Client . MaxKillTimeout != " " { dur , err := time . ParseDuration ( a . config . Client . MaxKillTimeout ) if err != nil { return nil , fmt . Errorf ( " " , err ) } conf . MaxKillTimeout = dur } conf . ClientMaxPort = uint ( a . config . Client . ClientMaxPort ) conf . ClientMinPort = uint ( a . config . Client . ClientMinPort ) conf . Node = new ( structs . Node ) conf . Node . Datacenter = a . config . Datacenter conf . Node . Name = a . config . NodeName conf . Node . Meta = a . config . Client . Meta conf . Node . NodeClass = a . config . Client . NodeClass conf . Node . HTTPAddr = a . config . AdvertiseAddrs . HTTP r := conf . Node . Reserved if r == nil { r = new ( structs . Resources ) conf . Node . Reserved = r } r . CPU = a . config . Client . Reserved . CPU r . MemoryMB = a . config . Client . Reserved . MemoryMB r . DiskMB = a . config . Client . Reserved . DiskMB r . IOPS = a . config . Client . Reserved . IOPS conf . GloballyReservedPorts = a . config . Client . Reserved . ParsedReservedPorts conf . Version = fmt . Sprintf ( " " , a . config . Version , a . config . VersionPrerelease ) conf . Revision = a . config . Revision if * a . config . Consul . AutoAdvertise && a . config . Consul . ClientServiceName == " " { return nil , fmt . Errorf ( " " ) } conf . ConsulConfig = a . config . Consul conf . VaultConfig = a . config . Vault conf . StatsCollectionInterval = a . config . Telemetry . collectionInterval conf . PublishNodeMetrics = a . config . Telemetry . PublishNodeMetrics conf . PublishAllocationMetrics = a . config . Telemetry . PublishAllocationMetrics conf . TLSConfig = a . config . TLSConfig conf . Node . TLSEnabled = conf . TLSConfig . EnableHTTP conf . GCInterval = a . config . Client . GCInterval conf . GCParallelDestroys = a . config . Client . GCParallelDestroys conf . GCDiskUsageThreshold = a . config . Client . GCDiskUsageThreshold conf . GCInodeUsageThreshold = a . config . Client . GCInodeUsageThreshold conf . GCMaxAllocs = a . config . Client . GCMaxAllocs if a . config . Client . NoHostUUID != nil { conf . NoHostUUID = * a . config . Client . NoHostUUID } else { conf . NoHostUUID = true } return conf , nil }
clientConfig is used to generate a new client configuration struct
for initializing a Nomad client.
clientConfig is used to generate a new client configuration struct for initializing a Nomad client .
// Setup the configuration // Logging deprecation messages about consul related configuration in client // options // Setup the node // Set up the HTTP advertise address // Reserve resources on the node. // Set the TLS related configs // Set the GC related configs // Default no_host_uuid to true