-
Notifications
You must be signed in to change notification settings - Fork 38.8k
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
Support persistent volume usage for kubernetes running on Photon Controller platform #36133
Support persistent volume usage for kubernetes running on Photon Controller platform #36133
Conversation
@pdhamdhere @abrarshivani @AlainRoy @kerneltime |
eda6ed7
to
b212091
Compare
658392d
to
2688fed
Compare
Jenkins Kubemark GCE e2e failed for commit 2688fed3f4a8475596b437bdd5c40caa74110478. Full PR test history. The magic incantation to run this job again is |
Jenkins GCE e2e failed for commit 2688fed3f4a8475596b437bdd5c40caa74110478. Full PR test history. The magic incantation to run this job again is |
2688fed
to
3326b6b
Compare
cc @saad-ali we have reviewed the changes internally, let us know how we can help. Ref: vmware-archive#21 |
Jenkins GCI GCE e2e failed for commit 3326b6b7a8c5af592ca7c173d9391398ab9c90d0. Full PR test history. The magic incantation to run this job again is |
@@ -1159,6 +1175,14 @@ func ValidatePersistentVolume(pv *api.PersistentVolume) field.ErrorList { | |||
allErrs = append(allErrs, validateVsphereVolumeSource(pv.Spec.VsphereVolume, specPath.Child("vsphereVolume"))...) | |||
} | |||
} | |||
if pv.Spec.PhotonPersistentDisk != nil { |
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.
This code is duplicated, perhaps extract out as a single function?
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.
It's not 100% duplicated though... one is using fldPath and the other is using specPath. And I am trying to be consistent with the context code.
Maybe a separate commit just for code-cleanup to shorten all the duplicated code in this block would be a better solution?
func getVMIDbyNodename(project string, nodeName string) (string, error) { | ||
vmList, err := photonClient.Projects.GetVMs(project, nil) | ||
if err != nil { | ||
return "", fmt.Errorf("Failed to GetVMs from project %s with nodeName %s, error: [%v]", project, nodeName, err) |
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.
I'd prefer not wrapping errors, just return it. If you feel the need, log it as well.
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.
This and all the following wrapping errors are addressed.
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.
Overall structure seems ok, though there are a bunch of cleanups/refactors.
Plus it needs a rebase.
|
||
for _, vm := range vmList.Items { | ||
if vm.Name == nodeName { | ||
if vm.State == "STARTED" { |
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.
This is a magic string. Extract as a const and add a comment to explain what it means. (is this string not in the API SDK somewhere?)
func getVMIDbyIP(project string, IPAddress string) (string, error) { | ||
vmList, err := photonClient.Projects.GetVMs(project, nil) | ||
if err != nil { | ||
return "", fmt.Errorf("Failed to GetVMs for project %s, error [%v]", project, err) |
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.
as above wrt to wrapping errors.
func getProjIDbyName(tenantName, projName string) (string, error) { | ||
tenants, err := photonClient.Tenants.GetAll() | ||
if err != nil { | ||
return "", fmt.Errorf("GetAll tenants failed with error [%v]", err) |
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.
Here too.
if tenant.Name == tenantName { | ||
projects, err := photonClient.Tenants.GetProjects(tenant.ID, nil) | ||
if err != nil { | ||
return "", fmt.Errorf("Failed to GetProjects for tenant %s, error [%v]", tenantName, err) |
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.
And here, I'm going to stop commenting, but please just return err
everywhere.
} | ||
|
||
//TODO: add handling of certification enabled situation | ||
options := &photon.ClientOptions{ |
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.
Does this mean it is insecure? Please comment on what this means (and make sure it's in the docs too)
func logError(msg string, err error) error { | ||
s := "Photon Cloud Provider: " + msg + ". Error [" + err.Error() + "]" | ||
glog.Errorf(s) | ||
return fmt.Errorf(s) |
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.
please don't wrap the error, just return the error.
var _ volume.AttachableVolumePlugin = &photonPersistentDiskPlugin{} | ||
|
||
// Singleton key mutex for keeping attach operations for the same host atomic | ||
var attachdetachMutex = keymutex.NewKeyMutex() |
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.
Rather than use a global variable, why not just always return a singleton from NewAttacher
and have that singleton own the lock?
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.
Have double-checked with Photon Controller team and the attach/detach mutex is taken care inside Photon Controller, so we are safe to remove them here.
} | ||
|
||
func (detacher *photonPersistentDiskDetacher) WaitForDetach(devicePath string, timeout time.Duration) error { | ||
ticker := time.NewTicker(checkSleepDuration) |
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.
You should really just use util.Poll
here.
https://github.com/kubernetes/kubernetes/blob/master/pkg/util/wait/wait.go#L161
// scan scsi path to discover the new disk | ||
scsiHostScan() | ||
|
||
ticker := time.NewTicker(checkSleepDuration) |
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.
you should use util.Poll
here
https://github.com/kubernetes/kubernetes/blob/master/pkg/util/wait/wait.go#L161
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.
Thank you! this looks a better solution. This code again is trying to keep consistent with other volume plugins. I will work on to simplify this part of code in a separate PR for all the volume plugin.
) | ||
|
||
var ErrProbeVolume = errors.New("Error scanning attached volumes") | ||
var volNameToDeviceName = make(map[string]string) |
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.
Why is this a global? That seems like a bad idea.
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.
This is because the detacher doesn't have information about the disk ID. It only has information of volName. So we have to keep a global mapping in order to find out which device to be removed from scsi path. This will be gone when Photon start to use pvscsi controller instead of scsi controller.
3326b6b
to
861e974
Compare
@brendandburns |
861e974
to
e61ea39
Compare
LGTM. The risk is low, this is largely factored outside of the main code-paths. |
be20162
to
a3625f5
Compare
Jenkins verification failed for commit be20162540b61ee87ef32bdbad67f08f2443373d. Full PR test history. The magic incantation to run this job again is |
a3625f5
to
e3082e8
Compare
Jenkins unit/integration failed for commit e3082e8adc45937eed8fee9f7e65e88ca321f690. Full PR test history. The magic incantation to run this job again is |
e3082e8
to
5ac6fdd
Compare
Release-czar approved post-code freeze merge--This was LGTMed and in the merge-queue at code freeze time for 1.5. Adding 1.5 milestone to let it gets merged after code freeze. |
1. Enable Photon Controller as cloud provider 2. Support Photon persistent disk as volume source/persistent volume source
5ac6fdd
to
20b9fc6
Compare
Jenkins GCI GKE smoke e2e failed for commit 20b9fc6. Full PR test history. The magic incantation to run this job again is |
@k8s-bot gci gke e2e test this |
@k8s-bot test this [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue |
@@ -405,6 +407,8 @@ type PersistentVolumeSource struct { | |||
// AzureDisk represents an Azure Data Disk mount on the host and bind mount to the pod. | |||
// +optional | |||
AzureDisk *AzureDiskVolumeSource `json:"azureDisk,omitempty" protobuf:"bytes,16,opt,name=azureDisk"` | |||
// PhotonPersistentDisk represents a PhotonController persistent disk attached and mounted on kubelets host machine | |||
PhotonPersistentDisk *PhotonPersistentDiskVolumeSource `json:"photonPersistentDisk,omitempty" protobuf:"bytes,17,opt,name=photonPersistentDisk"` |
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.
@mbohlool Should we have // +optional
here?
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.
Same question for pkg/api/types.go
What this PR does / why we need it:
Enable the persistent volume usage for kubernetes running on Photon platform.
Photon Controller: https://vmware.github.io/photon-controller/
Only the first commit include the real code change.
The following commits are for third-party vendor dependency and auto-generated code/docs updating.
Two components are added:
pkg/cloudprovider/providers/photon: support Photon Controller as cloud provider
pkg/volume/photon_pd: support Photon persistent disk as volume source for persistent volume
Usage introduction:
a. Photon Controller is supported as cloud provider.
When choosing to use photon controller as a cloud provider, "--cloud-provider=photon --cloud-config=[path_to_config_file]" is required for kubelet/kube-controller-manager/kube-apiserver. The config file of Photon Controller should follow the following usage:
b. Photon persistent disk is supported as volume source/persistent volume source.
yaml usage:
pdID is the persistent disk ID from Photon Controller.
c. Enable Photon Controller as volume provisioner.
yaml usage:
The flavor "persistent-disk-gold" needs to be created by Photon platform admin before hand.
This change is![Reviewable](https://camo.githubusercontent.com/2d899f4291d07d3cd2fa4aaae1e3b243f164c23fce87d30a589ace0d496a444c/68747470733a2f2f72657669657761626c652e6b756265726e657465732e696f2f7265766965775f627574746f6e2e737667)