Skip to content

Commit bf8a7f8

Browse files
committed
Add e2e test case to test multiple dependencies with same package
Signed-off-by: Vu Dinh <[email protected]>
1 parent d5fe81d commit bf8a7f8

File tree

2 files changed

+140
-6
lines changed

2 files changed

+140
-6
lines changed

pkg/controller/registry/registry_client.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
1212
)
1313

14-
var _ RegistryClientInterface = &OLMRegistryClient{}
15-
1614
type ChannelEntryStream interface {
1715
Recv() (*registryapi.ChannelEntry, error)
1816
}
@@ -57,6 +55,8 @@ func NewRegistryClient(client *client.Client) *OLMRegistryClient {
5755
return &OLMRegistryClient{Client: client}
5856
}
5957

58+
var _ RegistryClientInterface = &OLMRegistryClient{}
59+
6060
// GetLatestChannelEntriesThatProvide uses registry client to get a list of
6161
// latest channel entries that provide the requested API (via an iterator)
6262
func (rc *OLMRegistryClient) GetLatestChannelEntriesThatProvide(ctx context.Context, group, version, kind string) (*ChannelEntryIterator, error) {
@@ -74,9 +74,8 @@ func (rc *OLMRegistryClient) FindBundleThatProvides(ctx context.Context, group,
7474
if err != nil {
7575
return nil, err
7676
}
77-
78-
entry := FilterChannelEntries(it, pkgName)
79-
if entry != nil {
77+
entry := rc.filterChannelEntries(it, pkgName)
78+
if entry == nil {
8079
return nil, fmt.Errorf("Unable to find a channel entry which doesn't belong to package %s", pkgName)
8180
}
8281
bundle, err := rc.Client.Registry.GetBundle(ctx, &registryapi.GetBundleRequest{PkgName: entry.PackageName, ChannelName: entry.ChannelName, CsvName: entry.BundleName})
@@ -89,7 +88,7 @@ func (rc *OLMRegistryClient) FindBundleThatProvides(ctx context.Context, group,
8988
// FilterChannelEntries filters out a channel entries that provide the requested
9089
// API and come from the same package with original operator and returns the
9190
// first entry on the list
92-
func FilterChannelEntries(it *ChannelEntryIterator, pkgName string) *opregistry.ChannelEntry {
91+
func (rc *OLMRegistryClient) filterChannelEntries(it *ChannelEntryIterator, pkgName string) *opregistry.ChannelEntry {
9392
var entry *opregistry.ChannelEntry
9493
for e := it.Next(); e != nil; e = it.Next() {
9594
if e.PackageName != pkgName {

test/e2e/subscription_e2e_test.go

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,141 @@ var _ = Describe("Subscription", func() {
12651265
require.NoError(GinkgoT(), err)
12661266
require.Len(GinkgoT(), installPlan.Status.CatalogSources, 1)
12671267
})
1268+
1269+
FIt("creation with multiple dependencies", func() {
1270+
1271+
defer cleaner.NotifyTestComplete(GinkgoT(), true)
1272+
1273+
kubeClient := newKubeClient(GinkgoT())
1274+
crClient := newCRClient(GinkgoT())
1275+
1276+
permissions := deploymentPermissions()
1277+
1278+
crdPlural := genName("ins")
1279+
crdName := crdPlural + ".cluster.com"
1280+
crdPlural2 := genName("ins")
1281+
crdName2 := crdPlural2 + ".cluster.com"
1282+
1283+
crd := apiextensions.CustomResourceDefinition{
1284+
ObjectMeta: metav1.ObjectMeta{
1285+
Name: crdName,
1286+
},
1287+
Spec: apiextensions.CustomResourceDefinitionSpec{
1288+
Group: "cluster.com",
1289+
Version: "v1alpha1",
1290+
Names: apiextensions.CustomResourceDefinitionNames{
1291+
Plural: crdPlural,
1292+
Singular: crdPlural,
1293+
Kind: crdPlural,
1294+
ListKind: "list" + crdPlural,
1295+
},
1296+
Scope: "Namespaced",
1297+
},
1298+
}
1299+
1300+
crd2 := apiextensions.CustomResourceDefinition{
1301+
ObjectMeta: metav1.ObjectMeta{
1302+
Name: crdName2,
1303+
},
1304+
Spec: apiextensions.CustomResourceDefinitionSpec{
1305+
Group: "cluster.com",
1306+
Version: "v1alpha1",
1307+
Names: apiextensions.CustomResourceDefinitionNames{
1308+
Plural: crdPlural2,
1309+
Singular: crdPlural2,
1310+
Kind: crdPlural2,
1311+
ListKind: "list" + crdPlural2,
1312+
},
1313+
Scope: "Namespaced",
1314+
},
1315+
}
1316+
1317+
// Create CSV
1318+
packageName1 := genName("apackage")
1319+
packageName2 := genName("bpackage")
1320+
1321+
namedStrategy := newNginxInstallStrategy((genName("dep")), permissions, nil)
1322+
depNamedStrategy := newNginxInstallStrategy((genName("dep")), permissions, nil)
1323+
depNamedStrategy2 := newNginxInstallStrategy((genName("dep")), permissions, nil)
1324+
csvA := newCSV("nginx-a", testNamespace, "", semver.MustParse("0.1.0"), nil, []apiextensions.CustomResourceDefinition{crd, crd2}, namedStrategy)
1325+
csvAB := newCSV("nginx-a-b", testNamespace, "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{crd}, nil, namedStrategy)
1326+
csvB := newCSV("nginx-b-dep", testNamespace, "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{crd}, nil, depNamedStrategy)
1327+
csvC := newCSV("nginx-c-dep", testNamespace, "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{crd2}, nil, depNamedStrategy2)
1328+
1329+
// Create PackageManifests
1330+
manifests := []registry.PackageManifest{
1331+
{
1332+
PackageName: packageName1,
1333+
Channels: []registry.PackageChannel{
1334+
{Name: stableChannel, CurrentCSVName: csvA.GetName()},
1335+
{Name: alphaChannel, CurrentCSVName: csvAB.GetName()},
1336+
},
1337+
DefaultChannelName: stableChannel,
1338+
},
1339+
{
1340+
PackageName: packageName2,
1341+
Channels: []registry.PackageChannel{
1342+
{Name: stableChannel, CurrentCSVName: csvB.GetName()},
1343+
},
1344+
DefaultChannelName: stableChannel,
1345+
},
1346+
}
1347+
1348+
manifests2 := []registry.PackageManifest{
1349+
{
1350+
PackageName: packageName2,
1351+
Channels: []registry.PackageChannel{
1352+
{Name: stableChannel, CurrentCSVName: csvC.GetName()},
1353+
},
1354+
DefaultChannelName: stableChannel,
1355+
},
1356+
}
1357+
1358+
catalogSourceName := genName("catsrc")
1359+
catsrc, cleanup := createInternalCatalogSource(GinkgoT(), kubeClient, crClient, catalogSourceName, testNamespace, manifests, []apiextensions.CustomResourceDefinition{crd, crd2}, []v1alpha1.ClusterServiceVersion{csvA, csvAB, csvB})
1360+
defer cleanup()
1361+
1362+
// Ensure that the catalog source is resolved before we create a subscription.
1363+
_, err := fetchCatalogSource(GinkgoT(), crClient, catsrc.GetName(), testNamespace, catalogSourceRegistryPodSynced)
1364+
require.NoError(GinkgoT(), err)
1365+
1366+
subscriptionSpec := &v1alpha1.SubscriptionSpec{
1367+
CatalogSource: catsrc.GetName(),
1368+
CatalogSourceNamespace: catsrc.GetNamespace(),
1369+
Package: packageName1,
1370+
Channel: stableChannel,
1371+
StartingCSV: csvA.GetName(),
1372+
InstallPlanApproval: v1alpha1.ApprovalAutomatic,
1373+
}
1374+
1375+
catalogSourceName2 := genName("catsrc")
1376+
catsrc2, cleanup2 := createInternalCatalogSource(GinkgoT(), kubeClient, crClient, catalogSourceName2, testNamespace, manifests2, []apiextensions.CustomResourceDefinition{crd2}, []v1alpha1.ClusterServiceVersion{csvC})
1377+
defer cleanup2()
1378+
1379+
// Ensure that the catalog source is resolved before we create a subscription.
1380+
_, err = fetchCatalogSource(GinkgoT(), crClient, catsrc2.GetName(), testNamespace, catalogSourceRegistryPodSynced)
1381+
require.NoError(GinkgoT(), err)
1382+
1383+
// Create a subscription that has a dependency
1384+
subscriptionName := genName("sub-")
1385+
cleanupSubscription := createSubscriptionForCatalogWithSpec(GinkgoT(), crClient, testNamespace, subscriptionName, subscriptionSpec)
1386+
defer cleanupSubscription()
1387+
1388+
subscription, err := fetchSubscription(GinkgoT(), crClient, testNamespace, subscriptionName, subscriptionStateAtLatestChecker)
1389+
require.NoError(GinkgoT(), err)
1390+
require.NotNil(GinkgoT(), subscription)
1391+
1392+
// Check that a single catalog source was used to resolve the InstallPlan
1393+
_, err = fetchInstallPlan(GinkgoT(), crClient, subscription.Status.InstallPlanRef.Name, buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseComplete))
1394+
require.NoError(GinkgoT(), err)
1395+
// Fetch CSVs
1396+
_, err = fetchCSV(GinkgoT(), crClient, csvB.Name, testNamespace, csvSucceededChecker)
1397+
require.NoError(GinkgoT(), err)
1398+
_, err = fetchCSV(GinkgoT(), crClient, csvC.Name, testNamespace, csvSucceededChecker)
1399+
require.NoError(GinkgoT(), err)
1400+
_, err = fetchCSV(GinkgoT(), crClient, csvA.Name, testNamespace, csvSucceededChecker)
1401+
require.NoError(GinkgoT(), err)
1402+
})
12681403
})
12691404

12701405
const (

0 commit comments

Comments
 (0)