1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
13 "git.arvados.org/arvados.git/sdk/go/arvados"
16 // SlurmNodeTypeFeatureKludge ensures SLURM accepts every instance
17 // type name as a valid feature name, even if no instances of that
18 // type have appeared yet.
20 // It takes advantage of some SLURM peculiarities:
22 // (1) A feature is valid after it has been offered by a node, even if
23 // it is no longer offered by any node. So, to make a feature name
24 // valid, we can add it to a dummy node ("compute0"), then remove it.
26 // (2) To test whether a set of feature names are valid without
27 // actually submitting a job, we can call srun --test-only with the
30 // SlurmNodeTypeFeatureKludge does a test-and-fix operation
31 // immediately, and then periodically, in case slurm restarts and
32 // forgets the list of valid features. It never returns (unless there
33 // are no node types configured, in which case it returns
34 // immediately), so it should generally be invoked with "go".
35 func SlurmNodeTypeFeatureKludge(cc *arvados.Cluster) {
36 if len(cc.InstanceTypes) == 0 {
40 for _, it := range cc.InstanceTypes {
41 features = append(features, "instancetype="+it.Name)
45 time.Sleep(2 * time.Second)
49 const slurmDummyNode = "compute0"
51 func slurmKludge(features []string) {
52 allFeatures := strings.Join(features, ",")
54 cmd := exec.Command("sinfo", "--nodes="+slurmDummyNode, "--format=%f", "--noheader")
55 out, err := cmd.CombinedOutput()
57 log.Printf("running %q %q: %s (output was %q)", cmd.Path, cmd.Args, err, out)
60 if string(out) == allFeatures+"\n" {
61 // Already configured correctly, nothing to do.
65 log.Printf("configuring node %q with all node type features", slurmDummyNode)
66 cmd = exec.Command("scontrol", "update", "NodeName="+slurmDummyNode, "Features="+allFeatures)
67 log.Printf("running: %q %q", cmd.Path, cmd.Args)
68 out, err = cmd.CombinedOutput()
70 log.Printf("error: scontrol: %s (output was %q)", err, out)