Skip to content

Commit 430f3db

Browse files
committed
OpenShiftP-281: cleanup for bad version management
Signed-off-by: Paul Bastide <[email protected]>
1 parent 3c4f052 commit 430f3db

File tree

11 files changed

+104
-163
lines changed

11 files changed

+104
-163
lines changed

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ TAG ?= v0.1.0
77

88
CONTAINER_RUNTIME ?= $(shell command -v podman 2> /dev/null || echo docker)
99

10-
include $(CURDIR)/versions.mk
10+
GOLANG_VERSION ?= 1.23.1
11+
12+
DRIVER_NAME := power-dra-driver
13+
MODULE := github.com/IBM/$(DRIVER_NAME)
14+
15+
REGISTRY ?= quay.io/powercloud/power-dra-driver
16+
17+
VERSION ?= v0.1.0
18+
19+
GIT_COMMIT ?= $(shell git describe --match="" --dirty --long --always --abbrev=40 2> /dev/null || echo "")
1120

1221
########################################################################
1322
# Go Targets

README.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
# Power Dynamic Resource Allocation Driver
2-
This repository contains a Power Architecture resource driver for use with the Dynamic Resource Allocation (DRA) feature of Kubernetes.
2+
3+
This repository contains a Power Architecture resource driver for use with the *Dynamic Resource Allocation (DRA)* feature of Kubernetes.
34

45
The driver facilitates access to:
5-
1. Nest Accelerator unit (NX) are non-core components of the POWER processor chip including compression and encryption co-processors. One feature is nx-gzip, which is a DEFLATE compliant (RFC1950, 1951, 1952) compression accelerator in NX. This feature is a device driver in userspace `/dev/crypto/nx-gzip` which is shared among many LPARs and many containers.
66

7-
As additional features are made available, the driver will be expanded.
7+
1. *Nest Accelerator unit (NX) compression and decompression co-processors*: NX is a non-core part of the Power processor, which provides a DEFLATE compliant (RFC1950, 1951, 1952) compression accelerator. This feature has a device driver in userspace `/dev/crypto/nx-gzip` which is shared among logical-partitions on the same systems, and by proxy containers in the logical partition.
8+
9+
As additional features are made available, the driver is to be expanded.
810

