Skip to content

Commit fd37f2b

Browse files
committed
Add test case for supporting multi-version CRD
Test updating CSV which owns different versions of the same CRD to ensure CSV is created correctly and deployed successfully. Jira: <https://jira.coreos.com/browse/ALM-629> Signed-off-by: Vu Dinh <[email protected]>
1 parent 6fcc74e commit fd37f2b

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
@@ -1349,4 +1349,231 @@ func TestUpdateCSVMultipleIntermediates(t *testing.T) {
13491349
require.NoError(t, err)
13501350
}
13511351

1352+
func TestUpdateCSVMultipleVersionCRD(t *testing.T) {
1353+
defer cleaner.NotifyTestComplete(t, true)
1354+
1355+
c := newKubeClient(t)
1356+
crc := newCRClient(t)
1357+
1358+
// Create initial CRD which has 2 versions: v1alpha1 & v1alpha2
1359+
crdPlural := genName("ins4")
1360+
crdName := crdPlural + ".cluster.com"
1361+
cleanupCRD, err := createCRD(c, extv1beta1.CustomResourceDefinition{
1362+
ObjectMeta: metav1.ObjectMeta{
1363+
Name: crdName,
1364+
},
1365+
Spec: extv1beta1.CustomResourceDefinitionSpec{
1366+
Group: "cluster.com",
1367+
Versions: []extv1beta1.CustomResourceDefinitionVersion{
1368+
{
1369+
Name: "v1alpha1",
1370+
Served: true,
1371+
Storage: true,
1372+
},
1373+
{
1374+
Name: "v1alpha2",
1375+
Served: true,
1376+
Storage: false,
1377+
},
1378+
},
1379+
Names: extv1beta1.CustomResourceDefinitionNames{
1380+
Plural: crdPlural,
1381+
Singular: crdPlural,
1382+
Kind: crdPlural,
1383+
ListKind: "list" + crdPlural,
1384+
},
1385+
Scope: "Namespaced",
1386+
},
1387+
})
1388+
require.NoError(t, err)
1389+
defer cleanupCRD()
1390+
1391+
// create initial deployment strategy
1392+
strategy := install.StrategyDetailsDeployment{
1393+
DeploymentSpecs: []install.StrategyDeploymentSpec{
1394+
{
1395+
Name: genName("dep1-"),
1396+
Spec: newNginxDeployment(genName("nginx-")),
1397+
},
1398+
},
1399+
}
1400+
strategyRaw, err := json.Marshal(strategy)
1401+
require.NoError(t, err)
1402+
1403+
// First CSV with owning CRD v1alpha1
1404+
csv := v1alpha1.ClusterServiceVersion{
1405+
TypeMeta: metav1.TypeMeta{
1406+
Kind: v1alpha1.ClusterServiceVersionKind,
1407+
APIVersion: v1alpha1.ClusterServiceVersionAPIVersion,
1408+
},
1409+
ObjectMeta: metav1.ObjectMeta{
1410+
Name: genName("csv"),
1411+
},
1412+
Spec: v1alpha1.ClusterServiceVersionSpec{
1413+
InstallStrategy: v1alpha1.NamedInstallStrategy{
1414+
StrategyName: install.InstallStrategyNameDeployment,
1415+
StrategySpecRaw: strategyRaw,
1416+
},
1417+
CustomResourceDefinitions: v1alpha1.CustomResourceDefinitions{
1418+
Owned: []v1alpha1.CRDDescription{
1419+
{
1420+
Name: crdName,
1421+
Version: "v1alpha1",
1422+
Kind: crdPlural,
1423+
DisplayName: crdName,
1424+
Description: "In the cluster4",
1425+
},
1426+
},
1427+
},
1428+
},
1429+
}
1430+
1431+
// CSV will be deleted by the upgrade process later
1432+
_, err = createCSV(t, c, crc, csv, testNamespace, true)
1433+
require.NoError(t, err)
1434+
1435+
// Wait for current CSV to succeed
1436+
_, err = fetchCSV(t, crc, csv.Name, csvSucceededChecker)
1437+
require.NoError(t, err)
1438+
1439+
// Should have created deployment
1440+
dep, err := c.GetDeployment(testNamespace, strategy.DeploymentSpecs[0].Name)
1441+
require.NoError(t, err)
1442+
require.NotNil(t, dep)
1443+
1444+
// Create updated deployment strategy
1445+
strategyNew := install.StrategyDetailsDeployment{
1446+
DeploymentSpecs: []install.StrategyDeploymentSpec{
1447+
{
1448+
Name: genName("dep2-"),
1449+
Spec: newNginxDeployment(genName("nginx-")),
1450+
},
1451+
},
1452+
}
1453+
strategyNewRaw, err := json.Marshal(strategyNew)
1454+
require.NoError(t, err)
1455+
1456+
// Second CSV with owning CRD v1alpha1 and v1alpha2
1457+
csvNew := v1alpha1.ClusterServiceVersion{
1458+
TypeMeta: metav1.TypeMeta{
1459+
Kind: v1alpha1.ClusterServiceVersionKind,
1460+
APIVersion: v1alpha1.ClusterServiceVersionAPIVersion,
1461+
},
1462+
ObjectMeta: metav1.ObjectMeta{
1463+
Name: genName("csv2"),
1464+
},
1465+
Spec: v1alpha1.ClusterServiceVersionSpec{
1466+
Replaces: csv.Name,
1467+
InstallStrategy: v1alpha1.NamedInstallStrategy{
1468+
StrategyName: install.InstallStrategyNameDeployment,
1469+
StrategySpecRaw: strategyNewRaw,
1470+
},
1471+
CustomResourceDefinitions: v1alpha1.CustomResourceDefinitions{
1472+
Owned: []v1alpha1.CRDDescription{
1473+
{
1474+
Name: crdName,
1475+
Version: "v1alpha1",
1476+
Kind: crdPlural,
1477+
DisplayName: crdName,
1478+
Description: "In the cluster4",
1479+
},
1480+
{
1481+
Name: crdName,
1482+
Version: "v1alpha2",
1483+
Kind: crdPlural,
1484+
DisplayName: crdName,
1485+
Description: "In the cluster4",
1486+
},
1487+
},
1488+
},
1489+
},
1490+
}
1491+
1492+
// Create newly updated CSV
1493+
_, err = createCSV(t, c, crc, csvNew, testNamespace, true)
1494+
require.NoError(t, err)
1495+
1496+
// Wait for updated CSV to succeed
1497+
fetchedCSV, err := fetchCSV(t, crc, csvNew.Name, csvSucceededChecker)
1498+
require.NoError(t, err)
1499+
1500+
// Fetch cluster service version again to check for unnecessary control loops
1501+
sameCSV, err := fetchCSV(t, crc, csvNew.Name, csvSucceededChecker)
1502+
require.NoError(t, err)
1503+
compareResources(t, fetchedCSV, sameCSV)
1504+
1505+
// Should have created new deployment and deleted old one
1506+
depNew, err := c.GetDeployment(testNamespace, strategyNew.DeploymentSpecs[0].Name)
1507+
require.NoError(t, err)
1508+
require.NotNil(t, depNew)
1509+
err = waitForDeploymentToDelete(t, c, strategy.DeploymentSpecs[0].Name)
1510+
require.NoError(t, err)
1511+
1512+
// Create updated deployment strategy
1513+
strategyNew2 := install.StrategyDetailsDeployment{
1514+
DeploymentSpecs: []install.StrategyDeploymentSpec{
1515+
{
1516+
Name: genName("dep3-"),
1517+
Spec: newNginxDeployment(genName("nginx-")),
1518+
},
1519+
},
1520+
}
1521+
strategyNewRaw2, err := json.Marshal(strategyNew2)
1522+
require.NoError(t, err)
1523+
1524+
// Third CSV with owning CRD v1alpha2
1525+
csvNew2 := v1alpha1.ClusterServiceVersion{
1526+
TypeMeta: metav1.TypeMeta{
1527+
Kind: v1alpha1.ClusterServiceVersionKind,
1528+
APIVersion: v1alpha1.ClusterServiceVersionAPIVersion,
1529+
},
1530+
ObjectMeta: metav1.ObjectMeta{
1531+
Name: genName("csv3"),
1532+
},
1533+
Spec: v1alpha1.ClusterServiceVersionSpec{
1534+
Replaces: csvNew.Name,
1535+
InstallStrategy: v1alpha1.NamedInstallStrategy{
1536+
StrategyName: install.InstallStrategyNameDeployment,
1537+
StrategySpecRaw: strategyNewRaw2,
1538+
},
1539+
CustomResourceDefinitions: v1alpha1.CustomResourceDefinitions{
1540+
Owned: []v1alpha1.CRDDescription{
1541+
{
1542+
Name: crdName,
1543+
Version: "v1alpha2",
1544+
Kind: crdPlural,
1545+
DisplayName: crdName,
1546+
Description: "In the cluster4",
1547+
},
1548+
},
1549+
},
1550+
},
1551+
}
1552+
1553+
// Create newly updated CSV
1554+
cleanupNewCSV, err := createCSV(t, c, crc, csvNew2, testNamespace, true)
1555+
require.NoError(t, err)
1556+
defer cleanupNewCSV()
1557+
1558+
// Wait for updated CSV to succeed
1559+
fetchedCSV, err = fetchCSV(t, crc, csvNew2.Name, csvSucceededChecker)
1560+
require.NoError(t, err)
1561+
1562+
// Fetch cluster service version again to check for unnecessary control loops
1563+
sameCSV, err = fetchCSV(t, crc, csvNew2.Name, csvSucceededChecker)
1564+
require.NoError(t, err)
1565+
compareResources(t, fetchedCSV, sameCSV)
1566+
1567+
// Should have created new deployment and deleted old one
1568+
depNew, err = c.GetDeployment(testNamespace, strategyNew2.DeploymentSpecs[0].Name)
1569+
require.NoError(t, err)
1570+
require.NotNil(t, depNew)
1571+
err = waitForDeploymentToDelete(t, c, strategyNew.DeploymentSpecs[0].Name)
1572+
require.NoError(t, err)
1573+
1574+
// Should clean up the CSV
1575+
err = waitForCSVToDelete(t, crc, csvNew.Name)
1576+
require.NoError(t, err)
1577+
}
1578+
13521579
// TODO: test behavior when replaces field doesn't point to existing CSV

0 commit comments

Comments
 (0)