Repository: hashicorp/nomad
File: command/agent/agent.go (Go)

Code before:
		conf.HostVolumesDir = filepath.Join(agentConfig.DataDir, "host_volumes")
		conf.HostVolumePluginDir = filepath.Join(agentConfig.DataDir, "host_volume_plugins")
		dataParent := filepath.Dir(agentConfig.DataDir)
		conf.AllocMountsDir = filepath.Join(dataParent, "alloc_mounts")
	}
	if agentConfig.Client.StateDir != "" {
		conf.StateDir = agentConfig.Client.StateDir
	}
	if agentConfig.Client.AllocDir != "" {
		conf.AllocDir = agentConfig.Client.AllocDir
	}
	if agentConfig.Client.AllocMountsDir != "" {
		conf.AllocMountsDir = agentConfig.Client.AllocMountsDir
	}
	if agentConfig.Client.HostVolumePluginDir != "" {
		conf.HostVolumePluginDir = agentConfig.Client.HostVolumePluginDir
	}
	if agentConfig.Client.HostVolumesDir != "" {
		conf.HostVolumesDir = agentConfig.Client.HostVolumesDir
	}
	if agentConfig.Client.NetworkInterface != "" {
		conf.NetworkInterface = agentConfig.Client.NetworkInterface
	}
	if agentConfig.Client.NodeMaxAllocs != 0 {
		conf.NodeMaxAllocs = agentConfig.Client.NodeMaxAllocs
	}

	// handle rpc yamux configuration
	conf.RPCSessionConfig = yamux.DefaultConfig()
	if agentConfig.RPC != nil {
		if agentConfig.RPC.AcceptBacklog > 0 {
			conf.RPCSessionConfig.AcceptBacklog = agentConfig.RPC.AcceptBacklog
		}
		if agentConfig.RPC.KeepAliveInterval > 0 {
			conf.RPCSessionConfig.KeepAliveInterval = agentConfig.RPC.KeepAliveInterval
		}
		if agentConfig.RPC.ConnectionWriteTimeout > 0 {
			conf.RPCSessionConfig.ConnectionWriteTimeout = agentConfig.RPC.ConnectionWriteTimeout
		}
		if agentConfig.RPC.StreamCloseTimeout > 0 {
			conf.RPCSessionConfig.StreamCloseTimeout = agentConfig.RPC.StreamCloseTimeout
		}
		if agentConfig.RPC.StreamOpenTimeout > 0 {
			conf.RPCSessionConfig.StreamOpenTimeout = agentConfig.RPC.StreamOpenTimeout
		}
	}

	conf.PreferredAddressFamily = agentConfig.Client.PreferredAddressFamily

	conf.ChrootEnv = agentConfig.Client.ChrootEnv
	conf.Options = agentConfig.Client.Options

Review comment (suggestion):
The value from `DefaultConfig()` will be 0, so we can skip the conditional here too:

```suggestion
	conf.NodeMaxAllocs = agentConfig.Client.NodeMaxAllocs
```

Code after:
		conf.HostVolumesDir = filepath.Join(agentConfig.DataDir, "host_volumes")
		conf.HostVolumePluginDir = filepath.Join(agentConfig.DataDir, "host_volume_plugins")
		dataParent := filepath.Dir(agentConfig.DataDir)
		conf.AllocMountsDir = filepath.Join(dataParent, "alloc_mounts")
	}
	if agentConfig.Client.StateDir != "" {
		conf.StateDir = agentConfig.Client.StateDir
	}
	if agentConfig.Client.AllocDir != "" {
		conf.AllocDir = agentConfig.Client.AllocDir
	}
	if agentConfig.Client.AllocMountsDir != "" {
		conf.AllocMountsDir = agentConfig.Client.AllocMountsDir
	}
	if agentConfig.Client.HostVolumePluginDir != "" {
		conf.HostVolumePluginDir = agentConfig.Client.HostVolumePluginDir
	}
	if agentConfig.Client.HostVolumesDir != "" {
		conf.HostVolumesDir = agentConfig.Client.HostVolumesDir
	}
	if agentConfig.Client.NetworkInterface != "" {
		conf.NetworkInterface = agentConfig.Client.NetworkInterface
	}
	conf.NodeMaxAllocs = agentConfig.Client.NodeMaxAllocs

	// handle rpc yamux configuration
	conf.RPCSessionConfig = yamux.DefaultConfig()
	if agentConfig.RPC != nil {
		if agentConfig.RPC.AcceptBacklog > 0 {
			conf.RPCSessionConfig.AcceptBacklog = agentConfig.RPC.AcceptBacklog
		}
		if agentConfig.RPC.KeepAliveInterval > 0 {
			conf.RPCSessionConfig.KeepAliveInterval = agentConfig.RPC.KeepAliveInterval
		}
		if agentConfig.RPC.ConnectionWriteTimeout > 0 {
			conf.RPCSessionConfig.ConnectionWriteTimeout = agentConfig.RPC.ConnectionWriteTimeout
		}
		if agentConfig.RPC.StreamCloseTimeout > 0 {
			conf.RPCSessionConfig.StreamCloseTimeout = agentConfig.RPC.StreamCloseTimeout
		}
		if agentConfig.RPC.StreamOpenTimeout > 0 {
			conf.RPCSessionConfig.StreamOpenTimeout = agentConfig.RPC.StreamOpenTimeout
		}
	}

	conf.PreferredAddressFamily = agentConfig.Client.PreferredAddressFamily

	conf.ChrootEnv = agentConfig.Client.ChrootEnv
	conf.Options = agentConfig.Client.Options
	if agentConfig.Client.NetworkSpeed != 0 {
		conf.NetworkSpeed = agentConfig.Client.NetworkSpeed