From b773a1b77f29bdfe65ac3f93934bc4d6cd1349a0 Mon Sep 17 00:00:00 2001 From: Karl Johann Schubert Date: Tue, 24 Jan 2023 15:14:22 +0100 Subject: [PATCH] client: add disk_total_mb and disk_free_mb config options (#15852) --- .changelog/15852.txt | 3 +++ client/config/config.go | 8 ++++++++ client/fingerprint/storage.go | 11 +++++++++++ command/agent/agent.go | 6 ++++++ command/agent/config.go | 12 ++++++++++++ website/content/docs/configuration/client.mdx | 9 +++++++++ 6 files changed, 49 insertions(+) create mode 100644 .changelog/15852.txt diff --git a/.changelog/15852.txt b/.changelog/15852.txt new file mode 100644 index 000000000..2bfb82de5 --- /dev/null +++ b/.changelog/15852.txt @@ -0,0 +1,3 @@ +```release-note:improvement +client/fingerprint/storage: Added config options disk_total_mb and disk_free_mb to override detected disk space +``` diff --git a/client/config/config.go b/client/config/config.go index 646dc1fca..8599cb692 100644 --- a/client/config/config.go +++ b/client/config/config.go @@ -113,6 +113,14 @@ type Config struct { // determined dynamically. MemoryMB int + // DiskTotalMB is the default node total disk space in megabytes if it cannot be + // determined dynamically. + DiskTotalMB int + + // DiskFreeMB is the default node free disk space in megabytes if it cannot be + // determined dynamically. + DiskFreeMB int + // MaxKillTimeout allows capping the user-specifiable KillTimeout. If the // task's KillTimeout is greater than the MaxKillTimeout, MaxKillTimeout is // used. diff --git a/client/fingerprint/storage.go b/client/fingerprint/storage.go index 8b8b992fc..e11a23f49 100644 --- a/client/fingerprint/storage.go +++ b/client/fingerprint/storage.go @@ -41,6 +41,17 @@ func (f *StorageFingerprint) Fingerprint(req *FingerprintRequest, resp *Fingerpr return fmt.Errorf("failed to determine disk space for %s: %v", storageDir, err) } + if cfg.DiskTotalMB > 0 { + total = uint64(cfg.DiskTotalMB) * bytesPerMegabyte + } + if cfg.DiskFreeMB > 0 { + free = uint64(cfg.DiskFreeMB) * bytesPerMegabyte + } + + if total < free { + return fmt.Errorf("detected more free disk space (%d) than total disk space (%d), use disk_total_mb and disk_free_mb to correct", free, total) + } + resp.AddAttribute("unique.storage.volume", volume) resp.AddAttribute("unique.storage.bytestotal", strconv.FormatUint(total, 10)) resp.AddAttribute("unique.storage.bytesfree", strconv.FormatUint(free, 10)) diff --git a/command/agent/agent.go b/command/agent/agent.go index 86e638262..b955485f1 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -668,6 +668,12 @@ func convertClientConfig(agentConfig *Config) (*clientconfig.Config, error) { if agentConfig.Client.MemoryMB != 0 { conf.MemoryMB = agentConfig.Client.MemoryMB } + if agentConfig.Client.DiskTotalMB != 0 { + conf.DiskTotalMB = agentConfig.Client.DiskTotalMB + } + if agentConfig.Client.DiskFreeMB != 0 { + conf.DiskFreeMB = agentConfig.Client.DiskFreeMB + } if agentConfig.Client.MaxKillTimeout != "" { dur, err := time.ParseDuration(agentConfig.Client.MaxKillTimeout) if err != nil { diff --git a/command/agent/config.go b/command/agent/config.go index 31b751309..08db9e6a9 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -227,6 +227,12 @@ type ClientConfig struct { // MemoryMB is used to override any detected or default total memory. MemoryMB int `hcl:"memory_total_mb"` + // DiskTotalMB is used to override any detected or default total disk space. + DiskTotalMB int `hcl:"disk_total_mb"` + + // DiskFreeMB is used to override any detected or default free disk space. + DiskFreeMB int `hcl:"disk_free_mb"` + // ReservableCores is used to override detected reservable cpu cores. ReserveableCores string `hcl:"reservable_cores"` @@ -2006,6 +2012,12 @@ func (a *ClientConfig) Merge(b *ClientConfig) *ClientConfig { if b.MemoryMB != 0 { result.MemoryMB = b.MemoryMB } + if b.DiskTotalMB != 0 { + result.DiskTotalMB = b.DiskTotalMB + } + if b.DiskFreeMB != 0 { + result.DiskFreeMB = b.DiskFreeMB + } if b.MaxKillTimeout != "" { result.MaxKillTimeout = b.MaxKillTimeout } diff --git a/website/content/docs/configuration/client.mdx b/website/content/docs/configuration/client.mdx index 0a2fe0ebf..b001a305f 100644 --- a/website/content/docs/configuration/client.mdx +++ b/website/content/docs/configuration/client.mdx @@ -65,6 +65,15 @@ client { - `memory_total_mb` `(int:0)` - Specifies an override for the total memory. If set, this value overrides any detected memory. +- `disk_total_mb` `(int:0)` - Specifies an override for the total disk space + fingerprint attribute. This value is not used by the scheduler unless you have + constraints set on the attribute `unique.storage.bytestotal`. The actual total + disk space can be determined via the [Read Stats API](https://github.com/api-docs/client#read-stats) + +- `disk_free_mb` `(int:0)` - Specifies the disk space free for scheduling + allocations. If set, this value overrides any detected free disk space. This + value can be seen in `nomad node status` under Allocated Resources. + - `min_dynamic_port` `(int:20000)` - Specifies the minimum dynamic port to be assigned. Individual ports and ranges of ports may be excluded from dynamic port assignment via [`reserved`](#reserved-parameters) parameters.