Skip to content

#26639: Local NFS volumes do not resolve hostnames#27329

Merged
justincormack merged 1 commit intomoby:masterfrom
dattatrayakumbhar:26639_nfs_volume_with_hostname
Nov 9, 2016
Merged

#26639: Local NFS volumes do not resolve hostnames#27329
justincormack merged 1 commit intomoby:masterfrom
dattatrayakumbhar:26639_nfs_volume_with_hostname

Conversation

@dattatrayakumbhar
Copy link
Contributor

@dattatrayakumbhar dattatrayakumbhar commented Oct 12, 2016

fixes #26639

- What I did
Implemented code for mounting local NFS with hostname

  • How I did it
    Added method GetAddress, to get address/hostname from options. Added another Method IsIP, to verify if option has IP or Address. If option has hostname then used LookupHost built in function to convert to IPAddress.

- How to verify it

  1. Build a developer container with latest docker/master and this PR
  2. Start docker daemon with copying binaries with hack/make.sh binary.
  3. Create docker volume with "docker volume create -o type=nfs -o o=addr=nfs-server,rw -o device=:/nfsdir --name test4"
    Note. Please make sure “nfs-server” is resolvable with Ip address.
  4. Create container with “docker run -it --rm -v test4:/storage datkumbh/nfs sh”
  5. Verify that container created successfully and nfsdir mounted in /storage.

- Description for the changelog

  1. Added a GetAddress method in volume/local/local_unix.go
  2. Added a IsIP method in volume/local/local_unix.go to verify if hostname is IP or return blank
  3. Added a support to convert hostname to IpAddress if option is wit hostname

*- A picture of a cute animal *

image

@dattatrayakumbhar dattatrayakumbhar force-pushed the 26639_nfs_volume_with_hostname branch 2 times, most recently from da8360c to 275f850 Compare October 13, 2016 08:34
Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

The host lookup should be done before every mount() syscall rather than caching addresses.

Copy link
Member

Choose a reason for hiding this comment

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

No need for strings.Contains, a lookup to if addr := GetAddress(v.opts.MountOpts); addr != "" { ... } should suffice.

Copy link
Member

Choose a reason for hiding this comment

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

No need for IsIP. net.ResolveIPAddr will work just fine here if it is a hostname or an IP.

Copy link
Member

Choose a reason for hiding this comment

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

Please don't export this.

Copy link
Member

Choose a reason for hiding this comment

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

function is not needed.

Copy link
Member

Choose a reason for hiding this comment

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

No src/

@cpuguy83
Copy link
Member

08:35:30 These files are not properly gofmt'd:
08:35:30 - volume/local/local_unix.go

Copy link
Contributor

Choose a reason for hiding this comment

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

This would also match maddr= or something on some other mount type. Also we should probably just do this for nfs, as addr might mean something else on other mount types (there might be other network filesystems with a similar issue but these could be added).

Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a helpful log message

Copy link
Contributor

Choose a reason for hiding this comment

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

Not helpful

Copy link
Contributor

Choose a reason for hiding this comment

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

as above

Copy link
Contributor

Choose a reason for hiding this comment

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

The opslist should already split on , so I don't see how this case could happen?

Copy link
Member

Choose a reason for hiding this comment

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

Looks like this can be removed instead of commented

Copy link
Member

Choose a reason for hiding this comment

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

You can do

if err != nil {
    return errors.Wrapf(err, "unable to resolve hostname"
}

So that you don't need an "else".

Perhaps include the actual hostname in the error message, as that may be valuable information

Copy link
Member

Choose a reason for hiding this comment

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

Do we need a regex here for MountType? Or simply v.opts.MountType == "nfs"

Copy link
Member

Choose a reason for hiding this comment

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

Also, given that we'll still check if an addr is actually set below, checking addr= may not even be nescessary here (but open to suggestions)

Copy link
Member

Choose a reason for hiding this comment

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

Should we replace the value of v.opts.MountOps here, or should we use a copy, and leave the original options as-is? @cpuguy83 ?

Copy link
Member

Choose a reason for hiding this comment

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

Copy please

@dattatrayakumbhar
Copy link
Contributor Author

Updated PR with changed.Can someone please review it ?

@dattatrayakumbhar
Copy link
Contributor Author

@thaJeztah @cpuguy83
Updated PR. Please take a look.

Copy link
Member

@thaJeztah thaJeztah Oct 20, 2016

Choose a reason for hiding this comment

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

nit: to reduce code duplication, you could put opts1 := v.opts.MountOpts outside the if ... (at line 72), and always use the copy (opts1) at line 85

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @thaJeztah.
Removed duplication. Updated PR with same detail

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM, but left one suggestion

@dattatrayakumbhar dattatrayakumbhar force-pushed the 26639_nfs_volume_with_hostname branch 2 times, most recently from f14def9 to 522be5e Compare October 20, 2016 15:20
@thaJeztah
Copy link
Member

ping @justincormack PTAL

@dattatrayakumbhar
Copy link
Contributor Author

@justincormack , Can you please take a look ?

Copy link
Member

Choose a reason for hiding this comment

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

Should be compiled at the package level rather than on every mount call.

But do we really need to match the regex here vs just iterating the opts with getAddress?
In most cases the opts list should be small enough to not matter.
WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Should also always check errors.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I suggested doing that in #27329 (comment), perhaps we should skip the regex (since getAddress is checking for it anyway to verify it's not empty)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I think It can be in getAddress function ,Will remove it.

Copy link
Member

Choose a reason for hiding this comment

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

This wrap message is not really adding any context and just duplicating what is already there since the error from net will be lookup <addrValue>: no such host.

Maybe something like error resolving passed in nfs address.
Also, errors should always be started as lower case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed error message

@GordonTheTurtle GordonTheTurtle added the dco/no Automatically set by a bot when one of the commits lacks proper signature label Oct 25, 2016
@dattatrayakumbhar dattatrayakumbhar force-pushed the 26639_nfs_volume_with_hostname branch from 7fc7a31 to 18a2457 Compare October 25, 2016 13:55
@GordonTheTurtle GordonTheTurtle removed the dco/no Automatically set by a bot when one of the commits lacks proper signature label Oct 25, 2016
@thaJeztah
Copy link
Member

ping @cpuguy83 PTAL

@dattatrayakumbhar04 can you squash your commits?

@dattatrayakumbhar dattatrayakumbhar force-pushed the 26639_nfs_volume_with_hostname branch 2 times, most recently from 3457450 to 20cd153 Compare October 26, 2016 06:22
Copy link
Member

Choose a reason for hiding this comment

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

getAddress is only defined for linux, but not for Windows.
Can probably move to a platform independent file.

@dattatrayakumbhar dattatrayakumbhar force-pushed the 26639_nfs_volume_with_hostname branch from 20cd153 to 7d3acb5 Compare October 27, 2016 07:59
@dattatrayakumbhar
Copy link
Contributor Author

dattatrayakumbhar commented Oct 28, 2016

@cpuguy83 @justincormack @thaJeztah
Updated PR and all checks are passed now.
Please let me know if any changes need to be done

Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@thaJeztah thaJeztah Oct 31, 2016

Choose a reason for hiding this comment

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

should we replace, including the addr=? Is there a chance another option has the same string?

Copy link
Member

Choose a reason for hiding this comment

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

e.g.

mountOpts = strings.Replace(mountOpts, "addr=" + addrValue, "addr=" + ipAddr.String(), 1)

(maybe not needed, just wondering)

Copy link
Member

Choose a reason for hiding this comment

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

Good idea

@dattatrayakumbhar dattatrayakumbhar force-pushed the 26639_nfs_volume_with_hostname branch 2 times, most recently from 638c95e to ce87725 Compare November 1, 2016 03:11
@dattatrayakumbhar
Copy link
Contributor Author

@cpuguy83 @thaJeztah @justincormack
Updated PR with changes.

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to check for addr= at the start of the item.

Copy link
Contributor

Choose a reason for hiding this comment

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

please avoid unrelated whitespace changes

Copy link
Contributor

Choose a reason for hiding this comment

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

and here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@justincormack
I have made changes PTAL

@GordonTheTurtle GordonTheTurtle added the dco/no Automatically set by a bot when one of the commits lacks proper signature label Nov 8, 2016
@dattatrayakumbhar dattatrayakumbhar force-pushed the 26639_nfs_volume_with_hostname branch from 95656ec to 1273d65 Compare November 8, 2016 05:28
@GordonTheTurtle GordonTheTurtle removed the dco/no Automatically set by a bot when one of the commits lacks proper signature label Nov 8, 2016
Signed-off-by: dattatrayakumbhar04 <dattatraya.kumbhar@gslab.com>
@dattatrayakumbhar dattatrayakumbhar force-pushed the 26639_nfs_volume_with_hostname branch from 1273d65 to 668fa8a Compare November 8, 2016 08:43
@justincormack
Copy link
Contributor

LGTM from under the sea!

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.

Local NFS volumes do not resolve hostnames

5 participants