@@ -25,12 +25,14 @@ import (
2525 resourceapi "k8s.io/api/resource/v1"
2626 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727 "k8s.io/apimachinery/pkg/runtime"
28+ "k8s.io/apimachinery/pkg/util/version"
2829 "k8s.io/dynamic-resource-allocation/kubeletplugin"
2930 "k8s.io/klog/v2"
3031 "k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
3132 cdiapi "tags.cncf.io/container-device-interface/pkg/cdi"
3233
3334 configapi "github.com/NVIDIA/k8s-dra-driver-gpu/api/nvidia.com/resource/v1beta1"
35+ "github.com/NVIDIA/k8s-dra-driver-gpu/pkg/featuregates"
3436)
3537
3638type OpaqueDeviceConfig struct {
@@ -62,6 +64,13 @@ func NewDeviceState(ctx context.Context, config *Config) (*DeviceState, error) {
6264 return nil , fmt .Errorf ("failed to create device library: %w" , err )
6365 }
6466
67+ // Check driver version if IMEXDaemonsWithDNSNames feature gate is enabled
68+ if featuregates .Enabled (featuregates .IMEXDaemonsWithDNSNames ) {
69+ if err := validateDriverVersionForIMEXDaemonsWithDNSNames (config .flags , nvdevlib ); err != nil {
70+ return nil , fmt .Errorf ("driver version validation failed: %w" , err )
71+ }
72+ }
73+
6574 allocatable , err := nvdevlib .enumerateAllPossibleDevices (config )
6675 if err != nil {
6776 return nil , fmt .Errorf ("error enumerating all possible devices: %w" , err )
@@ -561,6 +570,32 @@ func (s *DeviceState) getConfigResultsMap(rcs *resourceapi.ResourceClaimStatus,
561570 return configResultsMap , nil
562571}
563572
573+ // validateDriverVersionForIMEXDaemonsWithDNSNames validates that the driver version
574+ // meets the minimum requirement for the IMEXDaemonsWithDNSNames feature gate.
575+ func validateDriverVersionForIMEXDaemonsWithDNSNames (flags * Flags , nvdevlib * deviceLib ) error {
576+ klog .Infof ("Starting driver version validation for IMEXDaemonsWithDNSNames feature..." )
577+ klog .Infof ("Minimum required version: %s" , IMEXDaemonsWithDNSNamesMinDriverVersion )
578+
579+ driverVer , err := nvdevlib .getDriverVersion ()
580+ if err != nil {
581+ return fmt .Errorf ("error getting driver version: %w" , err )
582+ }
583+
584+ minVersion , err := version .ParseGeneric (IMEXDaemonsWithDNSNamesMinDriverVersion )
585+ if err != nil {
586+ return fmt .Errorf ("error parsing minimum version: %w" , err )
587+ }
588+
589+ if driverVer .LessThan (minVersion ) {
590+ klog .Errorf ("IMEXDaemonsWithDNSNames feature requires driver version >= %s, but found %s" , minVersion .String (), driverVer .String ())
591+ klog .Errorf ("If installed via helm, set featureGates.IMEXDaemonsWithDNSNames=false to disable feature" )
592+ return fmt .Errorf ("minimum version not satisfied for IMEXDaemonsWithDNSNames feature" )
593+ }
594+
595+ klog .Infof ("Driver version validation passed: %s >= %s" , driverVer .String (), minVersion .String ())
596+ return nil
597+ }
598+
564599// GetOpaqueDeviceConfigs returns an ordered list of the configs contained in possibleConfigs for this driver.
565600//
566601// Configs can either come from the resource claim itself or from the device
0 commit comments