Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/gpu-operator/main.go
Comment thread
rajathagasthya marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func main() {
clusterUpgradeStateManager, err := upgrade.NewClusterUpgradeStateManager(
upgradeLogger,
mgr.GetConfig(),
mgr.GetClient(),
// nolint:staticcheck
// TODO: update k8s-operator-libs to leverage events.EventRecorder instead
mgr.GetEventRecorderFor("nvidia-gpu-operator"),
Expand Down
14 changes: 10 additions & 4 deletions controllers/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,25 @@ func New(config *rest.Config, options ctrlcache.Options) (ctrlcache.Cache, error
return ctrlcache.New(config, options)
}

// stripUnusedNodeFields keeps only the Node fields that the operator reads.
func stripUnusedNodeFields(in any) (any, error) {
node, ok := in.(*corev1.Node)
if !ok {
return in, nil
}

runtimeVersion := node.Status.NodeInfo.ContainerRuntimeVersion
var conditions []corev1.NodeCondition
for _, condition := range node.Status.Conditions {
if condition.Type == corev1.NodeReady {
conditions = append(conditions, corev1.NodeCondition{Type: condition.Type, Status: condition.Status})
}
}
node.ManagedFields = nil
node.Spec = corev1.NodeSpec{}
node.Spec = corev1.NodeSpec{Unschedulable: node.Spec.Unschedulable}
node.Status = corev1.NodeStatus{
NodeInfo: corev1.NodeSystemInfo{ContainerRuntimeVersion: runtimeVersion},
NodeInfo: corev1.NodeSystemInfo{ContainerRuntimeVersion: runtimeVersion},
Conditions: conditions,
}
return node, nil
}
Expand All @@ -85,8 +93,6 @@ func Options(operatorNamespace string) ctrlcache.Options {
DefaultTransform: stripManagedFields,
ByObject: map[client.Object]ctrlcache.ByObject{
&corev1.Node{}: {
// The operator reads only the container runtime version from node
// status. Drop all other status data from the cached object.
Transform: stripUnusedNodeFields,
},
&corev1.Pod{}: {Namespaces: cachedNamespaces},
Expand Down
20 changes: 14 additions & 6 deletions controllers/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,16 @@ func TestCache(t *testing.T) {
},
Spec: corev1.NodeSpec{Unschedulable: true},
Status: corev1.NodeStatus{
Capacity: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("8")},
Images: []corev1.ContainerImage{{Names: []string{"example.com/large-image:v1"}, SizeBytes: 1000000}},
NodeInfo: corev1.NodeSystemInfo{ContainerRuntimeVersion: "containerd://2.0.0", KernelVersion: "6.0.0"},
Conditions: []corev1.NodeCondition{{Type: corev1.NodeReady, Status: corev1.ConditionTrue}},
Capacity: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("8")},
Images: []corev1.ContainerImage{{Names: []string{"example.com/large-image:v1"}, SizeBytes: 1000000}},
NodeInfo: corev1.NodeSystemInfo{ContainerRuntimeVersion: "containerd://2.0.0", KernelVersion: "6.0.0"},
Conditions: []corev1.NodeCondition{
{Type: corev1.NodeMemoryPressure, Status: corev1.ConditionFalse},
{
Type: corev1.NodeReady, Status: corev1.ConditionTrue, Reason: "KubeletReady",
LastHeartbeatTime: metav1.NewTime(time.Unix(1700000000, 0)),
},
},
},
}
configMap := &corev1.ConfigMap{
Expand Down Expand Up @@ -313,9 +319,11 @@ func TestCache(t *testing.T) {
require.NoError(t, cachedClient.Get(ctx, client.ObjectKey{Name: node.Name}, gotNode))
expectedNode := node.DeepCopy()
expectedNode.ManagedFields = nil
expectedNode.Spec = corev1.NodeSpec{}
// The upgrade library needs Spec.Unschedulable and the Ready condition.
expectedNode.Spec = corev1.NodeSpec{Unschedulable: true}
expectedNode.Status = corev1.NodeStatus{
NodeInfo: corev1.NodeSystemInfo{ContainerRuntimeVersion: node.Status.NodeInfo.ContainerRuntimeVersion},
NodeInfo: corev1.NodeSystemInfo{ContainerRuntimeVersion: node.Status.NodeInfo.ContainerRuntimeVersion},
Conditions: []corev1.NodeCondition{{Type: corev1.NodeReady, Status: corev1.ConditionTrue}},
}
require.Equal(t, expectedNode.ObjectMeta, gotNode.ObjectMeta)
require.Equal(t, expectedNode.Spec, gotNode.Spec)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/Masterminds/sprig/v3 v3.3.0
github.com/NVIDIA/go-nvlib v0.13.0
github.com/NVIDIA/k8s-kata-manager v0.2.3
github.com/NVIDIA/k8s-operator-libs v0.0.0-20260629200812-d720f2557494
github.com/NVIDIA/k8s-operator-libs v0.0.0-20261113163306-991fa4a9a29a
github.com/NVIDIA/nvidia-container-toolkit v1.20.2
github.com/cyphar/filepath-securejoin v0.7.0
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ github.com/NVIDIA/go-nvlib v0.13.0 h1:veqetT7p2m+u7yPVAtXQ/nLAqotTdZF1+RzpLd1Yci
github.com/NVIDIA/go-nvlib v0.13.0/go.mod h1:OmA7IhiBevXA4jUElFQjwmAZJLqrIAofyyn9MvRcz7s=
github.com/NVIDIA/k8s-kata-manager v0.2.3 h1:d5+gRFqU5el/fKMXhHUaPY7haj+dbHL4nDsO/q05LBo=
github.com/NVIDIA/k8s-kata-manager v0.2.3/go.mod h1:xx5OUiMsHyKbyX0JjKHqAftvqS8vx00LFn/5EaMdtB4=
github.com/NVIDIA/k8s-operator-libs v0.0.0-20260629200812-d720f2557494 h1:j+tWK79l9AouBulQps7rxILLhy2fWYcEhH4zgYjth/o=
github.com/NVIDIA/k8s-operator-libs v0.0.0-20260629200812-d720f2557494/go.mod h1:L+aiCiTKN63AX9SWz/F8pv9Jw9FIfI+dAEr7VA+KowE=
github.com/NVIDIA/k8s-operator-libs v0.0.0-20261113163306-991fa4a9a29a h1:PJTguzSwWLxQYBw/QNlqaRECYaK+CuDmsWpO67SZkbQ=
github.com/NVIDIA/k8s-operator-libs v0.0.0-20261113163306-991fa4a9a29a/go.mod h1:TfactzFEcVt03/Qi40SkwOawkVVTXfNZJvhkS7hzTaM=
github.com/NVIDIA/nvidia-container-toolkit v1.20.2 h1:ndvx+2v4c8HmRf8A5aONf1+sE32jNDZ7qnIaBEAN5i8=
github.com/NVIDIA/nvidia-container-toolkit v1.20.2/go.mod h1:q/O2jOSbK8JeHYhHMWwhuwof0yXzs7VE5uVjfSZriDw=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ github.com/NVIDIA/go-nvlib/pkg/pciids
# github.com/NVIDIA/k8s-kata-manager v0.2.3
## explicit; go 1.23.0
github.com/NVIDIA/k8s-kata-manager/api/v1alpha1/config
# github.com/NVIDIA/k8s-operator-libs v0.0.0-20260629200812-d720f2557494
# github.com/NVIDIA/k8s-operator-libs v0.0.0-20261113163306-991fa4a9a29a
## explicit; go 1.26.0
github.com/NVIDIA/k8s-operator-libs/api/upgrade/v1alpha1
github.com/NVIDIA/k8s-operator-libs/pkg/consts
Expand Down
Loading