Skip to content

Commit

Permalink
move the tuningpolicy_test.sh to golang (#2396)
Browse files Browse the repository at this point in the history
Signed-off-by: Nahshon Unna-Tsameret <[email protected]>
  • Loading branch information
nunnatsa authored Jun 27, 2023
1 parent 703fa1f commit ae3dd17
Show file tree
Hide file tree
Showing 9 changed files with 352 additions and 72 deletions.
69 changes: 0 additions & 69 deletions hack/check_tuningPolicy.sh

This file was deleted.

3 changes: 0 additions & 3 deletions hack/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ KUBECTL_BINARY=${KUBECTL_BINARY} ./hack/check_golden_images.sh
# Check TLS profile on the webhook
KUBECTL_BINARY=${KUBECTL_BINARY} ./hack/check_tlsprofile.sh

# Check tuning policy
KUBECTL_BINARY=${KUBECTL_BINARY} ./hack/check_tuningPolicy.sh

# check if HCO is able to correctly add back a label used as a label selector
${KUBECTL_BINARY} label priorityclass kubevirt-cluster-critical app-
sleep 10
Expand Down
102 changes: 102 additions & 0 deletions tests/func-tests/tuningpolicy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package tests_test

import (
"context"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"kubevirt.io/client-go/kubecli"

kvv1 "kubevirt.io/api/core/v1"
"kubevirt.io/kubevirt/tests/flags"

"github.com/kubevirt/hyperconverged-cluster-operator/api/v1beta1"
"github.com/kubevirt/hyperconverged-cluster-operator/controllers/common"
tests "github.com/kubevirt/hyperconverged-cluster-operator/tests/func-tests"
)

var _ = Describe("Check that the TuningPolicy annotation is configuring the KV object as expected", Serial, func() {
tests.FlagParse()
var (
cli kubecli.KubevirtClient
ctx context.Context
)

BeforeEach(func() {
var err error
cli, err = kubecli.GetKubevirtClient()
Expect(cli).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())

ctx = context.Background()
})

AfterEach(func() {
hc := tests.GetHCO(ctx, cli)

delete(hc.Annotations, common.TuningPolicyAnnotationName)
hc.Spec.TuningPolicy = ""

tests.UpdateHCORetry(ctx, cli, hc)
})

It("should update KV with the tuningPolicy annotation", func() {
hc := tests.GetHCO(ctx, cli)

if hc.Annotations == nil {
hc.Annotations = make(map[string]string)
}
hc.Annotations[common.TuningPolicyAnnotationName] = `{"qps":100,"burst":200}`
hc.Spec.TuningPolicy = v1beta1.HyperConvergedAnnotationTuningPolicy

tests.UpdateHCORetry(ctx, cli, hc)

expected := kvv1.TokenBucketRateLimiter{
Burst: 200,
QPS: 100,
}

checkTuningPolicy(cli, expected)
})

It("should update KV with the highBurst tuningPolicy", func() {
hc := tests.GetHCO(ctx, cli)

delete(hc.Annotations, common.TuningPolicyAnnotationName)
hc.Spec.TuningPolicy = v1beta1.HyperConvergedHighBurstProfile

tests.UpdateHCORetry(ctx, cli, hc)

expected := kvv1.TokenBucketRateLimiter{
Burst: 400,
QPS: 200,
}

checkTuningPolicy(cli, expected)
})
})

func checkTuningPolicy(cli kubecli.KubevirtClient, expected kvv1.TokenBucketRateLimiter) {
Eventually(func(g Gomega) {
kv, err := cli.KubeVirt(flags.KubeVirtInstallNamespace).Get("kubevirt-kubevirt-hyperconverged", &metav1.GetOptions{})
g.Expect(err).ShouldNot(HaveOccurred())
g.Expect(kv).ShouldNot(BeNil())
g.Expect(kv.Spec.Configuration).ShouldNot(BeNil())

checkReloadableComponentConfiguration(g, kv.Spec.Configuration.APIConfiguration, expected)
checkReloadableComponentConfiguration(g, kv.Spec.Configuration.ControllerConfiguration, expected)
checkReloadableComponentConfiguration(g, kv.Spec.Configuration.HandlerConfiguration, expected)
checkReloadableComponentConfiguration(g, kv.Spec.Configuration.WebhookConfiguration, expected)
}).WithTimeout(time.Minute * 2).WithPolling(time.Second).Should(Succeed())

}

func checkReloadableComponentConfiguration(g Gomega, actual *kvv1.ReloadableComponentConfiguration, expected kvv1.TokenBucketRateLimiter) {
g.ExpectWithOffset(1, actual).ShouldNot(BeNil())
g.ExpectWithOffset(1, actual.RestClient).ShouldNot(BeNil())
g.ExpectWithOffset(1, actual.RestClient.RateLimiter).ShouldNot(BeNil())
g.ExpectWithOffset(1, actual.RestClient.RateLimiter.TokenBucketRateLimiter).Should(HaveValue(Equal(expected)))
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ github.com/kubevirt/cluster-network-addons-operator/pkg/apis/networkaddonsoperat
# github.com/kubevirt/hyperconverged-cluster-operator v1.8.0 => ../
## explicit; go 1.19
github.com/kubevirt/hyperconverged-cluster-operator/api/v1beta1
github.com/kubevirt/hyperconverged-cluster-operator/controllers/common
github.com/kubevirt/hyperconverged-cluster-operator/pkg/util
# github.com/mailru/easyjson v0.7.7
## explicit; go 1.12
Expand Down Expand Up @@ -1000,6 +1001,7 @@ sigs.k8s.io/controller-runtime/pkg/healthz
sigs.k8s.io/controller-runtime/pkg/internal/log
sigs.k8s.io/controller-runtime/pkg/internal/objectutil
sigs.k8s.io/controller-runtime/pkg/log
sigs.k8s.io/controller-runtime/pkg/reconcile
sigs.k8s.io/controller-runtime/pkg/scheme
# sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd
## explicit; go 1.18
Expand Down
21 changes: 21 additions & 0 deletions tests/vendor/sigs.k8s.io/controller-runtime/pkg/reconcile/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ae3dd17

Please sign in to comment.