Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix monitoring test failure due to missing CRBs #11541

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 23 additions & 11 deletions tests/monitoring/component_monitoring.go
Expand Up @@ -87,6 +87,12 @@ var (
restErrorsHighAlert: "VirtOperatorRESTErrorsHigh",
lowCountAlert: "LowVirtOperatorCount",
}

crbs = []string{
"kubevirt-operator",
"kubevirt-controller",
"kubevirt-handler",
}
)

var _ = Describe("[Serial][sig-monitoring]Component Monitoring", Serial, decorators.SigMonitoring, func() {
Expand Down Expand Up @@ -167,13 +173,16 @@ var _ = Describe("[Serial][sig-monitoring]Component Monitoring", Serial, decorat
})

Context("Errors metrics", func() {
var crb *rbacv1.ClusterRoleBinding
var crbsBackup []*rbacv1.ClusterRoleBinding

BeforeEach(func() {
virtClient = kubevirt.Client()

crb, err = virtClient.RbacV1().ClusterRoleBindings().Get(context.Background(), "kubevirt-operator", metav1.GetOptions{})
util.PanicOnError(err)
for _, crb := range crbs {
crb, err := virtClient.RbacV1().ClusterRoleBindings().Get(context.Background(), crb, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
crbsBackup = append(crbsBackup, crb.DeepCopy())
}

increaseRateLimit()

Expand All @@ -184,13 +193,16 @@ var _ = Describe("[Serial][sig-monitoring]Component Monitoring", Serial, decorat
})

AfterEach(func() {
crb.Annotations = nil
crb.ObjectMeta.ResourceVersion = ""
crb.ObjectMeta.UID = ""
_, err = virtClient.RbacV1().ClusterRoleBindings().Create(context.Background(), crb, metav1.CreateOptions{})
if !errors.IsAlreadyExists(err) {
util.PanicOnError(err)
for _, crb := range crbsBackup {
crb.Annotations = nil
crb.ObjectMeta.ResourceVersion = ""
crb.ObjectMeta.UID = ""
_, err = virtClient.RbacV1().ClusterRoleBindings().Create(context.Background(), crb, metav1.CreateOptions{})
if !errors.IsAlreadyExists(err) {
util.PanicOnError(err)
}
}

scales.RestoreAllScales()

time.Sleep(10 * time.Second)
Expand All @@ -212,7 +224,7 @@ var _ = Describe("[Serial][sig-monitoring]Component Monitoring", Serial, decorat

It("VirtOperatorRESTErrorsBurst and VirtOperatorRESTErrorsHigh should be triggered when requests to virt-operator are failing", func() {
scales.RestoreScale(virtOperator.deploymentName)
err = virtClient.RbacV1().ClusterRoleBindings().Delete(context.Background(), crb.Name, metav1.DeleteOptions{})
err = virtClient.RbacV1().ClusterRoleBindings().Delete(context.Background(), "kubevirt-operator", metav1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred())

Eventually(func(g Gomega) {
Expand All @@ -221,7 +233,7 @@ var _ = Describe("[Serial][sig-monitoring]Component Monitoring", Serial, decorat
}, 5*time.Minute, 500*time.Millisecond).Should(Succeed())
})

PIt("VirtControllerRESTErrorsBurst and VirtControllerRESTErrorsHigh should be triggered when requests to virt-controller are failing", func() {
It("VirtControllerRESTErrorsBurst and VirtControllerRESTErrorsHigh should be triggered when requests to virt-controller are failing", func() {
err = virtClient.RbacV1().ClusterRoleBindings().Delete(context.Background(), "kubevirt-controller", metav1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred())

Expand Down
8 changes: 5 additions & 3 deletions tests/testsuite/kubevirtresource.go
Expand Up @@ -198,8 +198,10 @@ func UpdateKubeVirtConfigValue(kvConfig v1.KubeVirtConfiguration) *v1.KubeVirt {
patch, err := strategicpatch.CreateTwoWayMergePatch(old, newJson, kv)
Expect(err).ToNot(HaveOccurred())

kv, err = virtClient.KubeVirt(kv.Namespace).Patch(kv.GetName(), types.MergePatchType, patch, &metav1.PatchOptions{})
Expect(err).ToNot(HaveOccurred())
Eventually(func() error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@assafad Can you please explain why this is necessary? IIUC the issue was with handling cluster role bindings

_, err = virtClient.KubeVirt(kv.Namespace).Patch(kv.GetName(), types.MergePatchType, patch, &metav1.PatchOptions{})
return err
}, 30*time.Second, 1*time.Second).Should(BeNil())

return kv
return util.GetCurrentKv(virtClient)
}