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

host-local: add ifname to file tracking IP address used #203

Merged
merged 10 commits into from
Oct 10, 2018

Conversation

mccv1r0
Copy link
Member

@mccv1r0 mccv1r0 commented Sep 18, 2018

host-local: add ifname to file tracking IP address used

Obtain ifname from CmdArgs and pass to backend
In the file tracking the IP address in use, add ifname to the line after ContainerID
Update host-local tests to use ifname along with ContainerID in storage file

Fixes #164

…ine of file tracking the IP address used by ContainerID

Update host-local tests to use ifname along with ContainerID
in store file

Signed-off-by: Michael Cambria <mcambria@redhat.com>
@squeed
Copy link
Member

squeed commented Sep 19, 2018

We also have to handle upgrades over an existing store. So, when you get a Delete, and there is a reservation for the container ID without the interface, we should delete it too.

@@ -99,7 +99,9 @@ func (s *Store) Release(ip net.IP) error {

// N.B. This function eats errors to be tolerant and
// release as much as possible
func (s *Store) ReleaseByID(id string) error {
func (s *Store) ReleaseByID(id string, ifname string) error {

Copy link
Member

Choose a reason for hiding this comment

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

spurious newline added...

@@ -65,7 +65,7 @@ func (s *Store) Reserve(id string, ip net.IP, rangeID string) (bool, error) {
if err != nil {
return false, err
}
if _, err := f.WriteString(strings.TrimSpace(id)); err != nil {
if _, err := f.WriteString(strings.TrimSpace(id) + "\n" + ifname); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

@mccv1r0 your concerns WRT Windows are probably valid. We could use \r\n if you want to be more compatible there.

Copy link
Member

Choose a reason for hiding this comment

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

Nobody seemed to like my suggestion of using ASCII BEL :-)

}
return nil
})

if (!found) && (err == nil) {
Copy link
Member

Choose a reason for hiding this comment

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

You actually don't need the () around !found since it's a bool already.

Also, maybe a comment here explaining that this block is for backwards compatibility when reading files written by a previous version of the plugin that didn't store interface name?

Copy link
Contributor

Choose a reason for hiding this comment

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

Please ensure you've run go fmt. It should remove those unnecessary parens (and help prevent other stylistic inconsistencies).

}
return nil
})

if (!found) && (err == nil) {
err = filepath.Walk(s.dataDir, func(path string, info os.FileInfo, err error) error {
Copy link
Member

Choose a reason for hiding this comment

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

Another approach would be to pull the directory Walk/data compare/file remove code out to a new function, and then just call it twice; once for id+\n+iface, and if that wasn't found a second time for just 'id'.

plugins/ipam/host-local/host_local_test.go Show resolved Hide resolved
Add two interfaces (e.g. eth0, eth1) to the same container.
Ensure each file now has ContainerID and ifname.
Delete one, ensure that the right file was deleted.

Add an interface using just ContainerID in the file.
Delete to verify we are still backwards compatible with any
files created using earlier verison of host-local plugin.
Copy link
Member

@dcbw dcbw left a comment

Choose a reason for hiding this comment

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

/lgtm

@dcbw
Copy link
Member

dcbw commented Oct 2, 2018

Testcase failures are unrelated and will be fixed by #207

…ine of file tracking the IP address used by ContainerID

Update host-local tests to use ifname along with ContainerID
in store file

Signed-off-by: Michael Cambria <mcambria@redhat.com>
Add two interfaces (e.g. eth0, eth1) to the same container.
Ensure each file now has ContainerID and ifname.
Delete one, ensure that the right file was deleted.

Add an interface using just ContainerID in the file.
Delete to verify we are still backwards compatible with any
files created using earlier verison of host-local plugin.
@dcbw dcbw merged commit a326f9d into containernetworking:master Oct 10, 2018
@mccv1r0 mccv1r0 deleted the issue164 branch October 10, 2018 17:01
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.

5 participants