@@ -1402,11 +1402,9 @@ func TestCreateNewSubscriptionWithDependencies(t *testing.T) {
1402
1402
require .Len (t , installPlan .Status .CatalogSources , 1 )
1403
1403
}
1404
1404
1405
- // Test creation with dependencies required and provided in different versions of an
1406
- // operator in the same package
1407
- // CatSrc:
1405
+ // CatSrc1:
1408
1406
//
1409
- // Package A (apackage)
1407
+ // Package 1 (apackage)
1410
1408
// Default Channel: Stable
1411
1409
// Channel Stable:
1412
1410
// Operator A (Requires: CRD 1, CRD 2 )
@@ -1416,12 +1414,19 @@ func TestCreateNewSubscriptionWithDependencies(t *testing.T) {
1416
1414
// Default Channel: Stable
1417
1415
// Channel Stable:
1418
1416
// Operator B (Provides: CRD)
1419
- // CatSrc2:
1417
+ // Channel Alpha:
1418
+ // Operator D (Provides: CRD)
1420
1419
//
1421
- // Package B (bpackage)
1420
+ // CatSrc2:
1421
+ // Package 2 (bpackage)
1422
1422
// Default Channel: Stable
1423
1423
// Channel Stable:
1424
1424
// Operator C (Provides: CRD 2)
1425
+ // Package 3 (cpackage)
1426
+ // Default Channel: Stable
1427
+ // Channel Stable:
1428
+ // Operator E (Provides: CRD 2)
1429
+ //
1425
1430
// Then create a subscription:
1426
1431
//
1427
1432
// CatalogSource: CatSrc
@@ -1430,10 +1435,11 @@ func TestCreateNewSubscriptionWithDependencies(t *testing.T) {
1430
1435
// StartingCSV: CSV A
1431
1436
//
1432
1437
// Check installed:
1438
+ // CSV A, CSV B, CSV E
1433
1439
//
1434
- // CSV A, CSV B, CSV C
1435
- //
1436
- // CSV A required B and C but didn't get them from Package A
1440
+ // CSV ABC: not chosen as it is the same package with CSV A
1441
+ // CSV D: not chosen as it is in non-default channel
1442
+ // CSV C: not chosen as it is the same package with CSV B (which is chosen)
1437
1443
func TestCreateNewSubscriptionWithDependenciesSamePackage (t * testing.T ) {
1438
1444
defer cleaner .NotifyTestComplete (t , true )
1439
1445
@@ -1484,6 +1490,7 @@ func TestCreateNewSubscriptionWithDependenciesSamePackage(t *testing.T) {
1484
1490
// Create CSV
1485
1491
packageName1 := genName ("apackage" )
1486
1492
packageName2 := genName ("bpackage" )
1493
+ packageName3 := genName ("cpackage" )
1487
1494
1488
1495
namedStrategy := newNginxInstallStrategy ((genName ("dep" )), permissions , nil )
1489
1496
depNamedStrategy := newNginxInstallStrategy ((genName ("dep" )), permissions , nil )
@@ -1499,6 +1506,8 @@ func TestCreateNewSubscriptionWithDependenciesSamePackage(t *testing.T) {
1499
1506
csvC := newCSV ("nginx-c-dep" , testNamespace , "" , semver .MustParse ("0.1.0" ), []apiextensions.CustomResourceDefinition {crd2 }, nil , depNamedStrategy2 )
1500
1507
// csvD provides CRD1 in the same catalogsource with csvA (apackage)
1501
1508
csvD := newCSV ("nginx-d-dep" , testNamespace , "" , semver .MustParse ("0.1.0" ), []apiextensions.CustomResourceDefinition {crd }, nil , depNamedStrategy )
1509
+ // csvE provides CRD2 in the different catalogsource with csvC (bpackage)
1510
+ csvE := newCSV ("nginx-e-dep" , testNamespace , "" , semver .MustParse ("0.1.0" ), []apiextensions.CustomResourceDefinition {crd2 }, nil , depNamedStrategy2 )
1502
1511
1503
1512
// Create PackageManifests 1
1504
1513
// Contain csvA, ABC and B
@@ -1531,6 +1540,13 @@ func TestCreateNewSubscriptionWithDependenciesSamePackage(t *testing.T) {
1531
1540
},
1532
1541
DefaultChannelName : stableChannel ,
1533
1542
},
1543
+ {
1544
+ PackageName : packageName3 ,
1545
+ Channels : []registry.PackageChannel {
1546
+ {Name : stableChannel , CurrentCSVName : csvE .GetName ()},
1547
+ },
1548
+ DefaultChannelName : stableChannel ,
1549
+ },
1534
1550
}
1535
1551
1536
1552
catalogSourceName := genName ("catsrc" )
@@ -1551,7 +1567,7 @@ func TestCreateNewSubscriptionWithDependenciesSamePackage(t *testing.T) {
1551
1567
}
1552
1568
1553
1569
catalogSourceName2 := genName ("catsrc" )
1554
- catsrc2 , cleanup2 := createInternalCatalogSource (t , kubeClient , crClient , catalogSourceName2 , testNamespace , manifests2 , []apiextensions.CustomResourceDefinition {crd2 }, []v1alpha1.ClusterServiceVersion {csvC })
1570
+ catsrc2 , cleanup2 := createInternalCatalogSource (t , kubeClient , crClient , catalogSourceName2 , testNamespace , manifests2 , []apiextensions.CustomResourceDefinition {crd2 }, []v1alpha1.ClusterServiceVersion {csvC , csvE })
1555
1571
defer cleanup2 ()
1556
1572
1557
1573
// Ensure that the catalog source is resolved before we create a subscription.
@@ -1573,7 +1589,7 @@ func TestCreateNewSubscriptionWithDependenciesSamePackage(t *testing.T) {
1573
1589
// Fetch CSVs A, B and C
1574
1590
_ , err = fetchCSV (t , crClient , csvB .Name , testNamespace , csvSucceededChecker )
1575
1591
require .NoError (t , err )
1576
- _ , err = fetchCSV (t , crClient , csvC .Name , testNamespace , csvSucceededChecker )
1592
+ _ , err = fetchCSV (t , crClient , csvE .Name , testNamespace , csvSucceededChecker )
1577
1593
require .NoError (t , err )
1578
1594
_ , err = fetchCSV (t , crClient , csvA .Name , testNamespace , csvSucceededChecker )
1579
1595
require .NoError (t , err )
@@ -1585,6 +1601,191 @@ func TestCreateNewSubscriptionWithDependenciesSamePackage(t *testing.T) {
1585
1601
require .Error (t , err )
1586
1602
}
1587
1603
1604
+ // csvA owns CRD1 & csvB owns CRD2 and requires CRD1
1605
+ // Create subscription for csvB lead to installation of csvB and csvA
1606
+ // Update catsrc to upgrade csvA to csvNewA which now requires CRD1
1607
+ // csvNewA can't be installed due to no other operators provide CRD1 for it
1608
+ // (Note: OLM can't pick csvA as dependency for csvNewA as it is from the same
1609
+ // same package)
1610
+ // Update catsrc again to upgrade csvB to csvNewB which now owns both CRD1 and
1611
+ // CRD2.
1612
+ // Now csvNewA and csvNewB are installed successfully as csvNewB provides CRD1
1613
+ // that csvNewA requires
1614
+ func TestCreateNewSubscriptionWithTransferredDependencies (t * testing.T ) {
1615
+
1616
+ defer cleaner .NotifyTestComplete (t , true )
1617
+
1618
+ kubeClient := newKubeClient (t )
1619
+ crClient := newCRClient (t )
1620
+
1621
+ permissions := deploymentPermissions (t )
1622
+
1623
+ crdPlural := genName ("ins" )
1624
+ crdName := crdPlural + ".cluster.com"
1625
+ crdPlural2 := genName ("ins" )
1626
+ crdName2 := crdPlural2 + ".cluster.com"
1627
+
1628
+ crd := apiextensions.CustomResourceDefinition {
1629
+ ObjectMeta : metav1.ObjectMeta {
1630
+ Name : crdName ,
1631
+ },
1632
+ Spec : apiextensions.CustomResourceDefinitionSpec {
1633
+ Group : "cluster.com" ,
1634
+ Version : "v1alpha1" ,
1635
+ Names : apiextensions.CustomResourceDefinitionNames {
1636
+ Plural : crdPlural ,
1637
+ Singular : crdPlural ,
1638
+ Kind : crdPlural ,
1639
+ ListKind : "list" + crdPlural ,
1640
+ },
1641
+ Scope : "Namespaced" ,
1642
+ },
1643
+ }
1644
+
1645
+ crd2 := apiextensions.CustomResourceDefinition {
1646
+ ObjectMeta : metav1.ObjectMeta {
1647
+ Name : crdName2 ,
1648
+ },
1649
+ Spec : apiextensions.CustomResourceDefinitionSpec {
1650
+ Group : "cluster.com" ,
1651
+ Version : "v1alpha1" ,
1652
+ Names : apiextensions.CustomResourceDefinitionNames {
1653
+ Plural : crdPlural2 ,
1654
+ Singular : crdPlural2 ,
1655
+ Kind : crdPlural2 ,
1656
+ ListKind : "list" + crdPlural2 ,
1657
+ },
1658
+ Scope : "Namespaced" ,
1659
+ },
1660
+ }
1661
+
1662
+ // Create CSV
1663
+ packageName1 := genName ("apackage" )
1664
+ packageName2 := genName ("bpackage" )
1665
+
1666
+ namedStrategy := newNginxInstallStrategy ((genName ("dep" )), permissions , nil )
1667
+ namedStrategy2 := newNginxInstallStrategy ((genName ("dep" )), permissions , nil )
1668
+ // csvA provides CRD
1669
+ csvA := newCSV ("nginx-a" , testNamespace , "" , semver .MustParse ("0.1.0" ), []apiextensions.CustomResourceDefinition {crd }, nil , namedStrategy )
1670
+ // csvB provides CRD2 and requires CRD
1671
+ csvB := newCSV ("nginx-b" , testNamespace , "" , semver .MustParse ("0.1.0" ), []apiextensions.CustomResourceDefinition {crd2 }, []apiextensions.CustomResourceDefinition {crd }, namedStrategy2 )
1672
+ // New csvA requires CRD (transfer CRD ownership to the new csvB)
1673
+ csvNewA := newCSV ("nginx-new-a" , testNamespace , "nginx-a" , semver .MustParse ("0.2.0" ), nil , []apiextensions.CustomResourceDefinition {crd }, namedStrategy )
1674
+ // New csvB provides CRD and CRD2
1675
+ csvNewB := newCSV ("nginx-new-b" , testNamespace , "nginx-b" , semver .MustParse ("0.2.0" ), []apiextensions.CustomResourceDefinition {crd , crd2 }, nil , namedStrategy2 )
1676
+
1677
+ // Create PackageManifests 1
1678
+ // Contain csvA, ABC and B
1679
+ manifests := []registry.PackageManifest {
1680
+ {
1681
+ PackageName : packageName1 ,
1682
+ Channels : []registry.PackageChannel {
1683
+ {Name : stableChannel , CurrentCSVName : csvA .GetName ()},
1684
+ },
1685
+ DefaultChannelName : stableChannel ,
1686
+ },
1687
+ {
1688
+ PackageName : packageName2 ,
1689
+ Channels : []registry.PackageChannel {
1690
+ {Name : stableChannel , CurrentCSVName : csvB .GetName ()},
1691
+ },
1692
+ DefaultChannelName : stableChannel ,
1693
+ },
1694
+ }
1695
+
1696
+ catalogSourceName := genName ("catsrc" )
1697
+ catsrc , cleanup := createInternalCatalogSource (t , kubeClient , crClient , catalogSourceName , testNamespace , manifests , []apiextensions.CustomResourceDefinition {crd , crd2 }, []v1alpha1.ClusterServiceVersion {csvA , csvB })
1698
+ defer cleanup ()
1699
+
1700
+ // Ensure that the catalog source is resolved before we create a subscription.
1701
+ _ , err := fetchCatalogSource (t , crClient , catsrc .GetName (), testNamespace , catalogSourceRegistryPodSynced )
1702
+ require .NoError (t , err )
1703
+
1704
+ subscriptionSpec := & v1alpha1.SubscriptionSpec {
1705
+ CatalogSource : catsrc .GetName (),
1706
+ CatalogSourceNamespace : catsrc .GetNamespace (),
1707
+ Package : packageName2 ,
1708
+ Channel : stableChannel ,
1709
+ StartingCSV : csvB .GetName (),
1710
+ InstallPlanApproval : v1alpha1 .ApprovalAutomatic ,
1711
+ }
1712
+
1713
+ // Create a subscription that has a dependency
1714
+ subscriptionName := genName ("sub-" )
1715
+ cleanupSubscription := createSubscriptionForCatalogWithSpec (t , crClient , testNamespace , subscriptionName , subscriptionSpec )
1716
+ defer cleanupSubscription ()
1717
+
1718
+ subscription , err := fetchSubscription (t , crClient , testNamespace , subscriptionName , subscriptionStateAtLatestChecker )
1719
+ require .NoError (t , err )
1720
+ require .NotNil (t , subscription )
1721
+
1722
+ // Check that a single catalog source was used to resolve the InstallPlan
1723
+ _ , err = fetchInstallPlan (t , crClient , subscription .Status .InstallPlanRef .Name , buildInstallPlanPhaseCheckFunc (v1alpha1 .InstallPlanPhaseComplete ))
1724
+ require .NoError (t , err )
1725
+ // Fetch CSVs A and B
1726
+ _ , err = fetchCSV (t , crClient , csvA .Name , testNamespace , csvSucceededChecker )
1727
+ require .NoError (t , err )
1728
+ _ , err = fetchCSV (t , crClient , csvB .Name , testNamespace , csvSucceededChecker )
1729
+ require .NoError (t , err )
1730
+
1731
+ // Update PackageManifest
1732
+ manifests = []registry.PackageManifest {
1733
+ {
1734
+ PackageName : packageName1 ,
1735
+ Channels : []registry.PackageChannel {
1736
+ {Name : stableChannel , CurrentCSVName : csvNewA .GetName ()},
1737
+ },
1738
+ DefaultChannelName : stableChannel ,
1739
+ },
1740
+ {
1741
+ PackageName : packageName2 ,
1742
+ Channels : []registry.PackageChannel {
1743
+ {Name : stableChannel , CurrentCSVName : csvB .GetName ()},
1744
+ },
1745
+ DefaultChannelName : stableChannel ,
1746
+ },
1747
+ }
1748
+ updateInternalCatalog (t , kubeClient , crClient , catalogSourceName , testNamespace , []apiextensions.CustomResourceDefinition {crd , crd2 }, []v1alpha1.ClusterServiceVersion {csvNewA , csvA , csvB }, manifests )
1749
+ csvAsub := strings .Join ([]string {packageName1 , stableChannel , catalogSourceName , testNamespace }, "-" )
1750
+ _ , err = fetchSubscription (t , crClient , testNamespace , csvAsub , subscriptionStateUpgradeAvailableChecker )
1751
+ require .NoError (t , err )
1752
+ // Ensure csvNewA is not installed
1753
+ _ , err = crClient .OperatorsV1alpha1 ().ClusterServiceVersions (testNamespace ).Get (csvNewA .Name , metav1.GetOptions {})
1754
+ require .Error (t , err )
1755
+ // Ensure csvA still exists
1756
+ _ , err = fetchCSV (t , crClient , csvA .Name , testNamespace , csvSucceededChecker )
1757
+ require .NoError (t , err )
1758
+
1759
+ // Update packagemanifest again
1760
+ manifests = []registry.PackageManifest {
1761
+ {
1762
+ PackageName : packageName1 ,
1763
+ Channels : []registry.PackageChannel {
1764
+ {Name : stableChannel , CurrentCSVName : csvNewA .GetName ()},
1765
+ },
1766
+ DefaultChannelName : stableChannel ,
1767
+ },
1768
+ {
1769
+ PackageName : packageName2 ,
1770
+ Channels : []registry.PackageChannel {
1771
+ {Name : stableChannel , CurrentCSVName : csvNewB .GetName ()},
1772
+ },
1773
+ DefaultChannelName : stableChannel ,
1774
+ },
1775
+ }
1776
+ updateInternalCatalog (t , kubeClient , crClient , catalogSourceName , testNamespace , []apiextensions.CustomResourceDefinition {crd , crd2 }, []v1alpha1.ClusterServiceVersion {csvA , csvB , csvNewA , csvNewB }, manifests )
1777
+ subscription , err = fetchSubscription (t , crClient , testNamespace , subscriptionName , subscriptionHasInstallPlanDifferentChecker (subscription .Status .InstallPlanRef .Name ))
1778
+ require .NoError (t , err )
1779
+ _ , err = fetchInstallPlan (t , crClient , subscription .Status .InstallPlanRef .Name , buildInstallPlanPhaseCheckFunc (v1alpha1 .InstallPlanPhaseComplete ))
1780
+ require .NoError (t , err )
1781
+ // Ensure csvNewB is installed
1782
+ _ , err = fetchCSV (t , crClient , csvNewB .Name , testNamespace , csvSucceededChecker )
1783
+ require .NoError (t , err )
1784
+ // Ensure csvNewA is installed
1785
+ _ , err = fetchCSV (t , crClient , csvNewA .Name , testNamespace , csvSucceededChecker )
1786
+ require .NoError (t , err )
1787
+ }
1788
+
1588
1789
func checkDeploymentWithPodConfiguration (t * testing.T , client operatorclient.ClientInterface , csv * v1alpha1.ClusterServiceVersion , envVar []corev1.EnvVar , volumes []corev1.Volume , volumeMounts []corev1.VolumeMount ) {
1589
1790
resolver := install.StrategyResolver {}
1590
1791
0 commit comments