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

status-monitor: Filter out interface with no name #46

Merged
merged 2 commits into from
Dec 12, 2022

Conversation

AlonaKaplan
Copy link
Member

@AlonaKaplan AlonaKaplan commented Dec 11, 2022

What this PR does / why we need it:
The interface/network name is used to build the FQDN. Therefore, interfaces reported without a name are filtered out.
The reported interface may not have a name from multiple reasons. e.g the interface was added manually in the guest, the interface MAC address was change manually, the interface is SRIOV.

Special notes for your reviewer:
This PR is removing the empty name filtering from the zonemanger and moves it to a dedicated filter.

Release note:

NONE

@kubevirt-bot kubevirt-bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Dec 11, 2022
@@ -54,7 +54,9 @@ func (r *VirtualMachineInstanceReconciler) Reconcile(ctx context.Context, reques
// Error reading the object - requeue the request.
return ctrl.Result{}, err
}
err = r.ZoneManager.UpdateZone(request.NamespacedName, FilterMultusNonDefaultInterfaces(vmi.Status.Interfaces, vmi.Spec.Networks))
filteredInterfaces := FilterMultusNonDefaultInterfaces(vmi.Status.Interfaces, vmi.Spec.Networks)
filteredInterfaces = FilterInterfacesWithNoName(vmi.Status.Interfaces) // The interface/network name is used to build the FQDN, therefore, interfaces reported without a name are filtered out
Copy link
Collaborator

@oshoval oshoval Dec 11, 2022

Choose a reason for hiding this comment

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

Aint you overriding the list that was created in the previous line ?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes! Good catch:) The linter cached it as well.

@AlonaKaplan AlonaKaplan force-pushed the filter_no_name branch 2 times, most recently from 83bd2be to 9fe933d Compare December 11, 2022 12:50
Copy link
Collaborator

@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.

Thanks
Please add example on PR desc about SRIOV that for example a SRIOV interface without mac wouldn't have a network name

Might even worth release notes ? not crucial as we don't collect it yet

Please consider adding that it was filtered, but you refactor it to be in the right place
so it will be easier to understand why the ZM is changed

Please consider prefixing PR desc with status-monitor:. ...

@@ -30,3 +30,13 @@ func getDefaultNetwork(networks []v1.Network) *v1.Network {
func isDefaultNetwork(net v1.Network) bool {
return net.Pod != nil || (net.Multus != nil && net.Multus.Default)
}

func FilterInterfacesWithNoName(ifaces []v1.VirtualMachineInstanceNetworkInterface) []v1.VirtualMachineInstanceNetworkInterface {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think filter functions need to be named according what they do keep
FilterNamedInterfaces

And then the logic might be something like

if iface.Name == "" {
continue
}

if desirable - "return early"

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed the name.

@@ -54,7 +54,9 @@ func (r *VirtualMachineInstanceReconciler) Reconcile(ctx context.Context, reques
// Error reading the object - requeue the request.
return ctrl.Result{}, err
}
err = r.ZoneManager.UpdateZone(request.NamespacedName, FilterMultusNonDefaultInterfaces(vmi.Status.Interfaces, vmi.Spec.Networks))
filteredInterfaces := FilterMultusNonDefaultInterfaces(vmi.Status.Interfaces, vmi.Spec.Networks)
filteredInterfaces = FilterInterfacesWithNoName(filteredInterfaces) // The interface/network name is used to build the FQDN, therefore, interfaces reported without a name are filtered out
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lets remove please the comment, it is pretty trivial here
also comment should be line above the code usually imo

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 find the comment useful and not trivial.
Moved it to be above the code.

Copy link
Collaborator

@oshoval oshoval Dec 12, 2022

Choose a reason for hiding this comment

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

Imo it is very trivial and the comment is redundant
code should be (and it is) self explanatory

Moreover since name is part of the FQDN of course its needed

@@ -30,3 +30,13 @@ func getDefaultNetwork(networks []v1.Network) *v1.Network {
func isDefaultNetwork(net v1.Network) bool {
return net.Pod != nil || (net.Multus != nil && net.Multus.Default)
}

func FilterInterfacesWithNoName(ifaces []v1.VirtualMachineInstanceNetworkInterface) []v1.VirtualMachineInstanceNetworkInterface {
Copy link
Collaborator

@oshoval oshoval Dec 12, 2022

Choose a reason for hiding this comment

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

btw since it is used in the same package, maybe it can be lower cased first character ?
If so same for function on line 7

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 find it much more readable and safe to have public API to the interface_filter file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

but it is used internally only, we don't expose stuff that is not need to be exposed

Copy link
Member Author

Choose a reason for hiding this comment

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

The public method are the methods that the interace_file exposes. I want it to be clear.
It is even considered a good practice to have the unit tests in a separate package, so it will be clear what is the API of the tested file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But we don't have it on a separate package atm.
also API is for stuff that is used outside of the module, not inside.
else i would suggest for example that once we move unit tests to their own package
then we can expose it

Copy link
Member Author

Choose a reason for hiding this comment

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

moved the filter tests to a separate package.

@AlonaKaplan AlonaKaplan changed the title Filter out interface with no name status_monitor: Filter out interface with no name Dec 12, 2022
@AlonaKaplan AlonaKaplan changed the title status_monitor: Filter out interface with no name status-monitor: Filter out interface with no name Dec 12, 2022
@AlonaKaplan
Copy link
Member Author

Thanks Please add example on PR desc about SRIOV that for example a SRIOV interface without mac wouldn't have a network name

Might even worth release notes ? not crucial as we don't collect it yet

Please consider adding that it was filtered, but you refactor it to be in the right place so it will be easier to understand why the ZM is changed

Please consider prefixing PR desc with status-monitor:. ...

Added the prefix and explanation why the code was removed form the zone manager. I don't think the sriov example it relevant here. The reported interface may not have a name from multiple reasons. e.g the interface was added manually in the guest, the interface MAC address was change manually in the guest and also the SRIOV case. I think that for kubesecondarydns it is irrelevant why there is no name, the only relevant part is that if there is no name, there is no FQDN.

@oshoval
Copy link
Collaborator

oshoval commented Dec 12, 2022

Thanks Please add example on PR desc about SRIOV that for example a SRIOV interface without mac wouldn't have a network name
Might even worth release notes ? not crucial as we don't collect it yet
Please consider adding that it was filtered, but you refactor it to be in the right place so it will be easier to understand why the ZM is changed
Please consider prefixing PR desc with status-monitor:. ...

Added the prefix and explanation why the code was removed form the zone manager. I don't think the sriov example it relevant here. The reported interface may not have a name from multiple reasons. e.g the interface was added manually in the guest, the interface MAC address was change manually in the guest and also the SRIOV case. I think that for kubesecondarydns it is irrelevant why there is no name, the only relevant part is that if there is no name, there is no FQDN.

I understand, what about expressing all those examples in the PR description ?
It might be nice to have it listed

The interface/network name is used to build the FQDN.
Therefore, interfaces reported without a name are filtered out.

Signed-off-by: Alona Paz <alkaplan@redhat.com>
To allow writing the tests as though they were a real user of the package.

Signed-off-by: Alona Paz <alkaplan@redhat.com>
Copy link
Collaborator

@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.

Thanks

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 12, 2022
@AlonaKaplan
Copy link
Member Author

/approve

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AlonaKaplan

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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 12, 2022
@kubevirt-bot kubevirt-bot merged commit dfbddff into kubevirt:main Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants