Skip to content

Commit

Permalink
Add retry mechanism when getting the console pluginname
Browse files Browse the repository at this point in the history
The "console should reach kubevirt-plugin manifests" functional test
became flacky. The reason for that may be a bug in the console code,
that sometimes return partial and corrupted json response.

This PR reads the json in a retry mechanism to give the console plugin
pod a chance to return a valid response.

Signed-off-by: Nahshon Unna-Tsameret <[email protected]>
  • Loading branch information
nunnatsa committed Dec 24, 2024
1 parent 70ded59 commit bc67e09
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions tests/func-tests/console_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,35 @@ var _ = Describe("kubevirt console plugin", Label(tests.OpenshiftLabel, "console
pluginServiceName := kubevirtPlugin.Spec.Backend.Service.Name
pluginServicePort := kubevirtPlugin.Spec.Backend.Service.Port

consolePods := &corev1.PodList{}
Expect(cli.List(ctx, consolePods, client.MatchingLabels{
"app": "console",
"component": "ui",
}, client.InNamespace(openshiftConsoleNamespace))).To(Succeed())

Expect(consolePods.Items).ToNot(BeEmpty())

testConsolePod := consolePods.Items[0]
command := fmt.Sprintf(`curl -ks https://%s.%s.svc:%d/plugin-manifest.json`,
pluginServiceName, tests.InstallNamespace, pluginServicePort)

stdout, stderr, err := executeCommandOnPod(ctx, k8sClientSet, &testConsolePod, command)
Expect(err).ToNot(HaveOccurred())
Expect(stdout).ToNot(BeEmpty())
Expect(stderr).To(BeEmpty())

var pluginManifests map[string]interface{}
err = json.Unmarshal([]byte(stdout), &pluginManifests)
Expect(err).ToNot(HaveOccurred())

pluginName := pluginManifests["name"]
Expect(pluginName).To(Equal(expectedKubevirtConsolePluginName))
hcoPods := &corev1.PodList{}
Expect(cli.List(ctx, hcoPods, client.MatchingLabels{
"name": "hyperconverged-cluster-operator",
}, client.InNamespace(tests.InstallNamespace))).To(Succeed())

Expect(hcoPods.Items).ToNot(BeEmpty())

testConsolePod := hcoPods.Items[0]
command := fmt.Sprintf(`curl -ks https://%s:%d/plugin-manifest.json`,
pluginServiceName, pluginServicePort)

Eventually(func(g Gomega, ctx context.Context) string {
stdout, stderr, err := executeCommandOnPod(ctx, k8sClientSet, &testConsolePod, command)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(stdout).ToNot(BeEmpty())
g.Expect(stderr).To(BeEmpty())

var pluginManifests map[string]interface{}
err = json.Unmarshal([]byte(stdout), &pluginManifests)
g.Expect(err).ToNot(HaveOccurred())

pluginName, ok := pluginManifests["name"]
g.Expect(ok).To(BeTrue())
return pluginName.(string)
}).
WithContext(ctx).
WithTimeout(60 * time.Second).
WithPolling(time.Second).
Should(Equal(expectedKubevirtConsolePluginName))
})

It("nodePlacement should be propagated from HyperConverged CR to console-plugin and apiserver-proxy Deployments", Serial, func(ctx context.Context) {
Expand Down

0 comments on commit bc67e09

Please sign in to comment.