9-
This project is licensed under the Apache 2.0 License.
11+
This project is based on [dra-example-driver](https://github.com/kubernetes-sigs/dra-example-driver). This project is licensed under the Apache 2.0 License.
1012

1113
## Pre-Requisites
1214

13-
This feature uses DynamicResourceAllocation. To setup, go into the Cluster UI, `Administration` -> `CustomResourceDefinitions` -> `FeatureGate` -> `Instances` -> `cluster` add `spec.featureSet: TechPreviewNoUpgrade`
15+
On an OpenShift Container Platform cluster, one must enable the `DynamicResourceAllocation` `FeatureGate`. To setup, go into the Cluster UI, `Administration` -> `CustomResourceDefinitions` -> `FeatureGate` -> `Instances` -> `cluster` add `spec.featureSet: TechPreviewNoUpgrade`
1416

15-
You must have Power10+ nodes to take advantage of the power-dra-driver. It will not allocate nx-gzip access if you are not on a Power10, or if the nx-gzip is some how disabled on the Operating System.
17+
You must have Power10 or higher logical partitions that are part of your cluster. It will not allocate `/dev/crypto/nx-gzip` access. The system must have licensed the Power system feature `active_mem_expansion_capable`.
1618

1719
You should also be using an OpenShift Container Platform 4.19+.
1820

1921
## Install
2022

21-
```
23+
To install the code, use:
24+
25+
``` shell
2226
helm upgrade \
2327
--create-namespace \
2428
--namespace power-dra-driver \
@@ -28,7 +32,9 @@ helm upgrade \
2832

2933
## Uninstall
3034

31-
```
35+
To uninstall the code, use:
36+
37+
``` shell
3238
helm uninstall power-dra-driver -n power-dra-driver
3339
```
3440

@@ -39,21 +45,24 @@ preferred because it can be easily scanned.
3945

4046
If you would like to see the detailed LICENSE click [here](LICENSE).
4147

42-
```text
48+
``` text
4349
/*
4450
* Copyright 2025 - IBM Corporation. All rights reserved
4551
* SPDX-License-Identifier: Apache-2.0
4652
*/
4753
```
4854

4955
## References
56+
5057
1. [Kubernetes: Dynamic Resource Allocation](https://kubernetes.io/docs/concepts/scheduling-eviction/dynamic-resource-allocation/)
5158
2. [Kubernetes: Dynamic Resource Allocation example](https://github.com/kubernetes-sigs/dra-example-driver/blob/main/README.md)
5259
3. [OpenShift Feature Gate: DynamicResourceAllocation](https://docs.openshift.com/container-platform/4.17/nodes/clusters/nodes-cluster-enabling-features.html)
60+
5361
> Enables a new API for requesting and sharing resources between pods and containers. This is an internal feature that most users do not need to interact with. (DynamicResourceAllocation)
62+
5463
OpenShift Docs are specific to a use-case
5564

56-
This code repository is based on [kubernetes-sigs/dra-example-driver](https://github.com/kubernetes-sigs/dra-example-driver) and extends apis used in the example driver.
65+
This code repository is based on [kubernetes-sigs/dra-example-driver](https://github.com/kubernetes-sigs/dra-example-driver) and extends APIs used in the example driver.
5766

5867
# Support
5968

cmd/power-dra-kubeletplugin/cdi.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
/*
2-
* Copyright 2023 The Kubernetes Authors.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
2+
* Copyright 2025 - IBM Corporation. All rights reserved
3+
* SPDX-License-Identifier: Apache-2.0
154
*/
165

176
package main

cmd/power-dra-kubeletplugin/checkpoint.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright 2025 - IBM Corporation. All rights reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
package main
27

38
import (

cmd/power-dra-kubeletplugin/discovery.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
/*
2-
* Copyright 2023 The Kubernetes Authors.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
2+
* Copyright 2025 - IBM Corporation. All rights reserved
3+
* SPDX-License-Identifier: Apache-2.0
154
*/
165

176
package main

cmd/power-dra-kubeletplugin/driver.go

Lines changed: 55 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ package main
88
import (
99
"context"
1010
"fmt"
11+
"maps"
1112

12-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13+
resourceapi "k8s.io/api/resource/v1beta1"
14+
"k8s.io/apimachinery/pkg/types"
1315
coreclientset "k8s.io/client-go/kubernetes"
1416
"k8s.io/dynamic-resource-allocation/kubeletplugin"
17+
"k8s.io/dynamic-resource-allocation/resourceslice"
1518
"k8s.io/klog/v2"
16-
drapbv1 "k8s.io/kubelet/pkg/apis/dra/v1beta1"
1719
)
1820

19-
var _ drapbv1.DRAPluginServer = &driver{}
20-
2121
type driver struct {
2222
client coreclientset.Interface
23-
plugin kubeletplugin.DRAPlugin
23+
helper *kubeletplugin.Helper
2424
state *DeviceState
2525
}
2626

@@ -35,87 +35,94 @@ func NewDriver(ctx context.Context, config *Config) (*driver, error) {
3535
}
3636
driver.state = state
3737

38-
plugin, err := kubeletplugin.Start(
38+
helper, err := kubeletplugin.Start(
3939
ctx,
40-
[]any{driver},
40+
driver,
4141
kubeletplugin.KubeClient(config.coreclient),
4242
kubeletplugin.NodeName(config.flags.nodeName),
4343
kubeletplugin.DriverName(DriverName),
44-
kubeletplugin.RegistrarSocketPath(PluginRegistrationPath),
45-
kubeletplugin.PluginSocketPath(DriverPluginSocketPath),
46-
kubeletplugin.KubeletPluginSocketPath(DriverPluginSocketPath))
44+
kubeletplugin.RegistrarDirectoryPath(PluginRegistrationPath),
45+
kubeletplugin.PluginDataDirectoryPath(DriverPluginSocketPath))
4746
if err != nil {
4847
return nil, err
4948
}
50-
driver.plugin = plugin
49+
driver.helper = helper
5150

52-
var resources kubeletplugin.Resources
53-
for _, device := range state.allocatable {
54-
resources.Devices = append(resources.Devices, device)
51+
devices := make([]resourceapi.Device, 0, len(state.allocatable))
52+
for device := range maps.Values(state.allocatable) {
53+
devices = append(devices, device)
54+
}
55+
resources := resourceslice.DriverResources{
56+
Pools: map[string]resourceslice.Pool{
57+
config.flags.nodeName: {
58+
Slices: []resourceslice.Slice{
59+
{
60+
Devices: devices,
61+
},
62+
},
63+
},
64+
},
5565
}
5666

57-
if err := plugin.PublishResources(ctx, resources); err != nil {
67+
if err := helper.PublishResources(ctx, resources); err != nil {
5868
return nil, err
5969
}
6070

6171
return driver, nil
6272
}
6373

6474
func (d *driver) Shutdown(ctx context.Context) error {
65-
d.plugin.Stop()
75+
d.helper.Stop()
6676
return nil
6777
}
6878

69-
func (d *driver) NodePrepareResources(ctx context.Context, req *drapbv1.NodePrepareResourcesRequest) (*drapbv1.NodePrepareResourcesResponse, error) {
70-
klog.Infof("NodePrepareResource is called: number of claims: %d", len(req.Claims))
71-
preparedResources := &drapbv1.NodePrepareResourcesResponse{Claims: map[string]*drapbv1.NodePrepareResourceResponse{}}
79+
func (d *driver) PrepareResourceClaims(ctx context.Context, claims []*resourceapi.ResourceClaim) (map[types.UID]kubeletplugin.PrepareResult, error) {
80+
klog.Infof("PrepareResourceClaims is called: number of claims: %d", len(claims))
81+
result := make(map[types.UID]kubeletplugin.PrepareResult)
7282

73-
for _, claim := range req.Claims {
74-
preparedResources.Claims[claim.UID] = d.nodePrepareResource(ctx, claim)
83+
for _, claim := range claims {
84+
result[claim.UID] = d.prepareResourceClaim(ctx, claim)
7585
}
7686

77-
return preparedResources, nil
87+
return result, nil
7888
}
7989

80-
func (d *driver) nodePrepareResource(ctx context.Context, claim *drapbv1.Claim) *drapbv1.NodePrepareResourceResponse {
81-
resourceClaim, err := d.client.ResourceV1beta1().ResourceClaims(claim.Namespace).Get(
82-
ctx,
83-
claim.Name,
84-
metav1.GetOptions{})
90+
func (d *driver) prepareResourceClaim(_ context.Context, claim *resourceapi.ResourceClaim) kubeletplugin.PrepareResult {
91+
preparedPBs, err := d.state.Prepare(claim)
8592
if err != nil {
86-
return &drapbv1.NodePrepareResourceResponse{
87-
Error: fmt.Sprintf("failed to fetch ResourceClaim %s in namespace %s", claim.Name, claim.Namespace),
93+
return kubeletplugin.PrepareResult{
94+
Err: fmt.Errorf("error preparing devices for claim %v: %w", claim.UID, err),
8895
}
8996
}
90-
91-
prepared, err := d.state.Prepare(resourceClaim)
92-
if err != nil {
93-
return &drapbv1.NodePrepareResourceResponse{
94-
Error: fmt.Sprintf("error preparing devices for claim %v: %v", claim.UID, err),
95-
}
97+
var prepared []kubeletplugin.Device
98+
for _, preparedPB := range preparedPBs {
99+
prepared = append(prepared, kubeletplugin.Device{
100+
Requests: preparedPB.GetRequestNames(),
101+
PoolName: preparedPB.GetPoolName(),
102+
DeviceName: preparedPB.GetDeviceName(),
103+
CDIDeviceIDs: preparedPB.GetCDIDeviceIDs(),
104+
})
96105
}
97106

98107
klog.Infof("Returning newly prepared devices for claim '%v': %v", claim.UID, prepared)
99-
return &drapbv1.NodePrepareResourceResponse{Devices: prepared}
108+
return kubeletplugin.PrepareResult{Devices: prepared}
100109
}
101110

102-
func (d *driver) NodeUnprepareResources(ctx context.Context, req *drapbv1.NodeUnprepareResourcesRequest) (*drapbv1.NodeUnprepareResourcesResponse, error) {
103-
klog.Infof("NodeUnPrepareResource is called: number of claims: %d", len(req.Claims))
104-
unpreparedResources := &drapbv1.NodeUnprepareResourcesResponse{Claims: map[string]*drapbv1.NodeUnprepareResourceResponse{}}
111+
func (d *driver) UnprepareResourceClaims(ctx context.Context, claims []kubeletplugin.NamespacedObject) (map[types.UID]error, error) {
112+
klog.Infof("UnprepareResourceClaims is called: number of claims: %d", len(claims))
113+
result := make(map[types.UID]error)
105114

106-
for _, claim := range req.Claims {
107-
unpreparedResources.Claims[claim.UID] = d.nodeUnprepareResource(ctx, claim)
115+
for _, claim := range claims {
116+
result[claim.UID] = d.unprepareResourceClaim(ctx, claim)
108117
}
109118

110-
return unpreparedResources, nil
119+
return result, nil
111120
}
112121

113-
func (d *driver) nodeUnprepareResource(ctx context.Context, claim *drapbv1.Claim) *drapbv1.NodeUnprepareResourceResponse {
114-
if err := d.state.Unprepare(claim.UID); err != nil {
115-
return &drapbv1.NodeUnprepareResourceResponse{
116-
Error: fmt.Sprintf("error unpreparing devices for claim %v: %v", claim.UID, err),
117-
}
122+
func (d *driver) unprepareResourceClaim(_ context.Context, claim kubeletplugin.NamespacedObject) error {
123+
if err := d.state.Unprepare(string(claim.UID)); err != nil {
124+
return fmt.Errorf("error unpreparing devices for claim %v: %w", claim.UID, err)
118125
}
119126

120-
return &drapbv1.NodeUnprepareResourceResponse{}
127+
return nil
121128
}

cmd/power-dra-kubeletplugin/main.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
/*
2-
Copyright 2025.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
2+
* Copyright 2025 - IBM Corporation. All rights reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
165

176
package main
187

@@ -80,10 +69,11 @@ func newApp() *cli.App {
8069
Destination: &flags.cdiRoot,
8170
EnvVars: []string{"CDI_ROOT"},
8271
},
72+
// TODO: The default number of devices from the ConfigMap
8373
&cli.IntFlag{
8474
Name: "num-devices",
8575
Usage: "The number of devices to be generated.",
86-
Value: 8,
76+
Value: 1000,
8777
Destination: &flags.numDevices,
8878
EnvVars: []string{"NUM_DEVICES"},
8979
},

cmd/power-dra-kubeletplugin/state.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
/*
2-
* Copyright 2023 The Kubernetes Authors.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
2+
* Copyright 2025 - IBM Corporation. All rights reserved
3+
* SPDX-License-Identifier: Apache-2.0
154
*/
165

176
package main

pkg/flags/kubeclient.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
/*
2-
* Copyright 2023 The Kubernetes Authors.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
2+
* Copyright 2025 - IBM Corporation. All rights reserved
3+
* SPDX-License-Identifier: Apache-2.0
154
*/
165

176
package flags

pkg/flags/logging.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
/*
2-
* Copyright 2023 The Kubernetes Authors.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
2+
* Copyright 2025 - IBM Corporation. All rights reserved
3+
* SPDX-License-Identifier: Apache-2.0
154
*/
165

176
package flags

0 commit comments

Comments
 (0)