Skip to content

Commit a807a0d

Browse files
Merge pull request #1817 from jeyaramashok/1774-csv-hotfix
test: patch existing CSV for a hotfix
2 parents 152a471 + 286a63c commit a807a0d

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
@@ -2987,7 +2987,144 @@ var _ = Describe("ClusterServiceVersion", func() {
29872987
err = waitForDeploymentToDelete(c, strategy.DeploymentSpecs[0].Name)
29882988
Expect(err).ShouldNot(HaveOccurred())
29892989
})
2990+
It("update deployment spec in an existing CSV for a hotfix", func() {
29902991

2992+
c := newKubeClient()
2993+
crc := newCRClient()
2994+
2995+
// Create dependency first (CRD)
2996+
crdPlural := genName("ins")
2997+
crdName := crdPlural + ".cluster.com"
2998+
cleanupCRD, err := createCRD(c, apiextensions.CustomResourceDefinition{
2999+
ObjectMeta: metav1.ObjectMeta{
3000+
Name: crdName,
3001+
},
3002+
Spec: apiextensions.CustomResourceDefinitionSpec{
3003+
Group: "cluster.com",
3004+
Version: "v1alpha1",
3005+
Names: apiextensions.CustomResourceDefinitionNames{
3006+
Plural: crdPlural,
3007+
Singular: crdPlural,
3008+
Kind: crdPlural,
3009+
ListKind: "list" + crdPlural,
3010+
},
3011+
Scope: "Namespaced",
3012+
},
3013+
})
3014+
defer cleanupCRD()
3015+
Expect(err).ShouldNot(HaveOccurred())
3016+
3017+
// Create "current" CSV
3018+
nginxName := genName("nginx-")
3019+
strategy := v1alpha1.StrategyDetailsDeployment{
3020+
DeploymentSpecs: []v1alpha1.StrategyDeploymentSpec{
3021+
{
3022+
Name: genName("dep-"),
3023+
Spec: newNginxDeployment(nginxName),
3024+
},
3025+
},
3026+
}
3027+
3028+
csv := v1alpha1.ClusterServiceVersion{
3029+
TypeMeta: metav1.TypeMeta{
3030+
Kind: v1alpha1.ClusterServiceVersionKind,
3031+
APIVersion: v1alpha1.ClusterServiceVersionAPIVersion,
3032+
},
3033+
ObjectMeta: metav1.ObjectMeta{
3034+
Name: genName("csv"),
3035+
},
3036+
Spec: v1alpha1.ClusterServiceVersionSpec{
3037+
MinKubeVersion: "0.0.0",
3038+
InstallModes: []v1alpha1.InstallMode{
3039+
{
3040+
Type: v1alpha1.InstallModeTypeOwnNamespace,
3041+
Supported: true,
3042+
},
3043+
{
3044+
Type: v1alpha1.InstallModeTypeSingleNamespace,
3045+
Supported: true,
3046+
},
3047+
{
3048+
Type: v1alpha1.InstallModeTypeMultiNamespace,
3049+
Supported: true,
3050+
},
3051+
{
3052+
Type: v1alpha1.InstallModeTypeAllNamespaces,
3053+
Supported: true,
3054+
},
3055+
},
3056+
InstallStrategy: v1alpha1.NamedInstallStrategy{
3057+
StrategyName: v1alpha1.InstallStrategyNameDeployment,
3058+
StrategySpec: strategy,
3059+
},
3060+
CustomResourceDefinitions: v1alpha1.CustomResourceDefinitions{
3061+
Owned: []v1alpha1.CRDDescription{
3062+
{
3063+
Name: crdName,
3064+
Version: "v1alpha1",
3065+
Kind: crdPlural,
3066+
DisplayName: crdName,
3067+
Description: "In the cluster",
3068+
},
3069+
},
3070+
},
3071+
},
3072+
}
3073+
3074+
cleanupCSV, err := createCSV(c, crc, csv, testNamespace, true, false)
3075+
Expect(err).ShouldNot(HaveOccurred())
3076+
defer cleanupCSV()
3077+
3078+
// Wait for current CSV to succeed
3079+
_, err = fetchCSV(crc, csv.Name, testNamespace, csvSucceededChecker)
3080+
Expect(err).ShouldNot(HaveOccurred())
3081+
3082+
// Should have created deployment
3083+
dep, err := c.GetDeployment(testNamespace, strategy.DeploymentSpecs[0].Name)
3084+
Expect(err).ShouldNot(HaveOccurred())
3085+
Expect(dep).ShouldNot(BeNil())
3086+
3087+
// Create "updated" CSV
3088+
strategyNew := v1alpha1.StrategyDetailsDeployment{
3089+
DeploymentSpecs: []v1alpha1.StrategyDeploymentSpec{
3090+
{
3091+
// Same name
3092+
Name: strategy.DeploymentSpecs[0].Name,
3093+
// Different spec
3094+
Spec: newNginxDeployment(nginxName),
3095+
},
3096+
},
3097+
}
3098+
3099+
// Fetch the current csv
3100+
fetchedCSV, err := fetchCSV(crc, csv.Name, testNamespace, csvSucceededChecker)
3101+
Expect(err).ShouldNot(HaveOccurred())
3102+
3103+
// Update csv with modified deployment spec
3104+
fetchedCSV.Spec.InstallStrategy.StrategySpec = strategyNew
3105+
3106+
Eventually(func() error {
3107+
// Update the current csv
3108+
_, err = crc.OperatorsV1alpha1().ClusterServiceVersions(testNamespace).Update(context.TODO(), fetchedCSV, metav1.UpdateOptions{})
3109+
return err
3110+
}).Should(Succeed())
3111+
3112+
// Wait for updated CSV to succeed
3113+
_, err = fetchCSV(crc, csv.Name, testNamespace, func(csv *v1alpha1.ClusterServiceVersion) bool {
3114+
3115+
// Should have updated existing deployment
3116+
depUpdated, err := c.GetDeployment(testNamespace, strategyNew.DeploymentSpecs[0].Name)
3117+
Expect(err).ShouldNot(HaveOccurred())
3118+
Expect(depUpdated).ShouldNot(BeNil())
3119+
// container name has been updated and differs from initial CSV spec and updated CSV spec
3120+
Expect(depUpdated.Spec.Template.Spec.Containers[0].Name).ShouldNot(Equal(strategyNew.DeploymentSpecs[0].Spec.Template.Spec.Containers[0].Name))
3121+
3122+
// Check for success
3123+
return csvSucceededChecker(csv)
3124+
})
3125+
Expect(err).ShouldNot(HaveOccurred())
3126+
3127+
})
29913128
It("emits CSV requirement events", func() {
29923129

29933130
csv := &v1alpha1.ClusterServiceVersion{

0 commit comments

Comments
 (0)