Skip to content

Commit

Permalink
Change index func to return list of ns instead
Browse files Browse the repository at this point in the history
Signed-off-by: Vu Dinh <vdinh@redhat.com>
  • Loading branch information
dinhxuanvu committed Dec 2, 2019
1 parent 0edefe6 commit 5bb767a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/operators/catalog/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,11 @@ func (o *Operator) syncSourceState(state grpc.SourceState) {
switch state.State {
case connectivity.Ready:
if o.namespace == state.Key.Namespace {
subs, err := index.CatalogSubscriberNamespaces(o.catalogSubscriberIndexer,
namespaces, err := index.CatalogSubscriberNamespaces(o.catalogSubscriberIndexer,
state.Key.Name, state.Key.Namespace)

if err == nil {
for _, ns := range subs {
for ns := range namespaces {
o.nsResolveQueue.Add(ns)
}
}
Expand Down
22 changes: 10 additions & 12 deletions pkg/lib/index/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,22 @@ const (
// PresentCatalogIndexFunc returns index from CatalogSource/CatalogSourceNamespace
// of the given object (Subscription)
func PresentCatalogIndexFunc(obj interface{}) ([]string, error) {
indicies := []string{}

sub, ok := obj.(*v1alpha1.Subscription)
if !ok {
return indicies, fmt.Errorf("invalid object of type: %T", obj)
return []string{""}, fmt.Errorf("invalid object of type: %T", obj)
}

indicies = append(indicies, fmt.Sprintf("%s/%s", sub.Spec.CatalogSource,
sub.Spec.CatalogSourceNamespace))
if sub.Spec.CatalogSource != "" && sub.Spec.CatalogSourceNamespace != "" {
return []string{sub.Spec.CatalogSource + "/" + sub.Spec.CatalogSourceNamespace}, nil
}

return indicies, nil
return []string{""}, nil
}

// CatalogSubscriberNamespaces returns the list of Suscriptions' name and namespace
// (name/namespace as key and namespace as value) that uses the given CatalogSource (name/namespace)
func CatalogSubscriberNamespaces(indexers map[string]cache.Indexer, name, namespace string) (map[string]string, error) {
nsSet := map[string]string{}
// CatalogSubscriberNamespaces returns the list of namespace (as a map with namespace as key)
// which has Suscriptions(s) that subscribe(s) to a given CatalogSource (name/namespace)
func CatalogSubscriberNamespaces(indexers map[string]cache.Indexer, name, namespace string) (map[string]struct{}, error) {
nsSet := map[string]struct{}{}
index := fmt.Sprintf("%s/%s", name, namespace)

for _, indexer := range indexers {
Expand All @@ -46,8 +45,7 @@ func CatalogSubscriberNamespaces(indexers map[string]cache.Indexer, name, namesp
continue
}
// Add to set
key := fmt.Sprintf("%s/%s", s.GetName(), s.GetNamespace())
nsSet[key] = s.GetNamespace()
nsSet[s.GetNamespace()] = struct{}{}
}
}

Expand Down

0 comments on commit 5bb767a

Please sign in to comment.