Skip to content

Commit

Permalink
Merge pull request kubevirt#536 from kubevirt-bot/cherry-pick-535-to-…
Browse files Browse the repository at this point in the history
…release-v0.17

[release-v0.17] fix: stabilize functests of VM Console proxy
  • Loading branch information
kubevirt-bot authored Apr 5, 2023
2 parents 238a5b8 + 0ba9096 commit f0a4ae2
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions tests/vm_console_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package tests

import (
"crypto/tls"
"fmt"
"io"
"kubevirt.io/ssp-operator/tests/env"
"net/http"
"net/url"
"reflect"
"strconv"
"time"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -16,11 +17,13 @@ import (
apps "k8s.io/api/apps/v1"
core "k8s.io/api/core/v1"
rbac "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/pointer"

ssp "kubevirt.io/ssp-operator/api/v1beta1"
vm_console_proxy "kubevirt.io/ssp-operator/internal/operands/vm-console-proxy"
"kubevirt.io/ssp-operator/tests/env"
)

var _ = Describe("VM Console Proxy Operand", func() {
Expand All @@ -34,7 +37,7 @@ var _ = Describe("VM Console Proxy Operand", func() {
routeResource testResource
)

BeforeEach(func() {
BeforeEach(OncePerOrdered, func() {
strategy.SkipSspUpdateTestsIfNeeded()

updateSsp(func(foundSsp *ssp.SSP) {
Expand Down Expand Up @@ -130,14 +133,43 @@ var _ = Describe("VM Console Proxy Operand", func() {
},
}

// Waiting until the proxy deployment is created.
// This is a workaround, because the above updateSsp() function updates only annotations,
// which don't update the .metadata.generation field. So the waitUntilDeployed() call
// below succeeds immediately, and does not wait until proxy resources are created.
Eventually(func() error {
return apiClient.Get(ctx, deploymentResource.GetKey(), &apps.Deployment{})
}, env.ShortTimeout(), time.Second).Should(Succeed())

waitUntilDeployed()
})

AfterEach(func() {
AfterEach(OncePerOrdered, func() {
strategy.RevertToOriginalSspCr()

// Similar workaround as in BeforeEach().
originalSspProxyAnnotation := getSsp().Annotations[vm_console_proxy.EnableAnnotation]
if isEnabled, _ := strconv.ParseBool(originalSspProxyAnnotation); !isEnabled {
Eventually(func() error {
deployment := &apps.Deployment{}
err := apiClient.Get(ctx, deploymentResource.GetKey(), deployment)
if errors.IsNotFound(err) {
return nil
}
if err != nil {
return err
}
if !deployment.DeletionTimestamp.IsZero() {
return nil
}
return fmt.Errorf("the console proxy deployment is not being deleted")
}, env.ShortTimeout(), time.Second).Should(Succeed())
}

waitUntilDeployed()
})

Context("Resource creation", func() {
Context("Resource creation", Ordered, func() {
DescribeTable("created cluster resource", func(res *testResource) {
resource := res.NewResource()
err := apiClient.Get(ctx, res.GetKey(), resource)
Expand Down Expand Up @@ -187,10 +219,6 @@ var _ = Describe("VM Console Proxy Operand", func() {
)

Context("With pause", func() {
BeforeEach(func() {
strategy.SkipSspUpdateTestsIfNeeded()
})

JustAfterEach(func() {
unpauseSsp()
})
Expand Down

0 comments on commit f0a4ae2

Please sign in to comment.