|
17 | 17 | package lm
|
18 | 18 |
|
19 | 19 | import (
|
20 |
| - "bufio" |
21 |
| - "errors" |
22 | 20 | "fmt"
|
23 |
| - "io" |
24 |
| - "net" |
25 |
| - "os" |
26 |
| - "path/filepath" |
27 |
| - "sort" |
28 | 21 | "strings"
|
29 | 22 |
|
30 |
| - "github.com/google/uuid" |
31 | 23 | "k8s.io/klog/v2"
|
32 | 24 |
|
33 | 25 | spec "github.com/NVIDIA/k8s-device-plugin/api/config/v1"
|
34 | 26 | "github.com/NVIDIA/k8s-device-plugin/internal/resource"
|
35 | 27 | )
|
36 | 28 |
|
37 |
| -const ( |
38 |
| - // ImexNodesConfigFilePath is the path to the IMEX nodes config file. |
39 |
| - // This file contains a list of IP addresses of the nodes in the IMEX domain. |
40 |
| - ImexNodesConfigFilePath = "/etc/nvidia-imex/nodes_config.cfg" |
41 |
| -) |
42 |
| - |
43 | 29 | func newImexLabeler(config *spec.Config, devices []resource.Device) (Labeler, error) {
|
44 |
| - var errs error |
45 |
| - for _, root := range imexNodesConfigFilePathSearchRoots(config) { |
46 |
| - configFilePath := filepath.Join(root, ImexNodesConfigFilePath) |
47 |
| - imexLabeler, err := imexLabelerForConfigFile(configFilePath, devices) |
48 |
| - if err != nil { |
49 |
| - errs = errors.Join(errs, err) |
50 |
| - continue |
51 |
| - } |
52 |
| - if imexLabeler != nil { |
53 |
| - klog.Infof("Using labeler for IMEX config %v", configFilePath) |
54 |
| - return imexLabeler, nil |
55 |
| - } |
56 |
| - } |
57 |
| - if errs != nil { |
58 |
| - return nil, errs |
59 |
| - } |
60 |
| - |
61 |
| - return empty{}, nil |
62 |
| -} |
63 |
| - |
64 |
| -// imexNodesConfigFilePathSearchRoots returns a list of roots to search for the IMEX nodes config file. |
65 |
| -func imexNodesConfigFilePathSearchRoots(config *spec.Config) []string { |
66 |
| - // By default, search / and /config for config files. |
67 |
| - roots := []string{"/", "/config"} |
68 |
| - |
69 |
| - if config == nil || config.Flags.Plugin == nil || config.Flags.Plugin.ContainerDriverRoot == nil { |
70 |
| - return roots |
71 |
| - } |
72 |
| - |
73 |
| - // If a driver root is specified, it is also searched. |
74 |
| - return append(roots, *config.Flags.Plugin.ContainerDriverRoot) |
75 |
| -} |
76 |
| - |
77 |
| -func imexLabelerForConfigFile(configFilePath string, devices []resource.Device) (Labeler, error) { |
78 |
| - imexConfigFile, err := os.Open(configFilePath) |
79 |
| - if os.IsNotExist(err) { |
80 |
| - // No imex config file, return empty labels |
81 |
| - return nil, nil |
82 |
| - } else if err != nil { |
83 |
| - return nil, fmt.Errorf("failed to open imex config file: %v", err) |
84 |
| - } |
85 |
| - defer imexConfigFile.Close() |
86 |
| - |
87 | 30 | clusterUUID, cliqueID, err := getFabricIDs(devices)
|
88 | 31 | if err != nil {
|
89 | 32 | return nil, err
|
90 | 33 | }
|
91 | 34 | if clusterUUID == "" || cliqueID == "" {
|
92 |
| - return nil, nil |
93 |
| - } |
94 |
| - |
95 |
| - imexDomainID, err := getImexDomainID(imexConfigFile) |
96 |
| - if err != nil { |
97 |
| - return nil, err |
98 |
| - } |
99 |
| - if imexDomainID == "" { |
100 |
| - return nil, nil |
| 35 | + return empty{}, nil |
101 | 36 | }
|
102 | 37 |
|
103 | 38 | labels := Labels{
|
104 |
| - "nvidia.com/gpu.clique": strings.Join([]string{clusterUUID, cliqueID}, "."), |
105 |
| - "nvidia.com/gpu.imex-domain": strings.Join([]string{imexDomainID, cliqueID}, "."), |
| 39 | + "nvidia.com/gpu.clique": strings.Join([]string{clusterUUID, cliqueID}, "."), |
106 | 40 | }
|
107 | 41 |
|
108 | 42 | return labels, nil
|
@@ -147,36 +81,3 @@ func getFabricIDs(devices []resource.Device) (string, string, error) {
|
147 | 81 | }
|
148 | 82 | return "", "", nil
|
149 | 83 | }
|
150 |
| - |
151 |
| -// getImexDomainID reads the imex config file and returns a unique identifier |
152 |
| -// based on the sorted list of IP addresses in the file. |
153 |
| -func getImexDomainID(r io.Reader) (string, error) { |
154 |
| - // Read the file line by line |
155 |
| - var ips []string |
156 |
| - scanner := bufio.NewScanner(r) |
157 |
| - for scanner.Scan() { |
158 |
| - ip := strings.TrimSpace(scanner.Text()) |
159 |
| - if net.ParseIP(ip) == nil { |
160 |
| - return "", fmt.Errorf("invalid IP address in imex config file: %s", ip) |
161 |
| - } |
162 |
| - ips = append(ips, ip) |
163 |
| - } |
164 |
| - |
165 |
| - if err := scanner.Err(); err != nil { |
166 |
| - return "", fmt.Errorf("failed to read imex config file: %v", err) |
167 |
| - } |
168 |
| - |
169 |
| - if len(ips) == 0 { |
170 |
| - // No IPs in the file, return empty labels |
171 |
| - return "", nil |
172 |
| - } |
173 |
| - |
174 |
| - sort.Strings(ips) |
175 |
| - |
176 |
| - return generateContentUUID(strings.Join(ips, "\n")), nil |
177 |
| - |
178 |
| -} |
179 |
| - |
180 |
| -func generateContentUUID(seed string) string { |
181 |
| - return uuid.NewSHA1(uuid.Nil, []byte(seed)).String() |
182 |
| -} |
0 commit comments