@@ -55,13 +55,16 @@ type Lifecycle struct {
5555func (l * Lifecycle ) Create (obj * v3.KontainerDriver ) (runtime.Object , error ) {
5656 logrus .Infof ("create kontainerdriver %v" , obj .Name )
5757
58- v3 .KontainerDriverConditionDownloaded .Unknown (obj )
59- v3 .KontainerDriverConditionInstalled .Unknown (obj )
60-
58+ // return early if driver is not active
59+ // set driver to a non-transitioning state
6160 if ! obj .Spec .Active {
61+ v3 .KontainerDriverConditionInactive .True (obj )
6262 return obj , nil
6363 }
6464
65+ v3 .KontainerDriverConditionDownloaded .Unknown (obj )
66+ v3 .KontainerDriverConditionInstalled .Unknown (obj )
67+
6568 // Update status
6669 obj , err := l .kontainerDrivers .Update (obj )
6770 if err != nil {
@@ -351,15 +354,17 @@ func (l *Lifecycle) Updated(obj *v3.KontainerDriver) (runtime.Object, error) {
351354 return obj , l .updateDynamicSchema (obj )
352355 }
353356
354- // redownload file if url changed or not downloaded
357+ // redownload file if active AND url changed or not downloaded
358+ // prevents downloading on air-gapped installations
355359 var err error
356- if obj .Spec .URL != obj .Status .ActualURL || v3 .KontainerDriverConditionDownloaded .IsFalse (obj ) || ! l .driverExists (obj ) {
360+ if obj .Spec .Active && ( obj . Spec . URL != obj .Status .ActualURL || v3 .KontainerDriverConditionDownloaded .IsFalse (obj ) || ! l .driverExists (obj ) ) {
357361 obj , err = l .download (obj )
358362 if err != nil {
359363 return nil , err
360364 }
361365 }
362-
366+ // Create schema if obj is active
367+ // Delete schema if obj is inactive
363368 if obj .Spec .Active {
364369 err = l .createDynamicSchema (obj )
365370
@@ -368,7 +373,6 @@ func (l *Lifecycle) Updated(obj *v3.KontainerDriver) (runtime.Object, error) {
368373 if err = l .dynamicSchemas .Delete (getDynamicTypeName (obj ), & v13.DeleteOptions {}); err != nil && ! errors .IsNotFound (err ) {
369374 return nil , fmt .Errorf ("error deleting schema: %v" , err )
370375 }
371-
372376 if err = l .removeFieldFromCluster (obj ); err != nil {
373377 return nil , err
374378 }
@@ -424,6 +428,7 @@ func (l *Lifecycle) Remove(obj *v3.KontainerDriver) (runtime.Object, error) {
424428 return obj , nil
425429}
426430
431+ // Removes the v3/dynamicschema "cluster"'s resourceField associated with the KontainerDriver obj
427432func (l * Lifecycle ) removeFieldFromCluster (obj * v3.KontainerDriver ) error {
428433 nodedriver .SchemaLock .Lock ()
429434 defer nodedriver .SchemaLock .Unlock ()
@@ -432,7 +437,7 @@ func (l *Lifecycle) removeFieldFromCluster(obj *v3.KontainerDriver) error {
432437
433438 nodeSchema , err := l .dynamicSchemasLister .Get ("" , "cluster" )
434439 if err != nil {
435- return fmt .Errorf ("error getting schema: %v" , err )
440+ return fmt .Errorf ("error getting schema: %v" , err ) // this error may fire during Rancher startup
436441 }
437442
438443 nodeSchema = nodeSchema .DeepCopy ()
0 commit comments