Skip to content

Commit

Permalink
WIP fixes from comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Peeler committed Mar 18, 2019
1 parent de0afa0 commit 333850f
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions pkg/controller/operators/olm/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,20 +321,15 @@ func (a *Operator) syncAPIService(obj interface{}) (syncError error) {
})
logger.Info("syncing APIService")

serviceLabels := apiSvc.GetLabels()
owningNamespace, owned := serviceLabels[ownerutil.OwnerNamespaceKey]
if owned {
_, err := a.lister.CoreV1().NamespaceLister().Get(owningNamespace)
if name, ns, ok := ownerutil.GetOwnerByKindLabel(apiSvc, v1alpha1.ClusterServiceVersionKind); ok {
_, err := a.lister.CoreV1().NamespaceLister().Get(ns)
if k8serrors.IsNotFound(err) {
logger.Debug("Deleting api service since owning namespace is not found")
syncError = a.OpClient.DeleteAPIService(apiSvc.GetName(), &metav1.DeleteOptions{})
return
}
}

owningCSVName, owned := serviceLabels[ownerutil.OwnerKey]
if owned {
_, err := a.lister.OperatorsV1alpha1().ClusterServiceVersionLister().ClusterServiceVersions(owningNamespace).Get(owningCSVName)
_, err = a.lister.OperatorsV1alpha1().ClusterServiceVersionLister().ClusterServiceVersions(ns).Get(name)
if k8serrors.IsNotFound(err) {
logger.Debug("Deleting api service since owning CSV is not found")
syncError = a.OpClient.DeleteAPIService(apiSvc.GetName(), &metav1.DeleteOptions{})
Expand All @@ -349,6 +344,7 @@ func (a *Operator) syncAPIService(obj interface{}) (syncError error) {
}
}
}

return nil
}

Expand Down Expand Up @@ -405,22 +401,23 @@ func (a *Operator) namespaceAddedOrRemoved(obj interface{}) {
}
}
}
// TODO move to ownerutil... maybe
// find any API services owned by this namespace and requeue them
stringSelector := fmt.Sprintf("%v==%v", ownerutil.OwnerNamespaceKey, namespace.GetName())
labelSelector, err := labels.Parse(stringSelector)
if err != nil {
logger.WithError(err).Warn("parser failed")
return
}
apiServices, err := a.lister.APIRegistrationV1().APIServiceLister().List(labelSelector)
if err != nil {
logger.WithError(err).Warn("APIService lister failed")
return
}
for _, svc := range apiServices {
logger.Infof("gcing api service %v", svc.GetName())
a.apiSvcQueue.AddRateLimited(svc.GetName())
}
// stringSelector := fmt.Sprintf("%v==%v", ownerutil.OwnerNamespaceKey, namespace.GetName())
// labelSelector, err := labels.Parse(stringSelector)
// if err != nil {
// logger.WithError(err).Warn("parser failed")
// return
// }
// apiServices, err := a.lister.APIRegistrationV1().APIServiceLister().List(labelSelector)
// if err != nil {
// logger.WithError(err).Warn("APIService lister failed")
// return
// }
// for _, svc := range apiServices {
// logger.WithField("apiservice", svc.GetName()).Info("gcing api service")
// a.apiSvcQueue.Add(svc.GetName())
// }
return
}

Expand Down

0 comments on commit 333850f

Please sign in to comment.