6
6
package main
7
7
8
8
import (
9
- "fmt"
10
- "math/rand"
11
9
"os"
12
10
13
- "github.com/google/uuid"
14
11
resourceapi "k8s.io/api/resource/v1beta1"
15
12
"k8s.io/apimachinery/pkg/api/resource"
16
13
"k8s.io/klog/v2"
17
14
"k8s.io/utils/ptr"
18
15
)
19
16
20
- const NXGZIPCAPS = "/host-sys/devices/vio/ibm,compression-v1/nx_gzip_caps"
17
+ const CapsLocation = "/host-sys/devices/vio/ibm,compression-v1/nx_gzip_caps"
18
+ const UpperLimit = "200"
19
+ const Uuid = "b2ccae49-efdd-4d90-bc8e-6fec4a2b19f7"
21
20
22
21
func enumerateAllPossibleDevices (numNx int ) (AllocatableDevices , error ) {
23
- seed := os .Getenv ("NODE_NAME" )
24
- uuids := generateUUIDs (seed , numNx )
25
22
alldevices := make (AllocatableDevices )
23
+
24
+ // If nx-gzip doesn't exist, then don't return any devices.
26
25
if ! existsNxGzip () {
27
- // If nx-gzip doesn't exist, then don't return any devices.
28
26
return alldevices , nil
29
27
}
30
28
31
- for i , uuid := range uuids {
32
- device := resourceapi.Device {
33
- Name : fmt .Sprintf ("nx-%d" , i ),
34
- Basic : & resourceapi.BasicDevice {
35
- Attributes : map [resourceapi.QualifiedName ]resourceapi.DeviceAttribute {
36
- "index" : {
37
- IntValue : ptr .To (int64 (i )),
38
- },
39
- "uuid" : {
40
- StringValue : ptr .To (uuid ),
41
- },
42
- "model" : {
43
- StringValue : ptr .To ("LATEST-NX-MODEL" ),
44
- },
45
- "driverVersion" : {
46
- VersionValue : ptr .To ("0.1.0" ),
47
- },
29
+ // prepopulate
30
+
31
+ device := resourceapi.Device {
32
+ Name : "crypto/nx-gzip" ,
33
+ Basic : & resourceapi.BasicDevice {
34
+ Attributes : map [resourceapi.QualifiedName ]resourceapi.DeviceAttribute {
35
+ "index" : {
36
+ IntValue : ptr .To (int64 (0 )),
37
+ },
38
+ "uuid" : {
39
+ StringValue : ptr .To (Uuid ),
48
40
},
49
- Capacity : map [resourceapi.QualifiedName ]resourceapi.DeviceCapacity {
50
- "memory" : {
51
- Value : resource .MustParse ("80Gi" ),
52
- },
41
+ "model" : {
42
+ StringValue : ptr .To ("LATEST-NX-MODEL" ),
43
+ },
44
+ "driverVersion" : {
45
+ VersionValue : ptr .To ("0.1.0" ),
53
46
},
54
47
},
55
- }
56
- alldevices [device .Name ] = device
57
- }
58
- return alldevices , nil
59
- }
60
-
61
- func generateUUIDs (seed string , count int ) []string {
62
- rand := rand .New (rand .NewSource (hash (seed )))
63
-
64
- uuids := make ([]string , count )
65
- for i := 0 ; i < count ; i ++ {
66
- charset := make ([]byte , 16 )
67
- rand .Read (charset )
68
- uuid , _ := uuid .FromBytes (charset )
69
- uuids [i ] = "nx-" + uuid .String ()
48
+ Capacity : map [resourceapi.QualifiedName ]resourceapi.DeviceCapacity {
49
+ "nx-gzip" : {
50
+ Value : resource .MustParse (UpperLimit ),
51
+ },
52
+ },
53
+ },
70
54
}
55
+ alldevices [device .Name ] = device
71
56
72
- return uuids
57
+ return alldevices , nil
73
58
}
74
59
75
60
func hash (s string ) int64 {
@@ -82,7 +67,7 @@ func hash(s string) int64 {
82
67
83
68
// Detect NXGZIPCAPS exists
84
69
func existsNxGzip () bool {
85
- _ , err := os .Stat (NXGZIPCAPS )
70
+ _ , err := os .Stat (CapsLocation )
86
71
if err != nil {
87
72
klog .V (5 ).ErrorS (err , "Failed to detect Nest Accelerator nx-gzip feature" )
88
73
return false
0 commit comments