@@ -346,6 +346,22 @@ func (a *Operator) handleClusterServiceVersionDeletion(obj interface{}) {
346
346
defer func (csv v1alpha1.ClusterServiceVersion ) {
347
347
logger .Debug ("removing csv from queue set" )
348
348
a .csvQueueSet .Remove (csv .GetName (), csv .GetNamespace ())
349
+
350
+ // Requeue all OperatorGroups in the namespace
351
+ logger .Debug ("requeueing operatorgroups in namespace" )
352
+ operatorGroups , err := a .lister .OperatorsV1alpha2 ().OperatorGroupLister ().OperatorGroups (csv .GetNamespace ()).List (labels .Everything ())
353
+ if err != nil {
354
+ logger .WithError (err ).Warnf ("an error occurred while listing operatorgroups to requeue after csv deletion" )
355
+ return
356
+ }
357
+
358
+ for _ , operatorGroup := range operatorGroups {
359
+ logger := logger .WithField ("operatorgroup" , operatorGroup .GetName ())
360
+ logger .Debug ("requeueing" )
361
+ if err := a .ogQueueSet .Requeue (operatorGroup .GetName (), operatorGroup .GetNamespace ()); err != nil {
362
+ logger .WithError (err ).Debug ("error requeueing operatorgroup" )
363
+ }
364
+ }
349
365
}(* clusterServiceVersion )
350
366
351
367
targetNamespaces , ok := clusterServiceVersion .Annotations [v1alpha2 .OperatorGroupTargetsAnnotationKey ]
@@ -360,28 +376,16 @@ func (a *Operator) handleClusterServiceVersionDeletion(obj interface{}) {
360
376
return
361
377
}
362
378
363
- operatorGroupName , ok := clusterServiceVersion .Annotations [v1alpha2 .OperatorGroupAnnotationKey ]
364
- if ! ok {
379
+ if _ , ok = clusterServiceVersion .Annotations [v1alpha2 .OperatorGroupAnnotationKey ]; ! ok {
365
380
logger .Debug ("missing operatorgroup name annotation on csv" )
366
381
return
367
382
}
368
383
369
- if clusterServiceVersion .Status . Reason == v1alpha1 . CSVReasonCopied {
384
+ if clusterServiceVersion .IsCopied () {
370
385
logger .Debug ("deleted csv is copied. skipping additional cleanup steps" )
371
386
return
372
387
}
373
388
374
- logger = logger .WithField ("operatorgroup" , operatorGroupName )
375
- logger .Info ("active csv deleted, removing providedAPIs from operatorgroup annotations" )
376
- if operatorGroup , _ := a .lister .OperatorsV1alpha2 ().OperatorGroupLister ().OperatorGroups (operatorNamespace ).Get (operatorGroupName ); operatorGroup != nil {
377
- logger .Debug ("requeueing" )
378
- if err := a .ogQueueSet .Requeue (operatorGroup .GetName (), operatorGroup .GetNamespace ()); err != nil {
379
- logger .WithError (err ).Debug ("error requeueing" )
380
- }
381
- } else {
382
- logger .Debug ("operatorgroup not found during csv deletion" )
383
- }
384
-
385
389
logger .Info ("gcing children" )
386
390
namespaces := []string {}
387
391
if targetNamespaces == "" {
@@ -524,7 +528,7 @@ func (a *Operator) operatorGroupForActiveCSV(logger *logrus.Entry, csv *v1alpha1
524
528
525
529
// No OperatorGroup annotation
526
530
if ! ok {
527
- logger .Info ("no operatorgroup annotation" )
531
+ logger .Info ("no olm.operatorGroup annotation" )
528
532
return nil
529
533
}
530
534
@@ -537,9 +541,17 @@ func (a *Operator) operatorGroupForActiveCSV(logger *logrus.Entry, csv *v1alpha1
537
541
return nil
538
542
}
539
543
544
+ targets , ok := annotations [v1alpha2 .OperatorGroupTargetsAnnotationKey ]
545
+
546
+ // No target annotation
547
+ if ! ok {
548
+ logger .Info ("no olm.targetNamespaces annotation" )
549
+ return nil
550
+ }
551
+
540
552
// Target namespaces don't match
541
- if annotations [ v1alpha2 . OperatorGroupTargetsAnnotationKey ] != strings .Join (operatorGroup .Status .Namespaces , "," ) {
542
- logger .Info ("target namespace annotation doesn't match operatorgroup namespace list " )
553
+ if targets != strings .Join (operatorGroup .Status .Namespaces , "," ) {
554
+ logger .Info ("olm.targetNamespaces annotation doesn't match operatorgroup status " )
543
555
return nil
544
556
}
545
557
@@ -590,46 +602,54 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
590
602
operatorGroup = operatorGroups [0 ]
591
603
logger = logger .WithField ("opgroup" , operatorGroup .GetName ())
592
604
593
- a .addOperatorGroupAnnotations (& out .ObjectMeta , operatorGroup , true )
594
- _ , err = a .client .OperatorsV1alpha1 ().ClusterServiceVersions (out .GetNamespace ()).Update (out )
595
- if err != nil {
596
- logger .Error ("error adding operatorgroup annotation" )
597
- syncError = err
605
+ if a .operatorGroupAnnotationsDiffer (& out .ObjectMeta , operatorGroup ) {
606
+ a .setOperatorGroupAnnotations (& out .ObjectMeta , operatorGroup , true )
607
+ if _ , err := a .client .OperatorsV1alpha1 ().ClusterServiceVersions (out .GetNamespace ()).Update (out ); err != nil {
608
+ logger .WithError (err ).Warn ("error adding operatorgroup annotations" )
609
+ syncError = err
610
+ }
598
611
}
612
+
599
613
return
600
614
}
601
615
logger .Info ("csv in operatorgroup" )
602
616
default :
603
617
syncError = fmt .Errorf ("csv created in namespace with multiple operatorgroups, can't pick one automatically" )
604
- logger .Warn (syncError .Error ())
605
- out .SetPhaseWithEvent (v1alpha1 .CSVPhaseFailed , v1alpha1 .CSVReasonTooManyOperatorGroups , syncError .Error (), now , a .recorder )
618
+ logger .WithError (syncError ).Warn ("csv failed to become an operatorgroup member" )
619
+ if out .Status .Reason != v1alpha1 .CSVReasonTooManyOperatorGroups {
620
+ out .SetPhaseWithEvent (v1alpha1 .CSVPhaseFailed , v1alpha1 .CSVReasonTooManyOperatorGroups , syncError .Error (), now , a .recorder )
621
+ }
606
622
return
607
623
}
608
624
609
625
modeSet , err := v1alpha1 .NewInstallModeSet (out .Spec .InstallModes )
610
626
if err != nil {
611
627
syncError = err
612
- logger .Warn (err .Error ())
613
- out .SetPhaseWithEvent (v1alpha1 .CSVPhaseFailed , v1alpha1 .CSVReasonInvalidInstallModes , syncError .Error (), now , a .recorder )
628
+ logger .WithError (err ).Warn ("csv has invalid installmodes" )
629
+ if out .Status .Reason != v1alpha1 .CSVReasonInvalidInstallModes {
630
+ out .SetPhaseWithEvent (v1alpha1 .CSVPhaseFailed , v1alpha1 .CSVReasonInvalidInstallModes , syncError .Error (), now , a .recorder )
631
+ }
614
632
return
615
633
}
616
634
617
635
// Check if the CSV supports its operatorgroup's selected namespaces
618
636
targets , ok := out .GetAnnotations ()[v1alpha2 .OperatorGroupTargetsAnnotationKey ]
619
637
if ok {
620
638
namespaces := strings .Split (targets , "," )
621
- err = modeSet . Supports ( out . GetNamespace (), namespaces )
622
- if err != nil {
623
- logger .WithField ("reason" , err .Error ()).Infof ( "InstallModeSet does not support OperatorGroup namespace selection" )
639
+
640
+ if err := modeSet . Supports ( out . GetNamespace (), namespaces ); err != nil {
641
+ logger .WithField ("reason" , err .Error ()).Info ( "installmodeset does not support operatorgroups namespace selection" )
624
642
if out .Status .Reason != v1alpha1 .CSVReasonUnsupportedOperatorGroup {
625
643
out .SetPhaseWithEvent (v1alpha1 .CSVPhaseFailed , v1alpha1 .CSVReasonUnsupportedOperatorGroup , err .Error (), now , a .recorder )
626
644
}
627
645
return
628
646
}
629
647
} else {
630
- // This should never be the case
631
- logger .Info ("no targets annotation defined for CSV" )
632
- out .SetPhaseWithEvent (v1alpha1 .CSVPhaseFailed , v1alpha1 .CSVReasonNoTargetNamespaces , err .Error (), now , a .recorder )
648
+ logger .Info ("csv missing olm.targetNamespaces annotation" )
649
+ if out .Status .Reason != v1alpha1 .CSVReasonNoTargetNamespaces {
650
+ out .SetPhaseWithEvent (v1alpha1 .CSVPhaseFailed , v1alpha1 .CSVReasonNoTargetNamespaces , "csv missing olm.targetNamespaces annotation" , now , a .recorder )
651
+ }
652
+ return
633
653
}
634
654
635
655
// Check for intersecting provided APIs in intersecting OperatorGroups
0 commit comments