@@ -42,11 +42,15 @@ import (
4242// FakeConditionUpdater implements conditions.Updater
4343// It always returns CustomError if set
4444type FakeConditionUpdater struct {
45- CustomError error
45+ CustomError error
46+ LastErrorState nvidiav1alpha1.State
4647}
4748
4849// SetConditionsError always returns CustomError if set
4950func (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