Skip to content

Commit a3cc46a

Browse files
committed
test: patch existing CSV for a hotfix
This is a test for the hotfix scenario, where an existing CSV is patched directly to update the deployment spec. Ref: #1774
1 parent e2c0f2c commit a3cc46a

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

test/e2e/csv_e2e_test.go

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,7 +2664,136 @@ var _ = Describe("CSV", func() {
26642664
err = waitForDeploymentToDelete(GinkgoT(), c, strategy.DeploymentSpecs[0].Name)
26652665
require.NoError(GinkgoT(), err)
26662666
})
2667+
It("update deployment spec in an existing CSV for a hotfix", func() {
26672668

2669+
c := newKubeClient()
2670+
crc := newCRClient()
2671+
2672+
// Create dependency first (CRD)
2673+
crdPlural := genName("ins")
2674+
crdName := crdPlural + ".cluster.com"
2675+
cleanupCRD, err := createCRD(c, apiextensions.CustomResourceDefinition{
2676+
ObjectMeta: metav1.ObjectMeta{
2677+
Name: crdName,
2678+
},
2679+
Spec: apiextensions.CustomResourceDefinitionSpec{
2680+
Group: "cluster.com",
2681+
Version: "v1alpha1",
2682+
Names: apiextensions.CustomResourceDefinitionNames{
2683+
Plural: crdPlural,
2684+
Singular: crdPlural,
2685+
Kind: crdPlural,
2686+
ListKind: "list" + crdPlural,
2687+
},
2688+
Scope: "Namespaced",
2689+
},
2690+
})
2691+
defer cleanupCRD()
2692+
require.NoError(GinkgoT(), err)
2693+
2694+
// Create "current" CSV
2695+
nginxName := genName("nginx-")
2696+
strategy := v1alpha1.StrategyDetailsDeployment{
2697+
DeploymentSpecs: []v1alpha1.StrategyDeploymentSpec{
2698+
{
2699+
Name: genName("dep-"),
2700+
Spec: newNginxDeployment(nginxName),
2701+
},
2702+
},
2703+
}
2704+
2705+
csv := v1alpha1.ClusterServiceVersion{
2706+
TypeMeta: metav1.TypeMeta{
2707+
Kind: v1alpha1.ClusterServiceVersionKind,
2708+
APIVersion: v1alpha1.ClusterServiceVersionAPIVersion,
2709+
},
2710+
ObjectMeta: metav1.ObjectMeta{
2711+
Name: genName("csv"),
2712+
},
2713+
Spec: v1alpha1.ClusterServiceVersionSpec{
2714+
MinKubeVersion: "0.0.0",
2715+
InstallModes: []v1alpha1.InstallMode{
2716+
{
2717+
Type: v1alpha1.InstallModeTypeOwnNamespace,
2718+
Supported: true,
2719+
},
2720+
{
2721+
Type: v1alpha1.InstallModeTypeSingleNamespace,
2722+
Supported: true,
2723+
},
2724+
{
2725+
Type: v1alpha1.InstallModeTypeMultiNamespace,
2726+
Supported: true,
2727+
},
2728+
{
2729+
Type: v1alpha1.InstallModeTypeAllNamespaces,
2730+
Supported: true,
2731+
},
2732+
},
2733+
InstallStrategy: v1alpha1.NamedInstallStrategy{
2734+
StrategyName: v1alpha1.InstallStrategyNameDeployment,
2735+
StrategySpec: strategy,
2736+
},
2737+
CustomResourceDefinitions: v1alpha1.CustomResourceDefinitions{
2738+
Owned: []v1alpha1.CRDDescription{
2739+
{
2740+
Name: crdName,
2741+
Version: "v1alpha1",
2742+
Kind: crdPlural,
2743+
DisplayName: crdName,
2744+
Description: "In the cluster",
2745+
},
2746+
},
2747+
},
2748+
},
2749+
}
2750+
2751+
cleanupCSV, err := createCSV(c, crc, csv, testNamespace, true, false)
2752+
require.NoError(GinkgoT(), err)
2753+
defer cleanupCSV()
2754+
2755+
// Wait for current CSV to succeed
2756+
_, err = fetchCSV(crc, csv.Name, testNamespace, csvSucceededChecker)
2757+
require.NoError(GinkgoT(), err)
2758+
2759+
// Should have created deployment
2760+
dep, err := c.GetDeployment(testNamespace, strategy.DeploymentSpecs[0].Name)
2761+
require.NoError(GinkgoT(), err)
2762+
require.NotNil(GinkgoT(), dep)
2763+
2764+
// Create "updated" CSV
2765+
strategyNew := v1alpha1.StrategyDetailsDeployment{
2766+
DeploymentSpecs: []v1alpha1.StrategyDeploymentSpec{
2767+
{
2768+
// Same name
2769+
Name: strategy.DeploymentSpecs[0].Name,
2770+
// Different spec
2771+
Spec: newNginxDeployment(nginxName),
2772+
},
2773+
},
2774+
}
2775+
2776+
// Fetch the current csv
2777+
fetchedCSV, err := fetchCSV(crc, csv.Name, testNamespace, csvSucceededChecker)
2778+
require.NoError(GinkgoT(), err)
2779+
2780+
// Update csv with modified deployment spec
2781+
fetchedCSV.Spec.InstallStrategy.StrategySpec = strategyNew
2782+
2783+
// Update the current csv
2784+
_, err = crc.OperatorsV1alpha1().ClusterServiceVersions(testNamespace).Update(context.TODO(), fetchedCSV, metav1.UpdateOptions{})
2785+
require.NoError(GinkgoT(), err)
2786+
2787+
// Wait for updated CSV to succeed
2788+
_, err = fetchCSV(crc, csv.Name, testNamespace, csvSucceededChecker)
2789+
require.NoError(GinkgoT(), err)
2790+
2791+
// Should have updated existing deployment
2792+
depUpdated, err := c.GetDeployment(testNamespace, strategyNew.DeploymentSpecs[0].Name)
2793+
require.NoError(GinkgoT(), err)
2794+
require.NotNil(GinkgoT(), depUpdated)
2795+
require.Equal(GinkgoT(), depUpdated.Spec.Template.Spec.Containers[0].Name, strategyNew.DeploymentSpecs[0].Spec.Template.Spec.Containers[0].Name)
2796+
})
26682797
It("emits CSV requirement events", func() {
26692798

26702799
c := ctx.Ctx().KubeClient()

0 commit comments

Comments
 (0)