@@ -346,7 +346,7 @@ 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
-
349
+
350
350
// Requeue all OperatorGroups in the namespace
351
351
logger .Debug ("requeueing operatorgroups in namespace" )
352
352
operatorGroups , err := a .lister .OperatorsV1alpha2 ().OperatorGroupLister ().OperatorGroups (csv .GetNamespace ()).List (labels .Everything ())
@@ -406,6 +406,26 @@ func (a *Operator) handleClusterServiceVersionDeletion(obj interface{}) {
406
406
a .csvQueueSet .Requeue (clusterServiceVersion .GetName (), namespace )
407
407
}
408
408
}
409
+
410
+ for _ , desc := range clusterServiceVersion .Spec .APIServiceDefinitions .Owned {
411
+ apiServiceName := fmt .Sprintf ("%s.%s" , desc .Version , desc .Group )
412
+ fetched , err := a .lister .APIRegistrationV1 ().APIServiceLister ().Get (apiServiceName )
413
+ if k8serrors .IsNotFound (err ) {
414
+ continue
415
+ }
416
+ if err != nil {
417
+ logger .WithError (err ).Warn ("api service get failure" )
418
+ continue
419
+ }
420
+ apiServiceLabels := fetched .GetLabels ()
421
+ if clusterServiceVersion .GetName () == apiServiceLabels [ownerutil .OwnerKey ] && clusterServiceVersion .GetNamespace () == apiServiceLabels [ownerutil .OwnerNamespaceKey ] {
422
+ logger .Infof ("gcing api service %v" , apiServiceName )
423
+ err := a .OpClient .DeleteAPIService (apiServiceName , & metav1.DeleteOptions {})
424
+ if err != nil {
425
+ logger .WithError (err ).Warn ("cannot delete orphaned api service" )
426
+ }
427
+ }
428
+ }
409
429
}
410
430
411
431
func (a * Operator ) removeDanglingChildCSVs (csv * v1alpha1.ClusterServiceVersion ) error {
@@ -548,9 +568,9 @@ func (a *Operator) operatorGroupForActiveCSV(logger *logrus.Entry, csv *v1alpha1
548
568
logger .Info ("no olm.targetNamespaces annotation" )
549
569
return nil
550
570
}
551
-
571
+
552
572
// Target namespaces don't match
553
- if targets != strings .Join (operatorGroup .Status .Namespaces , "," ) {
573
+ if targets != strings .Join (operatorGroup .Status .Namespaces , "," ) {
554
574
logger .Info ("olm.targetNamespaces annotation doesn't match operatorgroup status" )
555
575
return nil
556
576
}
@@ -636,7 +656,7 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
636
656
targets , ok := out .GetAnnotations ()[v1alpha2 .OperatorGroupTargetsAnnotationKey ]
637
657
if ok {
638
658
namespaces := strings .Split (targets , "," )
639
-
659
+
640
660
if err := modeSet .Supports (out .GetNamespace (), namespaces ); err != nil {
641
661
logger .WithField ("reason" , err .Error ()).Info ("installmodeset does not support operatorgroups namespace selection" )
642
662
if out .Status .Reason != v1alpha1 .CSVReasonUnsupportedOperatorGroup {
0 commit comments