Skip to content

Commit 5cbe455

Browse files
authored
Merge pull request #548 from dinhxuanvu/multi-crd-test
Add test case for supporting multi-version CRD
2 parents 23a067a + fd37f2b commit 5cbe455

File tree

1 file changed

+227
-0
lines changed

1 file changed

+227
-0
lines changed

test/e2e/csv_e2e_test.go

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,4 +1429,231 @@ func TestUpdateCSVMultipleIntermediates(t *testing.T) {
14291429
require.NoError(t, err)
14301430
}
14311431

1432+
func TestUpdateCSVMultipleVersionCRD(t *testing.T) {
1433+
defer cleaner.NotifyTestComplete(t, true)
1434+
1435+
c := newKubeClient(t)
1436+
crc := newCRClient(t)
1437+
1438+
// Create initial CRD which has 2 versions: v1alpha1 & v1alpha2
1439+
crdPlural := genName("ins4")
1440+
crdName := crdPlural + ".cluster.com"
1441+
cleanupCRD, err := createCRD(c, extv1beta1.CustomResourceDefinition{
1442+
ObjectMeta: metav1.ObjectMeta{
1443+
Name: crdName,
1444+
},
1445+
Spec: extv1beta1.CustomResourceDefinitionSpec{
1446+
Group: "cluster.com",
1447+
Versions: []extv1beta1.CustomResourceDefinitionVersion{
1448+
{
1449+
Name: "v1alpha1",
1450+
Served: true,
1451+
Storage: true,
1452+
},
1453+
{
1454+
Name: "v1alpha2",
1455+
Served: true,
1456+
Storage: false,
1457+
},
1458+
},
1459+
Names: extv1beta1.CustomResourceDefinitionNames{
1460+
Plural: crdPlural,
1461+
Singular: crdPlural,
1462+
Kind: crdPlural,
1463+
ListKind: "list" + crdPlural,
1464+
},
1465+
Scope: "Namespaced",
1466+
},
1467+
})
1468+
require.NoError(t, err)
1469+
defer cleanupCRD()
1470+
1471+
// create initial deployment strategy
1472+
strategy := install.StrategyDetailsDeployment{
1473+
DeploymentSpecs: []install.StrategyDeploymentSpec{
1474+
{
1475+
Name: genName("dep1-"),
1476+
Spec: newNginxDeployment(genName("nginx-")),
1477+
},
1478+
},
1479+
}
1480+
strategyRaw, err := json.Marshal(strategy)
1481+
require.NoError(t, err)
1482+
1483+
// First CSV with owning CRD v1alpha1
1484+
csv := v1alpha1.ClusterServiceVersion{
1485+
TypeMeta: metav1.TypeMeta{
1486+
Kind: v1alpha1.ClusterServiceVersionKind,
1487+
APIVersion: v1alpha1.ClusterServiceVersionAPIVersion,
1488+
},
1489+
ObjectMeta: metav1.ObjectMeta{
1490+
Name: genName("csv"),
1491+
},
1492+
Spec: v1alpha1.ClusterServiceVersionSpec{
1493+
InstallStrategy: v1alpha1.NamedInstallStrategy{
1494+
StrategyName: install.InstallStrategyNameDeployment,
1495+
StrategySpecRaw: strategyRaw,
1496+
},
1497+
CustomResourceDefinitions: v1alpha1.CustomResourceDefinitions{
1498+
Owned: []v1alpha1.CRDDescription{
1499+
{
1500+
Name: crdName,
1501+
Version: "v1alpha1",
1502+
Kind: crdPlural,
1503+
DisplayName: crdName,
1504+
Description: "In the cluster4",
1505+
},
1506+
},
1507+
},
1508+
},
1509+
}
1510+
1511+
// CSV will be deleted by the upgrade process later
1512+
_, err = createCSV(t, c, crc, csv, testNamespace, true)
1513+
require.NoError(t, err)
1514+
1515+
// Wait for current CSV to succeed
1516+
_, err = fetchCSV(t, crc, csv.Name, csvSucceededChecker)
1517+
require.NoError(t, err)
1518+
1519+
// Should have created deployment
1520+
dep, err := c.GetDeployment(testNamespace, strategy.DeploymentSpecs[0].Name)
1521+
require.NoError(t, err)
1522+
require.NotNil(t, dep)
1523+
1524+
// Create updated deployment strategy
1525+
strategyNew := install.StrategyDetailsDeployment{
1526+
DeploymentSpecs: []install.StrategyDeploymentSpec{
1527+
{
1528+
Name: genName("dep2-"),
1529+
Spec: newNginxDeployment(genName("nginx-")),
1530+
},
1531+
},
1532+
}
1533+
strategyNewRaw, err := json.Marshal(strategyNew)
1534+
require.NoError(t, err)
1535+
1536+
// Second CSV with owning CRD v1alpha1 and v1alpha2
1537+
csvNew := v1alpha1.ClusterServiceVersion{
1538+
TypeMeta: metav1.TypeMeta{
1539+
Kind: v1alpha1.ClusterServiceVersionKind,
1540+
APIVersion: v1alpha1.ClusterServiceVersionAPIVersion,
1541+
},
1542+
ObjectMeta: metav1.ObjectMeta{
1543+
Name: genName("csv2"),
1544+
},
1545+
Spec: v1alpha1.ClusterServiceVersionSpec{
1546+
Replaces: csv.Name,
1547+
InstallStrategy: v1alpha1.NamedInstallStrategy{
1548+
StrategyName: install.InstallStrategyNameDeployment,
1549+
StrategySpecRaw: strategyNewRaw,
1550+
},
1551+
CustomResourceDefinitions: v1alpha1.CustomResourceDefinitions{
1552+
Owned: []v1alpha1.CRDDescription{
1553+
{
1554+
Name: crdName,
1555+
Version: "v1alpha1",
1556+
Kind: crdPlural,
1557+
DisplayName: crdName,
1558+
Description: "In the cluster4",
1559+
},
1560+
{
1561+
Name: crdName,
1562+
Version: "v1alpha2",
1563+
Kind: crdPlural,
1564+
DisplayName: crdName,
1565+
Description: "In the cluster4",
1566+
},
1567+
},
1568+
},
1569+
},
1570+
}
1571+
1572+
// Create newly updated CSV
1573+
_, err = createCSV(t, c, crc, csvNew, testNamespace, true)
1574+
require.NoError(t, err)
1575+
1576+
// Wait for updated CSV to succeed
1577+
fetchedCSV, err := fetchCSV(t, crc, csvNew.Name, csvSucceededChecker)
1578+
require.NoError(t, err)
1579+
1580+
// Fetch cluster service version again to check for unnecessary control loops
1581+
sameCSV, err := fetchCSV(t, crc, csvNew.Name, csvSucceededChecker)
1582+
require.NoError(t, err)
1583+
compareResources(t, fetchedCSV, sameCSV)
1584+
1585+
// Should have created new deployment and deleted old one
1586+
depNew, err := c.GetDeployment(testNamespace, strategyNew.DeploymentSpecs[0].Name)
1587+
require.NoError(t, err)
1588+
require.NotNil(t, depNew)
1589+
err = waitForDeploymentToDelete(t, c, strategy.DeploymentSpecs[0].Name)
1590+
require.NoError(t, err)
1591+
1592+
// Create updated deployment strategy
1593+
strategyNew2 := install.StrategyDetailsDeployment{
1594+
DeploymentSpecs: []install.StrategyDeploymentSpec{
1595+
{
1596+
Name: genName("dep3-"),
1597+
Spec: newNginxDeployment(genName("nginx-")),
1598+
},
1599+
},
1600+
}
1601+
strategyNewRaw2, err := json.Marshal(strategyNew2)
1602+
require.NoError(t, err)
1603+
1604+
// Third CSV with owning CRD v1alpha2
1605+
csvNew2 := v1alpha1.ClusterServiceVersion{
1606+
TypeMeta: metav1.TypeMeta{
1607+
Kind: v1alpha1.ClusterServiceVersionKind,
1608+
APIVersion: v1alpha1.ClusterServiceVersionAPIVersion,
1609+
},
1610+
ObjectMeta: metav1.ObjectMeta{
1611+
Name: genName("csv3"),
1612+
},
1613+
Spec: v1alpha1.ClusterServiceVersionSpec{
1614+
Replaces: csvNew.Name,
1615+
InstallStrategy: v1alpha1.NamedInstallStrategy{
1616+
StrategyName: install.InstallStrategyNameDeployment,
1617+
StrategySpecRaw: strategyNewRaw2,
1618+
},
1619+
CustomResourceDefinitions: v1alpha1.CustomResourceDefinitions{
1620+
Owned: []v1alpha1.CRDDescription{
1621+
{
1622+
Name: crdName,
1623+
Version: "v1alpha2",
1624+
Kind: crdPlural,
1625+
DisplayName: crdName,
1626+
Description: "In the cluster4",
1627+
},
1628+
},
1629+
},
1630+
},
1631+
}
1632+
1633+
// Create newly updated CSV
1634+
cleanupNewCSV, err := createCSV(t, c, crc, csvNew2, testNamespace, true)
1635+
require.NoError(t, err)
1636+
defer cleanupNewCSV()
1637+
1638+
// Wait for updated CSV to succeed
1639+
fetchedCSV, err = fetchCSV(t, crc, csvNew2.Name, csvSucceededChecker)
1640+
require.NoError(t, err)
1641+
1642+
// Fetch cluster service version again to check for unnecessary control loops
1643+
sameCSV, err = fetchCSV(t, crc, csvNew2.Name, csvSucceededChecker)
1644+
require.NoError(t, err)
1645+
compareResources(t, fetchedCSV, sameCSV)
1646+
1647+
// Should have created new deployment and deleted old one
1648+
depNew, err = c.GetDeployment(testNamespace, strategyNew2.DeploymentSpecs[0].Name)
1649+
require.NoError(t, err)
1650+
require.NotNil(t, depNew)
1651+
err = waitForDeploymentToDelete(t, c, strategyNew.DeploymentSpecs[0].Name)
1652+
require.NoError(t, err)
1653+
1654+
// Should clean up the CSV
1655+
err = waitForCSVToDelete(t, crc, csvNew.Name)
1656+
require.NoError(t, err)
1657+
}
1658+
14321659
// TODO: test behavior when replaces field doesn't point to existing CSV

0 commit comments

Comments
 (0)