Skip to content

Commit 286a63c

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 591aace commit 286a63c

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

test/e2e/csv_e2e_test.go

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,7 +2915,144 @@ var _ = Describe("ClusterServiceVersion", func() {
29152915
err = waitForDeploymentToDelete(c, strategy.DeploymentSpecs[0].Name)
29162916
Expect(err).ShouldNot(HaveOccurred())
29172917
})
2918+
It("update deployment spec in an existing CSV for a hotfix", func() {
29182919

2920+
c := newKubeClient()
2921+
crc := newCRClient()
2922+
2923+
// Create dependency first (CRD)
2924+
crdPlural := genName("ins")
2925+
crdName := crdPlural + ".cluster.com"
2926+
cleanupCRD, err := createCRD(c, apiextensions.CustomResourceDefinition{
2927+
ObjectMeta: metav1.ObjectMeta{
2928+
Name: crdName,
2929+
},
2930+
Spec: apiextensions.CustomResourceDefinitionSpec{
2931+
Group: "cluster.com",
2932+
Version: "v1alpha1",
2933+
Names: apiextensions.CustomResourceDefinitionNames{
2934+
Plural: crdPlural,
2935+
Singular: crdPlural,
2936+
Kind: crdPlural,
2937+
ListKind: "list" + crdPlural,
2938+
},
2939+
Scope: "Namespaced",
2940+
},
2941+
})
2942+
defer cleanupCRD()
2943+
Expect(err).ShouldNot(HaveOccurred())
2944+
2945+
// Create "current" CSV
2946+
nginxName := genName("nginx-")
2947+
strategy := v1alpha1.StrategyDetailsDeployment{
2948+
DeploymentSpecs: []v1alpha1.StrategyDeploymentSpec{
2949+
{
2950+
Name: genName("dep-"),
2951+
Spec: newNginxDeployment(nginxName),
2952+
},
2953+
},
2954+
}
2955+
2956+
csv := v1alpha1.ClusterServiceVersion{
2957+
TypeMeta: metav1.TypeMeta{
2958+
Kind: v1alpha1.ClusterServiceVersionKind,
2959+
APIVersion: v1alpha1.ClusterServiceVersionAPIVersion,
2960+
},
2961+
ObjectMeta: metav1.ObjectMeta{
2962+
Name: genName("csv"),
2963+
},
2964+
Spec: v1alpha1.ClusterServiceVersionSpec{
2965+
MinKubeVersion: "0.0.0",
2966+
InstallModes: []v1alpha1.InstallMode{
2967+
{
2968+
Type: v1alpha1.InstallModeTypeOwnNamespace,
2969+
Supported: true,
2970+
},
2971+
{
2972+
Type: v1alpha1.InstallModeTypeSingleNamespace,
2973+
Supported: true,
2974+
},
2975+
{
2976+
Type: v1alpha1.InstallModeTypeMultiNamespace,
2977+
Supported: true,
2978+
},
2979+
{
2980+
Type: v1alpha1.InstallModeTypeAllNamespaces,
2981+
Supported: true,
2982+
},
2983+
},
2984+
InstallStrategy: v1alpha1.NamedInstallStrategy{
2985+
StrategyName: v1alpha1.InstallStrategyNameDeployment,
2986+
StrategySpec: strategy,
2987+
},
2988+
CustomResourceDefinitions: v1alpha1.CustomResourceDefinitions{
2989+
Owned: []v1alpha1.CRDDescription{
2990+
{
2991+
Name: crdName,
2992+
Version: "v1alpha1",
2993+
Kind: crdPlural,
2994+
DisplayName: crdName,
2995+
Description: "In the cluster",
2996+
},
2997+
},
2998+
},
2999+
},
3000+
}
3001+
3002+
cleanupCSV, err := createCSV(c, crc, csv, testNamespace, true, false)
3003+
Expect(err).ShouldNot(HaveOccurred())
3004+
defer cleanupCSV()
3005+
3006+
// Wait for current CSV to succeed
3007+
_, err = fetchCSV(crc, csv.Name, testNamespace, csvSucceededChecker)
3008+
Expect(err).ShouldNot(HaveOccurred())
3009+
3010+
// Should have created deployment
3011+
dep, err := c.GetDeployment(testNamespace, strategy.DeploymentSpecs[0].Name)
3012+
Expect(err).ShouldNot(HaveOccurred())
3013+
Expect(dep).ShouldNot(BeNil())
3014+
3015+
// Create "updated" CSV
3016+
strategyNew := v1alpha1.StrategyDetailsDeployment{
3017+
DeploymentSpecs: []v1alpha1.StrategyDeploymentSpec{
3018+
{
3019+
// Same name
3020+
Name: strategy.DeploymentSpecs[0].Name,
3021+
// Different spec
3022+
Spec: newNginxDeployment(nginxName),
3023+
},
3024+
},
3025+
}
3026+
3027+
// Fetch the current csv
3028+
fetchedCSV, err := fetchCSV(crc, csv.Name, testNamespace, csvSucceededChecker)
3029+
Expect(err).ShouldNot(HaveOccurred())
3030+
3031+
// Update csv with modified deployment spec
3032+
fetchedCSV.Spec.InstallStrategy.StrategySpec = strategyNew
3033+
3034+
Eventually(func() error {
3035+
// Update the current csv
3036+
_, err = crc.OperatorsV1alpha1().ClusterServiceVersions(testNamespace).Update(context.TODO(), fetchedCSV, metav1.UpdateOptions{})
3037+
return err
3038+
}).Should(Succeed())
3039+
3040+
// Wait for updated CSV to succeed
3041+
_, err = fetchCSV(crc, csv.Name, testNamespace, func(csv *v1alpha1.ClusterServiceVersion) bool {
3042+
3043+
// Should have updated existing deployment
3044+
depUpdated, err := c.GetDeployment(testNamespace, strategyNew.DeploymentSpecs[0].Name)
3045+
Expect(err).ShouldNot(HaveOccurred())
3046+
Expect(depUpdated).ShouldNot(BeNil())
3047+
// container name has been updated and differs from initial CSV spec and updated CSV spec
3048+
Expect(depUpdated.Spec.Template.Spec.Containers[0].Name).ShouldNot(Equal(strategyNew.DeploymentSpecs[0].Spec.Template.Spec.Containers[0].Name))
3049+
3050+
// Check for success
3051+
return csvSucceededChecker(csv)
3052+
})
3053+
Expect(err).ShouldNot(HaveOccurred())
3054+
3055+
})
29193056
It("emits CSV requirement events", func() {
29203057

29213058
csv := &v1alpha1.ClusterServiceVersion{

0 commit comments

Comments
 (0)