-
Notifications
You must be signed in to change notification settings - Fork 527
Support NVIDIADriver reconciliation and driver upgrades without a ClusterPolicy #2572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
karthikvetrivel
wants to merge
3
commits into
main
Choose a base branch
from
kv-nvidiadriver-standalone
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -64,6 +64,7 @@ type NVIDIADriverReconciler struct { | |||||
| //+kubebuilder:rbac:groups=nvidia.com,resources=nvidiadrivers,verbs=get;list;watch;create;update;patch;delete | ||||||
| //+kubebuilder:rbac:groups=nvidia.com,resources=nvidiadrivers/status,verbs=get;update;patch | ||||||
| //+kubebuilder:rbac:groups=nvidia.com,resources=nvidiadrivers/finalizers,verbs=update | ||||||
| //+kubebuilder:rbac:groups=nvidia.com,resources=gpuclusters,verbs=get;list;watch | ||||||
|
|
||||||
| // Reconcile is part of the main kubernetes reconciliation loop which aims to | ||||||
| // move the current state of the cluster closer to the desired state. | ||||||
|
|
@@ -98,45 +99,26 @@ func (r *NVIDIADriverReconciler) Reconcile(ctx context.Context, req ctrl.Request | |||||
| return reconcile.Result{}, nil | ||||||
| } | ||||||
|
|
||||||
| // Get the singleton NVIDIA ClusterPolicy object in the cluster. | ||||||
| clusterPolicyList := &gpuv1.ClusterPolicyList{} | ||||||
| if err := r.List(ctx, clusterPolicyList); err != nil { | ||||||
| wrappedErr := fmt.Errorf("error getting ClusterPolicy list: %w", err) | ||||||
| logger.Error(err, "error getting ClusterPolicy list") | ||||||
| instance.Status.State = nvidiav1alpha1.NotReady | ||||||
| if condErr := r.conditionUpdater.SetConditionsError(ctx, instance, conditions.ReconcileFailed, err.Error()); condErr != nil { | ||||||
| logger.Error(condErr, "failed to set condition") | ||||||
| } | ||||||
| return reconcile.Result{}, wrappedErr | ||||||
| } | ||||||
|
|
||||||
| if len(clusterPolicyList.Items) == 0 { | ||||||
| err := fmt.Errorf("no ClusterPolicy object found in the cluster") | ||||||
| logger.Error(err, "failed to get ClusterPolicy object") | ||||||
| // Source the cluster-wide host root from the active configuration: a ClusterPolicy takes | ||||||
| // precedence, otherwise the controller runs standalone against the GPUCluster. | ||||||
| clusterPolicy, gpuCluster, err := resolveActiveConfig(ctx, r.Client) | ||||||
| if err != nil { | ||||||
| logger.Error(err, "error resolving active cluster configuration") | ||||||
| instance.Status.State = nvidiav1alpha1.NotReady | ||||||
| if condErr := r.conditionUpdater.SetConditionsError(ctx, instance, conditions.ReconcileFailed, err.Error()); condErr != nil { | ||||||
| logger.Error(condErr, "failed to set condition") | ||||||
| } | ||||||
| return reconcile.Result{}, err | ||||||
| } | ||||||
| clusterPolicyInstance := clusterPolicyList.Items[0] | ||||||
|
|
||||||
| // Ensure the NVIDIADriver CR has a consumer: either the ClusterPolicy delegates its | ||||||
| // driver to the NVIDIADriver CRD, or a GPUCluster exists. GPUCluster does | ||||||
| // not manage the driver itself — it is either preinstalled on the host (no NVIDIADriver | ||||||
| // CR) or installed via NVIDIADriver CRs, so any CR that exists alongside one is in use. | ||||||
| if !clusterPolicyInstance.Spec.Driver.UseNvidiaDriverCRDType() { | ||||||
| gpuClusters := &nvidiav1alpha1.GPUClusterList{} | ||||||
| if err := r.List(ctx, gpuClusters); err != nil { | ||||||
| wrappedErr := fmt.Errorf("error getting GPUCluster list: %w", err) | ||||||
| logger.Error(err, "error getting GPUCluster list") | ||||||
| instance.Status.State = nvidiav1alpha1.NotReady | ||||||
| if condErr := r.conditionUpdater.SetConditionsError(ctx, instance, conditions.ReconcileFailed, err.Error()); condErr != nil { | ||||||
| logger.Error(condErr, "failed to set condition") | ||||||
| } | ||||||
| return reconcile.Result{}, wrappedErr | ||||||
| } | ||||||
| if len(gpuClusters.Items) == 0 { | ||||||
| var hostRoot string | ||||||
| switch { | ||||||
| case clusterPolicy != nil: | ||||||
| if !clusterPolicy.Spec.Driver.UseNvidiaDriverCRDType() && gpuCluster == nil { | ||||||
| msg := "useNvidiaDriverCRD is not enabled in ClusterPolicy and no GPUCluster exists" | ||||||
| logger.V(consts.LogLevelWarning).Info("NVIDIADriver reconciliation skipped", "reason", msg) | ||||||
| instance.Status.State = nvidiav1alpha1.Disabled | ||||||
|
|
@@ -145,6 +127,17 @@ func (r *NVIDIADriverReconciler) Reconcile(ctx context.Context, req ctrl.Request | |||||
| } | ||||||
| return reconcile.Result{}, nil | ||||||
| } | ||||||
| hostRoot = clusterPolicy.Spec.HostPaths.RootFS | ||||||
| case gpuCluster != nil: | ||||||
| hostRoot = gpuCluster.Spec.HostPaths.RootFS | ||||||
| default: | ||||||
| err := fmt.Errorf("no ClusterPolicy or GPUCluster object found in the cluster") | ||||||
| logger.Error(err, "failed to get a cluster-wide configuration object") | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| instance.Status.State = nvidiav1alpha1.NotReady | ||||||
| if condErr := r.conditionUpdater.SetConditionsError(ctx, instance, conditions.ReconcileFailed, err.Error()); condErr != nil { | ||||||
| logger.Error(condErr, "failed to set condition") | ||||||
| } | ||||||
| return reconcile.Result{}, err | ||||||
| } | ||||||
|
|
||||||
| // Create a new InfoCatalog which is a generic interface for passing information to state managers | ||||||
|
|
@@ -153,8 +146,8 @@ func (r *NVIDIADriverReconciler) Reconcile(ctx context.Context, req ctrl.Request | |||||
| // Add an entry for ClusterInfo, which was collected before the NVIDIADriver controller was started | ||||||
| infoCatalog.Add(state.InfoTypeClusterInfo, r.ClusterInfo) | ||||||
|
|
||||||
| // Add an entry for Clusterpolicy, which is needed to deploy the driver daemonset | ||||||
| infoCatalog.Add(state.InfoTypeClusterPolicyCR, clusterPolicyInstance) | ||||||
| // Add the host root, which is needed to deploy the driver daemonset | ||||||
| infoCatalog.Add(state.InfoTypeHostRoot, hostRoot) | ||||||
|
|
||||||
| // Verify the nodeSelector configured for this NVIDIADriver instance does | ||||||
| // not conflict with any other instances. This ensures only one driver | ||||||
|
|
@@ -405,6 +398,7 @@ func (r *NVIDIADriverReconciler) SetupWithManager(ctx context.Context, mgr ctrl. | |||||
| gpuClusterMapFn := func(ctx context.Context, _ *nvidiav1alpha1.GPUCluster) []reconcile.Request { | ||||||
| return r.enqueueAllNVIDIADrivers(ctx) | ||||||
| } | ||||||
|
|
||||||
| err = c.Watch( | ||||||
| source.Kind( | ||||||
| mgr.GetCache(), | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I am wrong, but in the scenario where both ClusterPolicy and GPUCluster exist, will the
.spec.hostPaths.rootFSfrom GPUCluster have the higher order of precedence?