mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
client: defensively log reserved ports
- Fix test broken due to being improperly setup. - Include min/max ports in default client config.
This commit is contained in:
@@ -643,10 +643,16 @@ func (c *Client) init() error {
|
||||
|
||||
c.logger.Info("using alloc directory", "alloc_dir", c.config.AllocDir)
|
||||
|
||||
reserved := "<none>"
|
||||
if c.config.Node != nil && c.config.Node.ReservedResources != nil {
|
||||
// Node should always be non-nil due to initialization in the
|
||||
// agent package, but don't risk a panic just for a long line.
|
||||
reserved = c.config.Node.ReservedResources.Networks.ReservedHostPorts
|
||||
}
|
||||
c.logger.Info("using dynamic ports",
|
||||
"min", c.config.MinDynamicPort,
|
||||
"max", c.config.MaxDynamicPort,
|
||||
"reserved", c.config.Node.ReservedResources.Networks.ReservedHostPorts,
|
||||
"reserved", reserved,
|
||||
)
|
||||
|
||||
// Ensure cgroups are created on linux platform
|
||||
|
||||
@@ -737,11 +737,15 @@ func TestClient_Init(t *testing.T) {
|
||||
defer os.RemoveAll(dir)
|
||||
allocDir := filepath.Join(dir, "alloc")
|
||||
|
||||
config := config.DefaultConfig()
|
||||
config.AllocDir = allocDir
|
||||
config.StateDBFactory = cstate.GetStateDBFactory(true)
|
||||
|
||||
// Node is always initialized in agent.go:convertClientConfig()
|
||||
config.Node = mock.Node()
|
||||
|
||||
client := &Client{
|
||||
config: &config.Config{
|
||||
AllocDir: allocDir,
|
||||
StateDBFactory: cstate.GetStateDBFactory(true),
|
||||
},
|
||||
config: config,
|
||||
logger: testlog.HCLogger(t),
|
||||
}
|
||||
|
||||
|
||||
@@ -343,6 +343,8 @@ func DefaultConfig() *Config {
|
||||
CNIInterfacePrefix: "eth",
|
||||
HostNetworks: map[string]*structs.ClientHostNetworkConfig{},
|
||||
CgroupParent: cgutil.DefaultCgroupParent,
|
||||
MaxDynamicPort: structs.DefaultMinDynamicPort,
|
||||
MinDynamicPort: structs.DefaultMaxDynamicPort,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,13 +8,13 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// defaultMinDynamicPort is the smallest dynamic port generated by
|
||||
// DefaultMinDynamicPort is the smallest dynamic port generated by
|
||||
// default
|
||||
defaultMinDynamicPort = 20000
|
||||
DefaultMinDynamicPort = 20000
|
||||
|
||||
// defaultMaxDynamicPort is the largest dynamic port generated by
|
||||
// DefaultMaxDynamicPort is the largest dynamic port generated by
|
||||
// default
|
||||
defaultMaxDynamicPort = 32000
|
||||
DefaultMaxDynamicPort = 32000
|
||||
|
||||
// maxRandPortAttempts is the maximum number of attempt
|
||||
// to assign a random port
|
||||
@@ -53,8 +53,8 @@ func NewNetworkIndex() *NetworkIndex {
|
||||
AvailBandwidth: make(map[string]int),
|
||||
UsedPorts: make(map[string]Bitmap),
|
||||
UsedBandwidth: make(map[string]int),
|
||||
MinDynamicPort: defaultMinDynamicPort,
|
||||
MaxDynamicPort: defaultMaxDynamicPort,
|
||||
MinDynamicPort: DefaultMinDynamicPort,
|
||||
MaxDynamicPort: DefaultMaxDynamicPort,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user