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

NVIDIA / gpu-operator / 29513807383

16 Jul 2026 03:58PM UTC coverage: 32.688% (+0.9%) from 31.812%
29513807383

Pull #2571

github

karthikvetrivel
Add golden render tests for GPUCluster operand manifests

Signed-off-by: Karthik Vetrivel <kvetrivel@nvidia.com>
Pull Request #2571: Add GPUCluster CRD and controller for DRA-based stack

513 of 1343 new or added lines in 31 files covered. (38.2%)

5 existing lines in 4 files now uncovered.

4663 of 14265 relevant lines covered (32.69%)

0.37 hits per line

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

58.14
/internal/state/gpucluster.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 state
18

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

23
        appsv1 "k8s.io/api/apps/v1"
24
        corev1 "k8s.io/api/core/v1"
25
        "sigs.k8s.io/controller-runtime/pkg/client"
26
        "sigs.k8s.io/controller-runtime/pkg/handler"
27
        "sigs.k8s.io/controller-runtime/pkg/source"
28

29
        nvidiav1alpha1 "github.com/NVIDIA/gpu-operator/api/nvidia/v1alpha1"
30
        "github.com/NVIDIA/gpu-operator/controllers/clusterinfo"
31
)
32

33
// Helpers shared by the GPUCluster operand states (DRA driver, DCGM, ...).
34

35
const (
36
        // draAdminNamespaceLabelKey is the label the kube-scheduler requires on a namespace
37
        // before it allows adminAccess: true in ResourceClaim/ResourceClaimTemplate objects.
38
        draAdminNamespaceLabelKey = "resource.kubernetes.io/admin-access"
39
)
40

41
// dcgmEnabled reports whether the standalone DCGM hostengine operand is enabled.
42
// The DRA stack defaults it to disabled, so it does not use the reused v1
43
// DCGMSpec.IsEnabled() (which treats a nil Enabled as enabled).
44
func dcgmEnabled(cr *nvidiav1alpha1.GPUCluster) bool {
1✔
45
        return cr.Spec.DCGM != nil && cr.Spec.DCGM.Enabled != nil && *cr.Spec.DCGM.Enabled
1✔
46
}
1✔
47

48
// ensureAdminAccessLabel patches the operator namespace with the label required by the
49
// kube-scheduler to allow adminAccess: true in ResourceClaim/ResourceClaimTemplate
50
// objects. The label is deliberately never removed: it is namespace-level configuration
51
// that other adminAccess consumers in the namespace may rely on.
52
func ensureAdminAccessLabel(ctx context.Context, k8sClient client.Client, namespace string) error {
1✔
53
        ns := &corev1.Namespace{}
1✔
54
        if err := k8sClient.Get(ctx, client.ObjectKey{Name: namespace}, ns); err != nil {
1✔
NEW
55
                return fmt.Errorf("could not get namespace %s: %w", namespace, err)
×
NEW
56
        }
×
57
        if ns.Labels[draAdminNamespaceLabelKey] == "true" {
1✔
NEW
58
                return nil
×
NEW
59
        }
×
60
        patch := client.MergeFrom(ns.DeepCopy())
1✔
61
        if ns.Labels == nil {
2✔
62
                ns.Labels = make(map[string]string)
1✔
63
        }
1✔
64
        ns.Labels[draAdminNamespaceLabelKey] = "true"
1✔
65
        return k8sClient.Patch(ctx, ns, patch)
1✔
66
}
67

68
// gpuClusterDaemonSetSource watches DaemonSets and enqueues the owning
69
// GPUCluster. Every operand state returns the same source; the manager
70
// deduplicates them by key.
NEW
71
func gpuClusterDaemonSetSource(mgr ctrlManager) map[string]SyncingSource {
×
NEW
72
        return map[string]SyncingSource{
×
NEW
73
                "DaemonSet": source.Kind(
×
NEW
74
                        mgr.GetCache(),
×
NEW
75
                        &appsv1.DaemonSet{},
×
NEW
76
                        handler.TypedEnqueueRequestForOwner[*appsv1.DaemonSet](mgr.GetScheme(), mgr.GetRESTMapper(),
×
NEW
77
                                &nvidiav1alpha1.GPUCluster{}, handler.OnlyControllerOwner()),
×
NEW
78
                ),
×
NEW
79
        }
×
NEW
80
}
×
81

82
// draResourceAPIVersion returns the resource.k8s.io apiVersion served by the cluster,
83
// erroring when Dynamic Resource Allocation is not available.
84
func draResourceAPIVersion(infoCatalog InfoCatalog) (string, error) {
1✔
85
        info := infoCatalog.Get(InfoTypeClusterInfo)
1✔
86
        if info == nil {
1✔
NEW
87
                return "", fmt.Errorf("failed to get cluster info from info catalog")
×
NEW
88
        }
×
89
        clusterInfo := info.(clusterinfo.Interface)
1✔
90

1✔
91
        gvr, draSupported, err := clusterInfo.GetDRAResourceGVR()
1✔
92
        if err != nil {
1✔
NEW
93
                return "", fmt.Errorf("failed to determine DRA support: %w", err)
×
NEW
94
        }
×
95
        if !draSupported {
2✔
96
                return "", fmt.Errorf("the resource.k8s.io DeviceClass API is not served by the cluster; " +
1✔
97
                        "ensure Dynamic Resource Allocation is enabled on the API server and kubelet")
1✔
98
        }
1✔
99
        return gvr.Group + "/" + gvr.Version, nil
1✔
100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc