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

Add zones support for vSphere cloud provider(in-tree) #66795

Merged
merged 3 commits into from
Aug 8, 2018

Conversation

jiatongw
Copy link

@jiatongw jiatongw commented Jul 30, 2018

What this PR does / why we need it:
This PR added zones(built-in node labels) support for vSphere cloud provider(in-tree). More details can be found in the issue as below.

Which issue(s) this PR fixes :
Partially fixes phase 1 of issue #64021

Special notes for your reviewer:

Release note:

Add zones support for vSphere cloud provider

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 30, 2018
@jiatongw
Copy link
Author

jiatongw commented Jul 30, 2018

/assign @dougm

func (vs *VSphere) GetZoneByProviderID(ctx context.Context, providerID string) (cloudprovider.Zone, error) {

return cloudprovider.Zone{}, nil
}
Copy link
Author

Choose a reason for hiding this comment

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

GetZoneByNodeName() and GetZoneByProviderID() are called by out-tree cloud provider, which have not been tested yet. I have completed the code for those two funcs but for now I leave it just by returning an empty zone. If this is not a good way, please comment.

@neolit123
Copy link
Member

@kubernetes/sig-cloud-provider-pr-reviews
@kubernetes/vmware

@k8s-ci-robot k8s-ci-robot added the sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. label Jul 30, 2018
Copy link
Member

@neolit123 neolit123 left a comment

Choose a reason for hiding this comment

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

thanks for the PR @jiatongw
i've added some comments, mostly about whitespace.

re: [2]
i see that the files use glog.Errorf() instead of propagating errors back to the caller which isn't exactly a good practice.
feel free to ignore this for now, but this type of glog binding is undesired and possibly needs a cleanup in a separate PR.

thanks.

svm, err := s.FindByUuid(ctx, dc.Datacenter, vmUUID, true, nil)
if err != nil {
glog.Errorf("Failed to find VM by UUID. VM UUID: %s, err: %+v", vmUUID, err)
return nil, err
Copy link
Member

Choose a reason for hiding this comment

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

would it be better to return the above error using fmt.Errorf() instead of calling glog.Errorf?
[2]

Copy link
Author

Choose a reason for hiding this comment

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

thanks for catching this! But looking at other code in this file, it seems that glog.Errorf is using more frequently. @dougm there are 44 places that using glog.Errof. What do you think about this or fmt.Errorf?

Copy link
Member

Choose a reason for hiding this comment

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

There are cases in VCP where return fmt.Errorf is used too. I think its ok to leave as glog.Errorf as it can be useful to have the filename:linenumber info that it provides. We should probably have a separate issue to clean up the the logging in VCP. In this particular case, looks like this code should be calling Datacenter.GetVMByUUID instead as I commented below.

defer t.Client.Logout(ctx)

return f(t.Client)

Copy link
Member

Choose a reason for hiding this comment

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

please, remove this empty line.
[1]

}

