Skip to content

Commit 6b74117

Browse files
authored
Merge pull request #2289 from rahulait/fix-status-on-conflict
Set NVIDIADriver status to NotReady on selector conflict
2 parents 691aa75 + 30e43f5 commit 6b74117

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

controllers/nvidiadriver_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func (r *NVIDIADriverReconciler) Reconcile(ctx context.Context, req ctrl.Request
145145
// is deployed per GPU node.
146146
if err := r.nodeSelectorValidator.Validate(ctx, instance); err != nil {
147147
logger.Error(err, "nodeSelector validation failed")
148+
instance.Status.State = nvidiav1alpha1.NotReady
148149
if condErr := r.conditionUpdater.SetConditionsError(ctx, instance, conditions.ConflictingNodeSelector, err.Error()); condErr != nil {
149150
logger.Error(condErr, "failed to set condition")
150151
}

controllers/nvidiadriver_controller_test.go

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ import (
4242
// FakeConditionUpdater implements conditions.Updater
4343
// It always returns CustomError if set
4444
type FakeConditionUpdater struct {
45-
CustomError error
45+
CustomError error
46+
LastErrorState nvidiav1alpha1.State
4647
}
4748

4849
// SetConditionsError always returns CustomError if set
4950
func (f *FakeConditionUpdater) SetConditionsError(ctx context.Context, obj any, condType, msg string) error {
51+
if driver, ok := obj.(*nvidiav1alpha1.NVIDIADriver); ok {
52+
f.LastErrorState = driver.Status.State
53+
}
5054
return f.CustomError
5155
}
5256

@@ -193,3 +197,51 @@ func TestReconcile(t *testing.T) {
193197
})
194198
}
195199
}
200+
201+
func TestReconcileConflictSetsNotReadyState(t *testing.T) {
202+
scheme := runtime.NewScheme()
203+
require.NoError(t, nvidiav1alpha1.AddToScheme(scheme))
204+
require.NoError(t, gpuv1.AddToScheme(scheme))
205+
206+
driver := &nvidiav1alpha1.NVIDIADriver{
207+
ObjectMeta: metav1.ObjectMeta{
208+
Name: "test-driver",
209+
Namespace: "default",
210+
},
211+
Status: nvidiav1alpha1.NVIDIADriverStatus{
212+
State: nvidiav1alpha1.Ready,
213+
},
214+
}
215+
216+
cp := &gpuv1.ClusterPolicy{
217+
ObjectMeta: metav1.ObjectMeta{Name: "default"},
218+
Spec: gpuv1.ClusterPolicySpec{
219+
Driver: gpuv1.DriverSpec{
220+
UseNvidiaDriverCRD: ptr.To(true),
221+
},
222+
},
223+
}
224+
225+
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(cp, driver).Build()
226+
updater := &FakeConditionUpdater{}
227+
228+
reconciler := &NVIDIADriverReconciler{
229+
Client: client,
230+
Scheme: scheme,
231+
conditionUpdater: updater,
232+
nodeSelectorValidator: &FakeNodeSelectorValidator{
233+
CustomError: errors.New("conflicting selector"),
234+
},
235+
}
236+
237+
req := ctrl.Request{
238+
NamespacedName: types.NamespacedName{
239+
Name: driver.Name,
240+
Namespace: driver.Namespace,
241+
},
242+
}
243+
244+
_, err := reconciler.Reconcile(context.Background(), req)
245+
require.NoError(t, err)
246+
require.Equal(t, nvidiav1alpha1.NotReady, updater.LastErrorState)
247+
}

0 commit comments

Comments
 (0)