Skip to content

Commit 9258f5f

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

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

12581393
const (

0 commit comments

Comments
 (0)