func (t TagManagers) WithClient(ctx context.Context, f func(client *tags.RestClient) error) error {
err := t.Client.Login(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

can be changed to:

if err := t.Client.Login(ctx); err != nil {
...


zone := cloudprovider.Zone{}
vsi, err := vs.getVSphereInstanceForServer(vs.cfg.Workspace.VCenterIP, ctx)

Copy link
Member

Choose a reason for hiding this comment

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

[1]

ctx,
vmHost,
)

Copy link
Member

Choose a reason for hiding this comment

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

[1]

dc, err := vclib.GetDatacenter(ctx, vsi.conn, vs.cfg.Workspace.Datacenter)
if err != nil {
glog.Errorf("Cannot connect to datacenter. Get zone for node %s error", nodeName)
return cloudprovider.Zone{}, err
Copy link
Member

Choose a reason for hiding this comment

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

[2]


if err != nil {
glog.Errorf("Cannot connect to vsphere. Get zone for node %s error", nodeName)
return cloudprovider.Zone{}, err
Copy link
Member

Choose a reason for hiding this comment

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

[2]

vmHost, err := dc.GetHostByVMUUID(ctx, vs.vmUUID)
if err != nil {
glog.Errorf("Cannot find VM runtime host. Get zone for node %s error", nodeName)
return cloudprovider.Zone{}, err
Copy link
Member

Choose a reason for hiding this comment

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

[2]

tag, err := client.GetTag(ctx, value)
if err != nil {
glog.Errorf("Get tag %s error", value)
return err
Copy link
Member

Choose a reason for hiding this comment

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

[2]

category, err := client.GetCategory(ctx, tag.CategoryID)
if err != nil {
glog.Errorf("Get category %s error", value)
return err
Copy link
Member

Choose a reason for hiding this comment

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

[2]

Copy link
Member

@dougm dougm left a comment

Choose a reason for hiding this comment

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

@jiatongw looking good. You'll need to restore the Godeps/LICENSES files, not sure why there are "103,568 deletions"?

glog.Errorf("Unable to find VM by UUID. VM UUID: %s", vmUUID)
return nil, ErrNoVMFound
}
virtualMachine := VirtualMachine{object.NewVirtualMachine(dc.Client(), svm.Reference()), dc}
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 you can use the existing Datacenter.GetVMByUUID method here instead of copy-n-paste.

return TagManagers{Client: tags.NewClient(vsURL, connection.Insecure, "")}
}

func (t TagManagers) WithClient(ctx context.Context, f func(client *tags.RestClient) 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.

Typo in file name: tagmanegers.go

Looks like this should just be a func in vclib, rather than a new package. And longer term will go away when vmware/govmomi#1179 is fixed.

Copy link
Author

Choose a reason for hiding this comment

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

Ok. So it's good that I move this file into vclib root floder and delete tagmanagers folder?

Copy link
Member

Choose a reason for hiding this comment

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

func withTagsClient in vsphere.go should be fine. No need for the TagManagers type. If you do feel there's a need for the type, let's call it tagsClient instead of TagManagers. And no need for a separate file as this function will go away when vmware/govmomi#1179 is fixed.

@jiatongw jiatongw force-pushed the zones_vendor branch 2 times, most recently from e16d6e3 to bbd02b7 Compare August 2, 2018 08:15
// GetHostByVMUUID gets the host object from the given vmUUID
func (dc *Datacenter) GetHostByVMUUID(ctx context.Context, vmUUID string) (*types.ManagedObjectReference, error) {
virtualMachine, err := dc.GetVMByUUID(ctx, vmUUID)
var vmMo mo.VirtualMachine
Copy link
Author

Choose a reason for hiding this comment

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

Called dc.GetVMByUUID() here

@jiatongw
Copy link
Author

jiatongw commented Aug 2, 2018

Ready for review. Added withTagsClient func in vsphere.go and remove tagmanagers/ folder.
@dougm

@@ -808,8 +816,7 @@ func (vs *VSphere) LoadBalancer() (cloudprovider.LoadBalancer, bool) {

// Zones returns an implementation of Zones for vSphere.
func (vs *VSphere) Zones() (cloudprovider.Zones, bool) {
glog.V(1).Info("The vSphere cloud provider does not support zones")
return nil, false
return vs, true
Copy link
Member

Choose a reason for hiding this comment

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

As we are discussing if vcp config should be required on the nodes, maybe we should return false here if there is no vcenter configured?

Copy link
Author

Choose a reason for hiding this comment

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

you mean no vcp.conf file or no [labels] field in vcp.conf file?
If it's the second case, since the kubelet code will detect whether the zone and region is "" or not. If it's empty, the kubelet code will handle this. So we can just return vs, true here.

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking no vcenter == if vs.cfg.Workspace.VCenterIP == "": return false

Copy link
Author

Choose a reason for hiding this comment

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

If there is no vcp.conf file, Zones() maybe even not called since get node return No resources found

Copy link
Author

Choose a reason for hiding this comment

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

I see. one more concern, Should we also apply this check to other functions/interfaces in vsphere.go which they use vcp.conf file?

Copy link
Author

Choose a reason for hiding this comment

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

Ok. I see there are other similar checks like this already applied in vsphere.go . What about
if vs.cfg == "": return false? make it more simple

Copy link
Member

Choose a reason for hiding this comment

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

Yes, checking vs.cfg == nil should work fine.

}

func (vs *VSphere) GetZoneByNodeName(ctx context.Context, nodeName k8stypes.NodeName) (cloudprovider.Zone, error) {
return cloudprovider.Zone{}, nil
Copy link
Member

Choose a reason for hiding this comment

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

Should probably return cloudprovider.NotImplemented instead of nil here.

}

func (vs *VSphere) GetZoneByProviderID(ctx context.Context, providerID string) (cloudprovider.Zone, error) {
return cloudprovider.Zone{}, nil
Copy link
Member

Choose a reason for hiding this comment

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

Should probably return cloudprovider.NotImplemented instead of nil here.

}
client := vsi.conn
err = withTagsClient(ctx, client, func(client *tags.RestClient) error {
tags, err := client.ListAttachedTags(
Copy link
Member

Choose a reason for hiding this comment

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

This a short parameter list, no need for multiple lines: client.ListAttachedTags(ctx, vmHost)

client := vsi.conn
err = withTagsClient(ctx, client, func(client *tags.RestClient) error {
tags, err := client.ListAttachedTags(ctx, vmHost)
if err != nil {
Copy link
Author

Choose a reason for hiding this comment

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

Changed to one line arguments

Copy link
Author

@jiatongw jiatongw Aug 3, 2018

Choose a reason for hiding this comment

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

And removed all not necessary blank lines, fixed problems in the above conversations.
@dougm

@jiatongw
Copy link
Author

jiatongw commented Aug 3, 2018

For those who review this PR, my changes on k8s code are the file vsphere.go and vclib/datacenter.go. The other 40 changes of file are because I updated the vmware/govmomi vendor and used Godep. So you can ignore those file changes when reviewing this PR

Copy link
Member

@dougm dougm left a comment

Choose a reason for hiding this comment

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

/ok-to-test
/approve

return nil, err
}
host := vmMo.Summary.Runtime.Host
glog.Infof("%s host is %s", virtualMachine.Reference(), vmMo.Summary.Runtime.Host)
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 make use of the host variable here too.

Zones implementation for vSphere cloud provider needs dependencies
which are not included in current vmware/govmomi vendor. So this
update added "vapi" package to support zones.
@k8s-ci-robot
Copy link
Contributor

@jiatongw: GitHub didn't allow me to assign the following users: dep-approvers.

Note that only kubernetes members and repo collaborators can be assigned.
For more information please see the contributor guide

In response to this:

/assign @dep-approvers

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@cblecker
Copy link
Member

cblecker commented Aug 6, 2018

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 6, 2018
@jiatongw
Copy link
Author

jiatongw commented Aug 6, 2018

/test pull-kubernetes-bazel-test

@cblecker
Copy link
Member

cblecker commented Aug 6, 2018

@jiatongw This is a legitimate test failure. Please review.

@jiatongw
Copy link
Author

jiatongw commented Aug 6, 2018

@cblecker Yes, I have to modify the test func in _test.go file

@jiatongw
Copy link
Author

jiatongw commented Aug 6, 2018

@dougm Modified TestZone() in vsphere_test.go. We need test both GetZone() and Zones() interface here. Currently the we don't have simulator support, so the GetZone() will return an empty zone and nil error. Zones() will return true because we implemented this interface.

@dougm
Copy link
Member

dougm commented Aug 6, 2018

@jiatongw yes, that's good for now. I am currently working on vcsim support for the tags API.

@jiatongw
Copy link
Author

jiatongw commented Aug 6, 2018

@cblecker tests passed. Please have a review, thanks!

@dougm
Copy link
Member

dougm commented Aug 7, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 7, 2018
@cblecker
Copy link
Member

cblecker commented Aug 7, 2018

/approve
Approving for godeps.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cblecker, dougm, jiatongw

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 7, 2018
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 67052, 67094, 66795). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 9d260ff into kubernetes:master Aug 8, 2018
dougm added a commit to dougm/kubernetes that referenced this pull request Aug 23, 2018
- Add tests for GetZones()

- Fix bug where a host tag other than region or zone caused an error

- Fix bug where GetZones() errored if zone tag was set, but region was not

Follow up to PR kubernetes#66795 / towards kubernetes#64021
k8s-github-robot pushed a commit that referenced this pull request Aug 23, 2018
Automatic merge from submit-queue (batch tested with PRs 66980, 67604, 67741, 67715). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

vsphere: add tests for Cloud Provider Zones implementation

**What this PR does / why we need it**:

- Add tests for GetZones()

- Fix bug where a host tag other than region or zone caused an error

- Fix bug where GetZones() errored if zone tag was set, but region was not

Follow up to PR #66795 / towards #64021

**Release note**:

```release-note
NONE
```
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Sep 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants