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

Refactor Pool-manager tests #448

Merged
merged 5 commits into from
Jan 6, 2025

Conversation

RamLavi
Copy link
Member

@RamLavi RamLavi commented Dec 31, 2024

What this PR does / why we need it:
This PR does refactor chores on the pool-manager library:

  • Give meaningful names to const MACs
  • Use multus consts
  • Move closure functions to regular functions
  • Add check for macpool deleted MACs

Special notes for your reviewer:

Release note:

NONE

Signed-off-by: Ram Lavi <ralavi@redhat.com>
The networks and network-status annotations consts are set on multus
repo, and controlled by it. Using their consts to keep consistency.
For example, the deprecated 'k8s.v1.cni.cncf.io/networks-status'
annotation is replaced by the new one 'k8s.v1.cni.cncf.io/network-status'

Signed-off-by: Ram Lavi <ralavi@redhat.com>
There is no good reason to use these functions as closure functions.
Moving them to be regular functions, thus reducing code complexity.

Signed-off-by: Ram Lavi <ralavi@redhat.com>
Currently not all unit tests check macpool size after doing changes in
the macpool map (allocate, update or delete MACs entries)
Moving the check inside checkMacPoolMapEntries so that all tests check
this, removing the now redundant checks.
Also refactoring use of "errors.New(fmt.Sprintf(...))" into
"fmt.Errorf(...)"

Signed-off-by: Ram Lavi <ralavi@redhat.com>
Comment on lines 61 to 63
managedPodWithMacAllocated := v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "podpod", Namespace: managedNamespaceName, Annotations: afterAllocationAnnotation(managedNamespaceName, managedNamespaceMAC)}}
unmanagedPodWithMacAllocated := v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "unmanagedPod", Namespace: notManagedNamespaceName, Annotations: afterAllocationAnnotation(notManagedNamespaceName, unmanagedNamespaceMAC)}}
vmConfigMap := v1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Namespace: testManagerNamespace, Name: names.WAITING_VMS_CONFIGMAP}}
Copy link

Choose a reason for hiding this comment

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

My personal note, I would break these long lines, its a bit a hard to read the initialization of the struct here.

@kubevirt-bot
Copy link
Collaborator

@enp0s3: changing LGTM is restricted to collaborators

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

using formatted view instead of long lines improves readability

Signed-off-by: Ram Lavi <ralavi@redhat.com>
Comment on lines 62 to 83
managedPodWithMacAllocated := v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "podpod",
Namespace: managedNamespaceName,
Annotations: afterAllocationAnnotation(managedNamespaceName, managedNamespaceMAC),
},
}

unmanagedPodWithMacAllocated := v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "unmanagedPod",
Namespace: notManagedNamespaceName,
Annotations: afterAllocationAnnotation(notManagedNamespaceName, unmanagedNamespaceMAC),
},
}

vmConfigMap := v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: testManagerNamespace,
Name: names.WAITING_VMS_CONFIGMAP,
},
}
Copy link

Choose a reason for hiding this comment

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

@RamLavi Awesome!

@enp0s3
Copy link

enp0s3 commented Jan 5, 2025

@RamLavi Thing is that I am not a member in k8s network plumbing org

@RamLavi
Copy link
Member Author

RamLavi commented Jan 5, 2025

@ormergi can you take a look?

Copy link
Member

@oshoval oshoval left a comment

Choose a reason for hiding this comment

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

Just nits
Thanks

},
Webhooks: []admissionregistrationv1.MutatingWebhook{
admissionregistrationv1.MutatingWebhook{
Name: virtualMachnesWebhookName,
Copy link
Member

Choose a reason for hiding this comment

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

virtualMachnesWebhookName typo (also in original code, so not mandatory of course)

Copy link
Member Author

Choose a reason for hiding this comment

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

I will make a mental note to fix it on the next refactor PR

@@ -293,7 +292,6 @@ var _ = Describe("Pool", func() {
err := poolManager.AllocateVirtualMachineMac(&newVM, &transactionTimestamp, true, logger)
Expect(err).ToNot(HaveOccurred())

Expect(poolManager.macPoolMap).To(HaveLen(2))
Copy link
Member

@oshoval oshoval Jan 6, 2025

Choose a reason for hiding this comment

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

Change is fine, i just wonder, isnt it better to be explicit ? (not sure, maybe robust is better indeed)
just food for thought

Copy link
Member Author

Choose a reason for hiding this comment

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

It is still explicit, I just moved the check to the checkMacPoolMapEntries function, so that all tests benefit from it.

@RamLavi
Copy link
Member Author

RamLavi commented Jan 6, 2025

Thanks @oshoval !

/approve

@kubevirt-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RamLavi

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubevirt-bot kubevirt-bot merged commit 26eb443 into k8snetworkplumbingwg:main Jan 6, 2025
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants