Skip to content

Commit 6642852

Browse files
committed
OpenShiftP-281: only one device is visible to the lpar, accounting for that with the capacity
Signed-off-by: Paul Bastide <[email protected]>
1 parent c4681df commit 6642852

File tree

1 file changed

+30
-45
lines changed

1 file changed

+30
-45
lines changed

cmd/power-dra-kubeletplugin/discovery.go

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,70 +6,55 @@
66
package main
77

88
import (
9-
"fmt"
10-
"math/rand"
119
"os"
1210

13-
"github.com/google/uuid"
1411
resourceapi "k8s.io/api/resource/v1beta1"
1512
"k8s.io/apimachinery/pkg/api/resource"
1613
"k8s.io/klog/v2"
1714
"k8s.io/utils/ptr"
1815
)
1916

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"
2120

2221
func enumerateAllPossibleDevices(numNx int) (AllocatableDevices, error) {
23-
seed := os.Getenv("NODE_NAME")
24-
uuids := generateUUIDs(seed, numNx)
2522
alldevices := make(AllocatableDevices)
23+
24+
// If nx-gzip doesn't exist, then don't return any devices.
2625
if !existsNxGzip() {
27-
// If nx-gzip doesn't exist, then don't return any devices.
2826
return alldevices, nil
2927
}
3028

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),
4840
},
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"),
5346
},
5447
},
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+
},
7054
}
55+
alldevices[device.Name] = device
7156

72-
return uuids
57+
return alldevices, nil
7358
}
7459

7560
func hash(s string) int64 {
@@ -82,7 +67,7 @@ func hash(s string) int64 {
8267

8368
// Detect NXGZIPCAPS exists
8469
func existsNxGzip() bool {
85-
_, err := os.Stat(NXGZIPCAPS)
70+
_, err := os.Stat(CapsLocation)
8671
if err != nil {
8772
klog.V(5).ErrorS(err, "Failed to detect Nest Accelerator nx-gzip feature")
8873
return false

0 commit comments

Comments
 (0)