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 e2e failures due to missing CRBs #11506

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
32 changes: 22 additions & 10 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 crbs_backup []*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())
crbs_backup = append(crbs_backup, 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 crbs_backup {
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 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 {
_, err = virtClient.KubeVirt(kv.Namespace).Patch(kv.GetName(), types.MergePatchType, patch, &metav1.PatchOptions{})
return err
}, 30*time.Second, 1*time.Second).Should(BeNil())
Comment on lines +201 to +204
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 elaborate on the reason we need it? I see that the test changes cluster roles only. How come this has something to do with the flake?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not 100% sure, @machadovilaca would know better.

Copy link
Member Author

Choose a reason for hiding this comment

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

@enp0s3 since we removed the CRB from the pods, sometimes when this is executed the pods are not yet working properly and this call is not successful


return kv
return util.GetCurrentKv(virtClient)
}