[go: up one dir, main page]

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

code clean for pkg/utils.go IsValidMACAddress #238

Merged
merged 1 commit into from
Feb 15, 2023
Merged

code clean for pkg/utils.go IsValidMACAddress #238

merged 1 commit into from
Feb 15, 2023

Conversation

yanggangtony
Copy link
Contributor
@yanggangtony yanggangtony commented Jan 14, 2023

Signed-off-by: yanggang gang.yang@daocloud.io

/kind cleanup

for _, invalidMACAddress := range invalidMACAddresses {
			if bytes.Equal(addr, invalidMACAddress) {
				valid = false
				break
			}
		}

the code will reduce the loop cost , when it is first found to be false . just break and skip next process.

And

if err != nil || linkObj.Attrs() == nil {
		return fmt.Errorf("failed to get netlink device with name %q: %v", ifName, err)
	}

will fix the potential panic, when linkObj.Attrs() is nil..

@coveralls
Copy link
coveralls commented Jan 30, 2023

Pull Request Test Coverage Report for Build 3919189276

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 1 (0.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 38.027%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/utils/utils.go 0 1 0.0%
Totals Coverage Status
Change from base Build 3540793813: 0.0%
Covered Lines: 424
Relevant Lines: 1115

💛 - Coveralls

@SchSeba
Copy link
Collaborator
SchSeba commented Feb 5, 2023

/lgtm

thanks for the contribution!

@yanggangtony
Copy link
Contributor Author

thanks for review.
@SchSeba

@wizhaoredhat
Copy link
Contributor

/lgtm

@@ -168,7 +168,7 @@ func AnnounceIPs(ifName string, ipConfigs []*current.IPConfig) error {

// Retrieve the interface name in the container.
linkObj, err := myNetLink.LinkByName(ifName)
if err != nil {
if err != nil || linkObj.Attrs() == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

is there really a case where netlink LinkByName completes successfully but returned Attr() is nil ?

I think not, and if there is, i think we should panic as it would be an un-expected behaviour of netlink (or any other impl of the interface)

IMO this additional condition should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@adrianchiris
thanks for review.
i read the netlink LinkByName code again.

func (h *Handle) linkByNameDump(name string) (Link, error) {
	links, err := h.LinkList()
	if err != nil {
		return nil, err
	}

	for _, link := range links {
		if link.Attrs().Name == name {
			return link, nil
		}
	}
	return nil, LinkNotFoundError{fmt.Errorf("Link %s not found", name)}
}

the lib also not judge the link.Attrs()==nil , So we may relay on it .
and delete the case for nil

Signed-off-by: yanggang <gang.yang@daocloud.io>
Copy link
Collaborator
@SchSeba SchSeba left a comment

Choose a reason for hiding this comment

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

/lgtm

@adrianchiris adrianchiris merged commit 338529e into k8snetworkplumbingwg:master Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants