-
-
Notifications
You must be signed in to change notification settings - Fork 10
Fix "index out of range" error while getting IP #25
Conversation
Thank you for your contribution. I've just checked and your commit doesn't appear to be signed-off. That's something we need before your Pull Request can be merged. Please see our contributing guide. |
When getting IP for the created container, if the host does not has eth0 as the default network interface, the "index out of range" error is generated. This gets the correct interface for the namespace of the container PID. Signed-off-by: Carlos de Paula <[email protected]>
if config.Sandbox == netns { | ||
for _, ipConfig := range config.IPConfigs { | ||
serviceMap.Add(name, &ipConfig.IP) | ||
log.Printf("%s has IP: %s.\n", name, &ipConfig.IP) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, why aren't we doing a break out of the loops here?
serviceMap.Add(name, &ipConfig.IP) | ||
log.Printf("%s has IP: %s.\n", name, &ipConfig.IP) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's discover the IP in the loop, then act on it after the loop, either from breaking out or from finishing without a result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The network discovery could be improved. Please can you extract it to its own function before merge.
This has been replaced by the refactor on PR #26 |
Description
When getting IP for the created container, if the host does not has eth0
as the default network interface, the "index out of range" error is
generated.
This gets the correct interface for the namespace of the container PID.
Motivation and Context
This fixes the error on issue #24 .
How Has This Been Tested?
Tested on a host where the default network interface is
eth1
that generated the reported error. With this fix, the IP is returned correctly.Types of changes
Checklist:
Commits:
git commit -s
for the Developer Certificate of Origin (DCO)Code:
Docs: