From ca380205212b18e478930e65ea4cdd3c1203f551 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Mon, 3 Jul 2017 13:25:33 -0700 Subject: [PATCH] 0 compute == error --- client/fingerprint/cpu.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/client/fingerprint/cpu.go b/client/fingerprint/cpu.go index a75ee0d8b..0c9b4c25d 100644 --- a/client/fingerprint/cpu.go +++ b/client/fingerprint/cpu.go @@ -59,19 +59,20 @@ func (f *CPUFingerprint) Fingerprint(cfg *config.Config, node *structs.Node) (bo tt = cfg.CpuCompute } - // Set the node compute resources if they are detected/configured - if tt > 0 { - node.Attributes["cpu.totalcompute"] = fmt.Sprintf("%d", tt) - - if node.Resources == nil { - node.Resources = &structs.Resources{} - } - - node.Resources.CPU = tt - } else { - f.logger.Printf("[INFO] fingerprint.cpu: cannot detect cpu total compute. "+ + // Return an error if no cpu was detected or explicitly set as this + // node would be unable to receive any allocations. + if tt == 0 { + return false, fmt.Errorf("cannot detect cpu total compute. "+ "CPU compute must be set manually using the client config option %q", "cpu_total_compute") } + + node.Attributes["cpu.totalcompute"] = fmt.Sprintf("%d", tt) + + if node.Resources == nil { + node.Resources = &structs.Resources{} + } + + node.Resources.CPU = tt return true, nil }