Skip to content

Commit 45f0689

Browse files
committed
Change index func to return list of ns instead
Signed-off-by: Vu Dinh <[email protected]>
1 parent 0edefe6 commit 45f0689

File tree

3 files changed

+27
-28
lines changed

3 files changed

+27
-28
lines changed

pkg/controller/operators/catalog/operator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,11 @@ func (o *Operator) syncSourceState(state grpc.SourceState) {
348348
switch state.State {
349349
case connectivity.Ready:
350350
if o.namespace == state.Key.Namespace {
351-
subs, err := index.CatalogSubscriberNamespaces(o.catalogSubscriberIndexer,
351+
namespaces, err := index.CatalogSubscriberNamespaces(o.catalogSubscriberIndexer,
352352
state.Key.Name, state.Key.Namespace)
353353

354354
if err == nil {
355-
for _, ns := range subs {
355+
for ns := range namespaces {
356356
o.nsResolveQueue.Add(ns)
357357
}
358358
}

pkg/lib/index/catalog.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,22 @@ const (
1616
// PresentCatalogIndexFunc returns index from CatalogSource/CatalogSourceNamespace
1717
// of the given object (Subscription)
1818
func PresentCatalogIndexFunc(obj interface{}) ([]string, error) {
19-
indicies := []string{}
20-
2119
sub, ok := obj.(*v1alpha1.Subscription)
2220
if !ok {
23-
return indicies, fmt.Errorf("invalid object of type: %T", obj)
21+
return []string{""}, fmt.Errorf("invalid object of type: %T", obj)
2422
}
2523

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

29-
return indicies, nil
28+
return []string{""}, nil
3029
}
3130

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

3837
for _, indexer := range indexers {
@@ -46,8 +45,7 @@ func CatalogSubscriberNamespaces(indexers map[string]cache.Indexer, name, namesp
4645
continue
4746
}
4847
// Add to set
49-
key := fmt.Sprintf("%s/%s", s.GetName(), s.GetNamespace())
50-
nsSet[key] = s.GetNamespace()
48+
nsSet[s.GetNamespace()] = struct{}{}
5149
}
5250
}
5351

test/e2e/catalog_e2e_test.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,27 @@ func TestGlobalCatalogUpdateTriggersSubscriptionSync(t *testing.T) {
138138
Package: mainPackageName,
139139
Channel: stableChannel,
140140
StartingCSV: mainCSV.GetName(),
141-
InstallPlanApproval: v1alpha1.ApprovalAutomatic,
141+
InstallPlanApproval: v1alpha1.ApprovalManual,
142142
}
143143

144144
// Create Subscription
145145
subscriptionName := genName("sub-")
146146
createSubscriptionForCatalogWithSpec(t, crc, testNamespace, subscriptionName, subscriptionSpec)
147147

148-
subscription, err := fetchSubscription(t, crc, testNamespace, subscriptionName, subscriptionStateAtLatestChecker)
148+
subscription, err := fetchSubscription(t, crc, testNamespace, subscriptionName, subscriptionHasInstallPlanChecker)
149149
require.NoError(t, err)
150150
require.NotNil(t, subscription)
151-
_, err = fetchCSV(t, crc, subscription.Status.CurrentCSV, testNamespace, buildCSVConditionChecker(v1alpha1.CSVPhaseSucceeded))
151+
152+
installPlanName := subscription.Status.Install.Name
153+
requiresApprovalChecker := buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseRequiresApproval)
154+
fetchedInstallPlan, err := fetchInstallPlan(t, crc, installPlanName, requiresApprovalChecker)
155+
require.NoError(t, err)
156+
157+
fetchedInstallPlan.Spec.Approved = true
158+
_, err = crc.OperatorsV1alpha1().InstallPlans(testNamespace).Update(fetchedInstallPlan)
159+
require.NoError(t, err)
160+
161+
_, err = awaitCSV(t, crc, testNamespace, mainCSV.GetName(), csvSucceededChecker)
152162
require.NoError(t, err)
153163

154164
// Update manifest
@@ -166,19 +176,10 @@ func TestGlobalCatalogUpdateTriggersSubscriptionSync(t *testing.T) {
166176
updateInternalCatalog(t, c, crc, mainCatalogName, globalNS, []apiextensions.CustomResourceDefinition{mainCRD}, []v1alpha1.ClusterServiceVersion{mainCSV, replacementCSV}, mainManifests)
167177

168178
// Get updated catalogsource
169-
fetchedUpdatedCatalog, err := fetchCatalogSource(t, crc, mainCatalogName, globalNS, func(catalog *v1alpha1.CatalogSource) bool {
170-
registry := catalog.Status.RegistryServiceStatus
171-
connState := catalog.Status.GRPCConnectionState
172-
if registry != nil && connState != nil && connState.LastObservedState == "READY" && !connState.LastConnectTime.IsZero() {
173-
fmt.Printf("catalog %s pod with address %s\n", catalog.GetName(), registry.Address())
174-
return registryPodHealthy(registry.Address())
175-
}
176-
fmt.Printf("waiting for catalog pod %v to be available (for sync)\n", catalog.GetName())
177-
return false
178-
})
179+
fetchedUpdatedCatalog, err := fetchCatalogSource(t, crc, mainCatalogName, globalNS, catalogSourceRegistryPodSynced)
179180
require.NoError(t, err)
180181

181-
subscription, err = fetchSubscription(t, crc, testNamespace, subscriptionName, subscriptionStateUpgradeAvailableChecker)
182+
subscription, err = fetchSubscription(t, crc, testNamespace, subscriptionName, subscriptionStateUpgradePendingChecker)
182183
require.NoError(t, err)
183184
require.NotNil(t, subscription)
184185

0 commit comments

Comments
 (0)