Skip to content

Commit 82d4ae9

Browse files
committed
Fix CSV hotfix flake
The logic of this test was incorrect. We want the updated deployment to have an updated container name, same as the CSV. Previously, it was expecting the container name to be different than the CSV. If the test completed quickly, the deployment would still have the old name and the test would pass. If it took a reasonable amount of time then the test would fail. Signed-off-by: Todd Short <[email protected]>
1 parent da028e4 commit 82d4ae9

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

test/e2e/csv_e2e_test.go

+36-28
Original file line numberDiff line numberDiff line change
@@ -3550,7 +3550,7 @@ var _ = Describe("ClusterServiceVersion", func() {
35503550
c := newKubeClient()
35513551
crc := newCRClient()
35523552

3553-
// Create dependency first (CRD)
3553+
By("Creating dependency first (CRD)")
35543554
crdPlural := genName("ins")
35553555
crdName := crdPlural + ".cluster.com"
35563556
cleanupCRD, err := createCRD(c, apiextensionsv1.CustomResourceDefinition{
@@ -3584,7 +3584,7 @@ var _ = Describe("ClusterServiceVersion", func() {
35843584
defer cleanupCRD()
35853585
Expect(err).ShouldNot(HaveOccurred())
35863586

3587-
// Create "current" CSV
3587+
By("Creating 'current' CSV")
35883588
nginxName := genName("nginx-")
35893589
strategy := operatorsv1alpha1.StrategyDetailsDeployment{
35903590
DeploymentSpecs: []operatorsv1alpha1.StrategyDeploymentSpec{
@@ -3645,16 +3645,18 @@ var _ = Describe("ClusterServiceVersion", func() {
36453645
Expect(err).ShouldNot(HaveOccurred())
36463646
defer cleanupCSV()
36473647

3648-
// Wait for current CSV to succeed
3648+
By("Waiting for current CSV to succeed")
36493649
_, err = fetchCSV(crc, generatedNamespace.GetName(), csv.Name, csvSucceededChecker)
36503650
Expect(err).ShouldNot(HaveOccurred())
36513651

3652-
// Should have created deployment
3653-
dep, err := c.GetDeployment(generatedNamespace.GetName(), strategy.DeploymentSpecs[0].Name)
3652+
By("Waiting for deployment to be created")
3653+
dep, err := waitForDeployment(generatedNamespace.GetName(), strategy.DeploymentSpecs[0].Name, c)
36543654
Expect(err).ShouldNot(HaveOccurred())
36553655
Expect(dep).ShouldNot(BeNil())
36563656

3657-
// Create "updated" CSV
3657+
GinkgoT().Logf("Deployment container name: %v", dep.Spec.Template.Spec.Containers[0].Name)
3658+
3659+
By("Creating 'updated' CSV")
36583660
strategyNew := operatorsv1alpha1.StrategyDetailsDeployment{
36593661
DeploymentSpecs: []operatorsv1alpha1.StrategyDeploymentSpec{
36603662
{
@@ -3666,40 +3668,46 @@ var _ = Describe("ClusterServiceVersion", func() {
36663668
},
36673669
}
36683670

3669-
// Fetch the current csv
3671+
By("Fetching the current csv")
36703672
fetchedCSV, err := fetchCSV(crc, generatedNamespace.GetName(), csv.Name, csvSucceededChecker)
36713673
Expect(err).ShouldNot(HaveOccurred())
36723674

3673-
// Update csv with modified deployment spec
3675+
By("Updating the CSV")
36743676
fetchedCSV.Spec.InstallStrategy.StrategySpec = strategyNew
3675-
36763677
Eventually(func() error {
3677-
// Update the current csv
36783678
_, err = crc.OperatorsV1alpha1().ClusterServiceVersions(generatedNamespace.GetName()).Update(context.TODO(), fetchedCSV, metav1.UpdateOptions{})
36793679
return err
36803680
}).Should(Succeed())
36813681

3682-
// Wait for updated CSV to succeed
3683-
_, err = fetchCSV(crc, generatedNamespace.GetName(), csv.Name, func(csv *operatorsv1alpha1.ClusterServiceVersion) bool {
3682+
By(fmt.Sprintf("Waiting for the updated CSV to succeed with deplpoyment container name: %s", strategyNew.DeploymentSpecs[0].Spec.Template.Spec.Containers[0].Name))
3683+
nameMatchesPrinted := false
3684+
Eventually(func() error {
3685+
_, err = fetchCSV(crc, generatedNamespace.GetName(), csv.Name, func(csv *operatorsv1alpha1.ClusterServiceVersion) bool {
36843686

3685-
// Should have updated existing deployment
3686-
depUpdated, err := c.GetDeployment(generatedNamespace.GetName(), strategyNew.DeploymentSpecs[0].Name)
3687-
if err != nil {
3688-
return false
3689-
}
3690-
if depUpdated == nil {
3691-
return false
3692-
}
3693-
// container name has been updated and differs from initial CSV spec and updated CSV spec
3694-
if depUpdated.Spec.Template.Spec.Containers[0].Name == strategyNew.DeploymentSpecs[0].Spec.Template.Spec.Containers[0].Name {
3695-
return false
3696-
}
3687+
// Should have updated existing deployment
3688+
depUpdated, err := c.GetDeployment(generatedNamespace.GetName(), strategyNew.DeploymentSpecs[0].Name)
3689+
if err != nil {
3690+
GinkgoT().Logf("error getting deployment %s/%s: %v", generatedNamespace.GetName(), strategyNew.DeploymentSpecs[0].Name, err)
3691+
return false
3692+
}
3693+
if depUpdated == nil {
3694+
return false
3695+
}
36973696

3698-
// Check for success
3699-
return csvSucceededChecker(csv)
3700-
})
3701-
Expect(err).ShouldNot(HaveOccurred())
3697+
// container name has been updated and differs from initial CSV spec and updated CSV spec
3698+
if depUpdated.Spec.Template.Spec.Containers[0].Name != strategyNew.DeploymentSpecs[0].Spec.Template.Spec.Containers[0].Name {
3699+
return false
3700+
}
3701+
if !nameMatchesPrinted {
3702+
GinkgoT().Logf("deployments: dep container name matches: %v", strategyNew.DeploymentSpecs[0].Spec.Template.Spec.Containers[0].Name)
3703+
nameMatchesPrinted = true
3704+
}
37023705

3706+
// Check for success
3707+
return csvSucceededChecker(csv)
3708+
})
3709+
return err
3710+
}, pollDuration, pollInterval).Should(Succeed())
37033711
})
37043712
It("emits CSV requirement events", func() {
37053713

0 commit comments

Comments
 (0)