-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable multiple namespaces sync if catsrc is updated in global ns
Currently, if CatalogSource is updated and connection is Ready, only the namespace where CatalogSource resides gets resynced. Now, a list of namespaces that contain Subscriptions that use updated CatalogSource will get resynced instead. Signed-off-by: Vu Dinh <vdinh@redhat.com>
- Loading branch information
1 parent
1debd99
commit cfd087c
Showing
2 changed files
with
111 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package indexer | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1" | ||
"k8s.io/client-go/tools/cache" | ||
) | ||
|
||
const ( | ||
// PresentCatalogIndexFuncKey is the recommended key to use for registering | ||
// the index func with an indexer. | ||
PresentCatalogIndexFuncKey string = "presentcatalogindexfunc" | ||
) | ||
|
||
// PresentCatalogIndexFunc returns index from CatalogSource/CatalogSourceNamespace | ||
// of the given object (Subscription) | ||
func PresentCatalogIndexFunc(obj interface{}) ([]string, error) { | ||
sub, ok := obj.(*v1alpha1.Subscription) | ||
if !ok { | ||
return []string{""}, fmt.Errorf("invalid object of type: %T", obj) | ||
} | ||
|
||
index := fmt.Sprintf("%s/%s", sub.Spec.CatalogSource, sub.Spec.CatalogSourceNamespace) | ||
|
||
return []string{index}, nil | ||
} | ||
|
||
// CatalogSubscriberNamespaces returns the list of namespaces of Subscription(s) | ||
// that uses the given CatalogSource (name/namespace) | ||
func CatalogSubscriberNamespaces(indexers map[string]cache.Indexer, name, namespace string) (map[string]struct{}, error) { | ||
nsSet := map[string]struct{}{} | ||
var index string | ||
|
||
index = fmt.Sprintf("%s/%s", name, namespace) | ||
|
||
for _, indexer := range indexers { | ||
subs, err := indexer.ByIndex(PresentCatalogIndexFuncKey, index) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, item := range subs { | ||
s, ok := item.(*v1alpha1.Subscription) | ||
if !ok { | ||
continue | ||
} | ||
if s.Spec.CatalogSource == "" || s.Spec.CatalogSourceNamespace == "" { | ||
continue | ||
} | ||
// Add to set | ||
nsSet[s.GetNamespace()] = struct{}{} | ||
} | ||
} | ||
|
||
return nsSet, nil | ||
} |