Skip to content

Commit 01f8289

Browse files
committed
Make ComptueDomains with DNS names the default
Signed-off-by: Kevin Klues <[email protected]>
1 parent 491c9ab commit 01f8289

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed

cmd/compute-domain-kubelet-plugin/main.go

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,19 @@ import (
2727

2828
"github.com/urfave/cli/v2"
2929

30+
"k8s.io/apimachinery/pkg/util/version"
3031
"k8s.io/dynamic-resource-allocation/kubeletplugin"
3132
"k8s.io/klog/v2"
3233

3334
"github.com/NVIDIA/k8s-dra-driver-gpu/internal/info"
35+
"github.com/NVIDIA/k8s-dra-driver-gpu/pkg/featuregates"
3436
"github.com/NVIDIA/k8s-dra-driver-gpu/pkg/flags"
3537
)
3638

3739
const (
38-
DriverName = "compute-domain.nvidia.com"
39-
DriverPluginCheckpointFileBasename = "checkpoint.json"
40+
DriverName = "compute-domain.nvidia.com"
41+
DriverPluginCheckpointFileBasename = "checkpoint.json"
42+
IMEXDaemonsWithDNSNamesMinDriverVersion = "570.158.01"
4043
)
4144

4245
type Flags struct {
@@ -186,6 +189,13 @@ func newApp() *cli.App {
186189

187190
// RunPlugin initializes and runs the compute domain kubelet plugin.
188191
func RunPlugin(ctx context.Context, config *Config) error {
192+
// Check driver version if IMEXDaemonsWithDNSNames feature gate is enabled
193+
if featuregates.Enabled(featuregates.IMEXDaemonsWithDNSNames) {
194+
if err := validateDriverVersionForIMEXDaemonsWithDNSNames(config.flags); err != nil {
195+
return fmt.Errorf("driver version validation failed: %w", err)
196+
}
197+
}
198+
189199
// Create the plugin directory
190200
err := os.MkdirAll(config.DriverPluginPath(), 0750)
191201
if err != nil {
@@ -263,3 +273,35 @@ func (c Config) setNvidiaCDIHookPath() error {
263273

264274
return nil
265275
}
276+
277+
// validateDriverVersionForIMEXDaemonsWithDNSNames validates that the driver version
278+
// meets the minimum requirement for the IMEXDaemonsWithDNSNames feature gate.
279+
func validateDriverVersionForIMEXDaemonsWithDNSNames(flags *Flags) error {
280+
klog.Infof("Starting driver version validation for IMEXDaemonsWithDNSNames feature...")
281+
klog.Infof("Minimum required version: %s", IMEXDaemonsWithDNSNamesMinDriverVersion)
282+
283+
containerDriverRoot := root(flags.containerDriverRoot)
284+
nvdevlib, err := newDeviceLib(containerDriverRoot)
285+
if err != nil {
286+
return fmt.Errorf("failed to create device library: %w", err)
287+
}
288+
289+
driverVer, err := nvdevlib.getDriverVersion()
290+
if err != nil {
291+
return fmt.Errorf("error getting driver version: %w", err)
292+
}
293+
294+
minVersion, err := version.ParseGeneric(IMEXDaemonsWithDNSNamesMinDriverVersion)
295+
if err != nil {
296+
return fmt.Errorf("error parsing minimum version: %w", err)
297+
}
298+
299+
if driverVer.LessThan(minVersion) {
300+
klog.Errorf("IMEXDaemonsWithDNSNames feature requires driver version >= %s, but found %s", minVersion.String(), driverVer.String())
301+
klog.Errorf("If installed via helm, set featureGates.IMEXDaemonsWithDNSNames=false to run without this feature.")
302+
return fmt.Errorf("minimum version not satisfied")
303+
}
304+
305+
klog.Infof("Driver version validation passed: %s >= %s", driverVer.String(), minVersion.String())
306+
return nil
307+
}

cmd/compute-domain-kubelet-plugin/nvlib.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"strconv"
2727
"strings"
2828

29+
"k8s.io/apimachinery/pkg/util/version"
2930
"k8s.io/klog/v2"
3031
"k8s.io/mount-utils"
3132

@@ -388,3 +389,24 @@ func (l deviceLib) unmountRecursively(root string) error {
388389

389390
return helper(root)
390391
}
392+
393+
// getDriverVersion returns the version of the NVIDIA driver.
394+
func (l deviceLib) getDriverVersion() (*version.Version, error) {
395+
if err := l.init(); err != nil {
396+
return nil, fmt.Errorf("error initializing NVML: %w", err)
397+
}
398+
defer l.alwaysShutdown()
399+
400+
driverVersion, ret := l.nvmllib.SystemGetDriverVersion()
401+
if ret != nvml.SUCCESS {
402+
return nil, fmt.Errorf("error getting driver version: %v", ret)
403+
}
404+
405+
// Parse the version using Kubernetes version utilities
406+
v, err := version.ParseGeneric(driverVersion)
407+
if err != nil {
408+
return nil, fmt.Errorf("invalid driver version format '%s': %w", driverVersion, err)
409+
}
410+
411+
return v, nil
412+
}

pkg/featuregates/featuregates.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ var defaultFeatureGates = map[featuregate.Feature]featuregate.VersionedSpecs{
6161
},
6262
IMEXDaemonsWithDNSNames: {
6363
{
64-
Default: false,
65-
PreRelease: featuregate.Alpha,
64+
Default: true,
65+
PreRelease: featuregate.Beta,
6666
Version: version.MajorMinor(25, 8),
6767
},
6868
},

0 commit comments

Comments
 (0)