Skip to content

Commit c4681df

Browse files
committed
OpenShiftP-281: refactor to account for the situation where nx-gzip is not present on system
Signed-off-by: Paul Bastide <[email protected]>
1 parent 430f3db commit c4681df

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

cmd/power-dra-kubeletplugin/discovery.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,24 @@ import (
1010
"math/rand"
1111
"os"
1212

13+
"github.com/google/uuid"
1314
resourceapi "k8s.io/api/resource/v1beta1"
1415
"k8s.io/apimachinery/pkg/api/resource"
16+
"k8s.io/klog/v2"
1517
"k8s.io/utils/ptr"
16-
17-
"github.com/google/uuid"
1818
)
1919

20+
const NXGZIPCAPS = "/host-sys/devices/vio/ibm,compression-v1/nx_gzip_caps"
21+
2022
func enumerateAllPossibleDevices(numNx int) (AllocatableDevices, error) {
2123
seed := os.Getenv("NODE_NAME")
2224
uuids := generateUUIDs(seed, numNx)
23-
2425
alldevices := make(AllocatableDevices)
26+
if !existsNxGzip() {
27+
// If nx-gzip doesn't exist, then don't return any devices.
28+
return alldevices, nil
29+
}
30+
2531
for i, uuid := range uuids {
2632
device := resourceapi.Device{
2733
Name: fmt.Sprintf("nx-%d", i),
@@ -73,3 +79,13 @@ func hash(s string) int64 {
7379
}
7480
return h
7581
}
82+
83+
// Detect NXGZIPCAPS exists
84+
func existsNxGzip() bool {
85+
_, err := os.Stat(NXGZIPCAPS)
86+
if err != nil {
87+
klog.V(5).ErrorS(err, "Failed to detect Nest Accelerator nx-gzip feature")
88+
return false
89+
}
90+
return true
91+
}

deployments/helm/power-dra-driver/templates/kubeletplugin.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ spec:
6666
mountPath: /var/lib/kubelet/plugins
6767
- name: cdi
6868
mountPath: /var/run/cdi
69+
- name: host-sys
70+
mountPath: /host-sys
6971
volumes:
7072
- name: plugins-registry
7173
hostPath:
@@ -75,6 +77,10 @@ spec:
7577
hostPath:
7678
path: /var/lib/kubelet/plugins
7779
type: Directory
80+
- name: host-sys
81+
hostPath:
82+
path: /sys
83+
type: Directory
7884
- name: cdi
7985
hostPath:
8086
path: /var/run/cdi

0 commit comments

Comments
 (0)