• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NVIDIA / gpu-operator / 27639094040

16 Jun 2026 06:00PM UTC coverage: 31.519% (+1.2%) from 30.322%
27639094040

push

github

rahulait
add support for default nvidiadriver and migration from clusterpolicy to nvidiadriver

changes include:
* added default nvidiadriver which doesn't conflict with other user-specified nvidiadrivers
* added migration support from clusterpolicy to nvidiadriver
* added/updated e2e tests for nvidiadriver workflow
* use new field to mark a nvidiadriver as default instead of using a label
* don't allow adding nodeselector to default nvidiadriver, it should cover entire cluster
* move default NVIDIADriver ownership helpers into internal/nvidiadriver and re-use
* requeue after node owner label changes so later reconcile steps read updated cache state
* use patch instead of update for node label updates

Signed-off-by: Rahul Sharma <rahulsharm@nvidia.com>

190 of 262 new or added lines in 10 files covered. (72.52%)

1 existing line in 1 file now uncovered.

4025 of 12770 relevant lines covered (31.52%)

0.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.36
/internal/validator/validator.go
1
/**
2
# Copyright (c) NVIDIA CORPORATION.  All rights reserved.
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
**/
16

17
package validator
18

19
import (
20
        "context"
21
        "fmt"
22
        "sort"
23

24
        corev1 "k8s.io/api/core/v1"
25
        "k8s.io/apimachinery/pkg/labels"
26
        "sigs.k8s.io/controller-runtime/pkg/client"
27

28
        nvidiav1alpha1 "github.com/NVIDIA/gpu-operator/api/nvidia/v1alpha1"
29
)
30

31
// Validator provides interface to validate NVIDIADriver fields
32
type Validator interface {
33
        Validate(ctx context.Context, cr *nvidiav1alpha1.NVIDIADriver) error
34
}
35

36
// nodeSelectorValidator validates against the nodeSelector
37
type nodeSelectorValidator struct {
38
        client client.Client
39
}
40

41
// NewNodeSelectorValidator returns a new instance of nodeselector validator
42
func NewNodeSelectorValidator(c client.Client) Validator {
1✔
43
        return &nodeSelectorValidator{client: c}
1✔
44
}
1✔
45

46
// Check returns error when nodes matching with the selector labels of current instance of NVIDIADriver
47
// are conflicting with other instances of NVIDIADriver
48
func (nsv *nodeSelectorValidator) Validate(ctx context.Context, cr *nvidiav1alpha1.NVIDIADriver) error {
1✔
49
        if err := cr.ValidateNodeSelector(); err != nil {
2✔
50
                return err
1✔
51
        }
1✔
52

53
        drivers := &nvidiav1alpha1.NVIDIADriverList{}
1✔
54
        err := nsv.client.List(ctx, drivers)
1✔
55
        if err != nil {
1✔
56
                return err
×
57
        }
×
58

59
        selectedNodeOwners := map[string][]string{}
1✔
60
        for _, driver := range drivers.Items {
2✔
61
                if err := driver.ValidateNodeSelector(); err != nil {
1✔
NEW
62
                        return err
×
NEW
63
                }
×
64
                if driver.IsDefault() {
2✔
65
                        continue
1✔
66
                }
67
                driverName := driver.Name
1✔
68
                nodeList, err := nsv.getNVIDIADriverSelectedNodes(ctx, driver)
1✔
69
                if err != nil {
1✔
70
                        return err
×
71
                }
×
72

73
                for ni := range nodeList.Items {
2✔
74
                        nodeName := nodeList.Items[ni].Name
1✔
75
                        selectedNodeOwners[nodeName] = append(selectedNodeOwners[nodeName], driverName)
1✔
76
                        if len(selectedNodeOwners[nodeName]) > 1 {
2✔
77
                                sort.Strings(selectedNodeOwners[nodeName])
1✔
78
                                return fmt.Errorf("multiple NVIDIADrivers match the same node %s: %v", nodeName, selectedNodeOwners[nodeName])
1✔
79
                        }
1✔
80
                }
81

82
        }
83

84
        return nil
1✔
85
}
86

87
// getNVIDIADriverSelectedNodes returns selected nodes based on the nodeselector labels set for a given NVIDIADriver instance
88
func (nsv *nodeSelectorValidator) getNVIDIADriverSelectedNodes(ctx context.Context, cr nvidiav1alpha1.NVIDIADriver) (*corev1.NodeList, error) {
1✔
89
        nodeList := &corev1.NodeList{}
1✔
90

1✔
91
        selector := labels.Set(cr.GetNodeSelector()).AsSelector()
1✔
92

1✔
93
        opts := []client.ListOption{
1✔
94
                client.MatchingLabelsSelector{Selector: selector},
1✔
95
        }
1✔
96
        err := nsv.client.List(ctx, nodeList, opts...)
1✔
97

1✔
98
        return nodeList, err
1✔
99
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc