Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Add compile support of new plugin/driver "vsphere-shared" #1574

Merged
merged 1 commit into from
Jul 13, 2017

Conversation

luomiao
Copy link
Contributor

@luomiao luomiao commented Jul 11, 2017

New plugin: client_plugin/shared_plugin
New driver: client_plugin/drivers/shared
To build the new plugin: make shared-all
Plugin is pushed into: [DOCKER_HUB_REPO]/vsphere-shared:[VERSION_TAG][EXTRA_TAG]
Functions in the new shared_driver are to be implemented.

There are a few layout change in drivers directory.
Common utility functions are grouped under drivers/commonUtilDriver.

The new plugin shares the same plugin_dockerbuild Makefile with original vmdk plugin.
Thus the Dockerfile and config.json are replaced by Dockerfile-template and config.json-template in order to be generic.

Testing result:
test-e2e runalways passed.
Skipped local run of test-e2e runonce due to testbed requirements not ideal, and will use CI for final check.

Copy link
Contributor

@msterin msterin left a comment

Choose a reason for hiding this comment

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

It's a big change so I did not get all the details reviewed but all in all it looks good to me.
A few comments/requests inline.

Makefile Outdated
@@ -42,6 +42,11 @@ build-all: dockerized-build-ui
$(MAKE) --directory=client_plugin $@
$(MAKE) --directory=plugin_dockerbuild all

# build shared plugin
build-shared: dockerized-build-ui
$(MAKE) --directory=client_plugin dockerbuild-shared
Copy link
Contributor

Choose a reason for hiding this comment

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

its generally a good idea to add $(MAKEFLAGS) to nested calls to $(MAKE)

)

// VolumeDriver - vsphere shared plugin volume driver struct
type CommonUtilDriver struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

the name looks redundant. commonutilsdriver.CommonUtilsDriver ? And why its "commonUtils" not simply driver or pluginDriver ?

d.refCounts.Init(d, mountDir, cfg.Driver)
d.mountIDtoName = make(map[string]string)

d.utils = &commonUtilDriver.CommonUtilDriver{
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, that's what I meant. THis looks slightly redundant

os.Exit(1)
}

if reflect.ValueOf(driver).IsNil() == true {
Copy link
Contributor

Choose a reason for hiding this comment

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

so if driver == Nil does not work ?

Copy link
Contributor Author

@luomiao luomiao Jul 12, 2017

Choose a reason for hiding this comment

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

Did some googling and it seems we cannot compare an interface with nil.
And here driver is an interface.
Although I tried to change the code to if driver == nil, compile still works.

Copy link
Contributor

Choose a reason for hiding this comment

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

:-(

@@ -21,7 +21,7 @@
"Options": ["rbind"]
},
{
"Description" : "Location to look for config file (/etc/docker-volume-vsphere.conf)",
"Description" : "Location to look for config file (/etc/BINARY.conf)",
Copy link
Contributor

@msterin msterin Jul 12, 2017

Choose a reason for hiding this comment

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

I strongly recommend using some pattern like %BINARY% to separate from comments etc.
Or better , try using golang template module

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm I am not sure how to use golang template here.
We don't have any go code. This is where we build the docker plugins.
So it's the script world...
It might be an overkill to add and compile some go code here in order to replace texts only :)
Let me add the pattern thing instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed

New plugin: client_plugin/shared_plugin
New driver: client_plugin/drivers/shared
To build the new plugin: make shared-all
Plugin is pushed into: [DOCKER_HUB_REPO]/vsphere-shared:[VERSION_TAG][EXTRA_TAG]
Functions in the new shared_driver are to be implemented.
Copy link
Contributor

@shuklanirdesh82 shuklanirdesh82 left a comment

Choose a reason for hiding this comment

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

some minor comments.

@@ -42,6 +42,11 @@ build-all: dockerized-build-ui
$(MAKE) --directory=client_plugin $@
$(MAKE) --directory=plugin_dockerbuild all

# build shared plugin
build-shared: dockerized-build-ui
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we don't need to invoke dockerized-build-ui anymore, can you please confirm with @msterin ?

// See the License for the specific language governing permissions and
// limitations under the License.

package shared
Copy link
Contributor

Choose a reason for hiding this comment

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

golang naming convention doesn't recommend _ in filename ..shared_driver.go .. it is better to avoid using _ .. how aboutsharedvolume.go?

As you are proposing new files I would suggest to correct the naming.

one more thing, package level comment should be above L15 .. that means before package xxx

Copy link
Contributor Author

@luomiao luomiao Jul 13, 2017

Choose a reason for hiding this comment

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

Hmmm I know that the golang naming convention doesn't recommend _ in package name. But I don't think there is a convention that doesn't recommend _ in filename.
I saw _ in filenames almost everywhere in the codebase :)
In vDVS codebase we already have:

client_plugin/utils/plugin_utils/plugin_utils.go
client_plugin/vmdk_plugin/sanity_test.go
client_plugin/drivers/vmdk/vmdk_driver.go
....

I don't think you ignore them on purpose before? ;)
Also please see my comment below.
Even golang's source code has _ in their filenames :)


package utils

//
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Package level comment should be above L15 .. that means before package xxx
  2. file name should be corrected too

Reference: "By convention, packages are given lower case, single-word names; there should be no need for underscores or mixedCaps."

Generally, file names follow the same convention as package names (https://golang.org/doc/effective_go.html#package-names)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as the comment above...
I don't think filename need to follow this rule...


package main

// A vSphere Shared Docker Data Volume plugin - main
Copy link
Contributor

Choose a reason for hiding this comment

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

need to move above L17

@@ -54,7 +54,8 @@ EXTRA_TAG ?= -dev
PLUGIN_TAG := $(VERSION_TAG)$(EXTRA_TAG)

# plugin name - used as a base for full plugin name and container for extracting rootfs
PLUGIN_NAME=$(DOCKER_HUB_REPO)/docker-volume-vsphere
PLUGIN_NAME ?= $(DOCKER_HUB_REPO)/docker-volume-vsphere
Copy link
Contributor

Choose a reason for hiding this comment

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

curious to know here .. ?= why is this change?

  1. is it passed or set?
  2. don't we need for L58?

Copy link
Contributor Author

@luomiao luomiao Jul 13, 2017

Choose a reason for hiding this comment

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

?= indicates to set the variable only if it's not set/doesn't have a value.
This change is because of we will recursively call the Makefile for the shared plugin, to avoid duplicate Makefile code.
See Line 67 in the new plugin_dockerbuild/Makefile:

shared-clean:
	PLUGIN_NAME=$(SHARED_PLUGIN_NAME) BINARY=$(SHARED_BINARY) $(MAKE) clean

L58 doesn't need ?= because there is no recursively setting of SHARED_PLUGIN_NAME.

// DefaultVMDKPluginLogPath is the default location of log (trace) file
DefaultVMDKPluginLogPath = "/var/log/docker-volume-vsphere.log"
// DefaultSharedPluginConfigPath is the default location of Log configuration file for shared plugin
DefaultSharedPluginConfigPath = "/etc/vsphere-shared.conf"
Copy link
Contributor

Choose a reason for hiding this comment

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

Haven't come across any document file .. would like to make sure to document this newly introduced conf/log file location. will it be in the following PR?

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. We will have readme for the new plugin. And it will be documented there.

"github.com/docker/go-plugins-helpers/volume"
"github.com/vmware/docker-volume-vsphere/client_plugin/drivers/shared"
"github.com/vmware/docker-volume-vsphere/client_plugin/utils/config"
"github.com/vmware/docker-volume-vsphere/client_plugin/utils/plugin_server"
Copy link
Contributor

Choose a reason for hiding this comment

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

I might have missed the PR where plugin_server is introduced ..

see import package seems ugly as go doesn't recommend _ in the PR (not for this PR though)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please don't ignore the _ in "client_plugin" part. :)

@luomiao
Copy link
Contributor Author

luomiao commented Jul 13, 2017

@shuklanirdesh82
I did some googling and found out some discussion about filename naming convention in golang:
https://stackoverflow.com/questions/25161774/what-are-conventions-for-filenames-in-go

Besides that there is special use for _test.go and _linux.go and so on, even golang's own package has _ in their filenames:
https://golang.org/src/compress/bzip2/move_to_front.go

So I guess there isn't a recommendation about not using _ in filenames.

@shuklanirdesh82
Copy link
Contributor

@luomiao

Besides that there is special use for _test.go and _linux.go

_test.go is kept to be picked by go test and identify test easily where as _linux.go & _<architecture> is also being kept for go build to pick up files while building.

@msterin
Copy link
Contributor

msterin commented Jul 13, 2017

Lots of code is not compliant with standards and code style guidance, so examples do not work very well.
The golang.org says in https://blog.golang.org/package-names

 Good package names are short and clear. They are lower case, with no under_scores or mixedCaps. They are often simple nouns, such as:

    time (provides functionality for measuring and displaying time)
    list (implements a doubly linked list)
    http (provides HTTP client and server implementations)

The style of names typical of another language might not be idiomatic in a Go program. Here are two examples of names that might be good style in other languages but do not fit well in Go:

    computeServiceClient
    priority_queue

A Go package may export several types and functions. For example, a compute package could export a Client type with methods for using the service as well as functions for partitioning a compute task across several clients.

Abbreviate judiciously. Package names may be abbreviated when the abbreviation is familiar to the programmer. Widely-used packages often have compressed names:

    strconv (string conversion)
    syscall (system call)
    fmt (formatted I/O)

On the other hand, if abbreviating a package name makes it ambiguous or unclear, don't do it. 

BTW, they actually advice against generic name. e.g. util :-)

So I am with @shuklanirdesh82 here, though IMO it's not a huge issue and we are not compliant in many other places already. Still, I suggest something like dockvolplugin. Or keep it as-is.

@luomiao
Copy link
Contributor Author

luomiao commented Jul 13, 2017

I don't mind if we apply this rule to vDVS code!
But please be consistent.
I saw that there is newly checked in files like:
https://github.com/vmware/docker-volume-vsphere/blob/master/tests/e2e/volume_access_test.go (the first '_' :))
https://github.com/vmware/docker-volume-vsphere/blob/master/tests/utils/esx/vim_cmd.go
https://github.com/vmware/docker-volume-vsphere/blob/master/tests/utils/dockercli/docker_mgmt.go

And of course as @msterin mentioned, we didn't follow such rule before. All files under client_plugin mainly are not compliant with this rule.

So if someone want to open an issue and adjust all the current filenames, I won't have an opinion.
But I don't think we should apply a rule suddenly and leaving filenames like
client_plugin/drivers/vmdk/vmdk_driver.go and client_plugin/drivers/shared/shareddriver.go there at the same time.
So I suggest that, if we REALLY care about the filename naming, please update the current filenames, and then apply to future PRs :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants