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

Support persistent volume usage for kubernetes running on Photon Controller platform #36133

Merged
merged 5 commits into from
Nov 9, 2016

Conversation

luomiao
Copy link

@luomiao luomiao commented Nov 3, 2016

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:

[Global]
target = http://[photon_controller_endpoint_IP]
ignoreCertificate = true
tenant = [tenant_name]
project = [project_name]
overrideIP = true

b. Photon persistent disk is supported as volume source/persistent volume source.
yaml usage:

volumes:
  - name: photon-storage-1
    photonPersistentDisk:
        pdID: "643ed4e2-3fcc-482b-96d0-12ff6cab2a69"

pdID is the persistent disk ID from Photon Controller.

c. Enable Photon Controller as volume provisioner.
yaml usage:

kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
  name: gold_sc
provisioner: kubernetes.io/photon-pd
parameters:
  flavor: persistent-disk-gold

The flavor "persistent-disk-gold" needs to be created by Photon platform admin before hand.


This change is Reviewable

@k8s-github-robot k8s-github-robot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/old-docs size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 3, 2016
@luomiao
Copy link
Author

luomiao commented Nov 3, 2016

@pdhamdhere @abrarshivani @AlainRoy @kerneltime
This change has been reviewed by the above contributors within vmware/kubernetes fork.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 3, 2016
@k8s-github-robot k8s-github-robot removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. kind/old-docs labels Nov 3, 2016
@k8s-ci-robot
Copy link
Contributor

Jenkins Kubemark GCE e2e failed for commit 2688fed3f4a8475596b437bdd5c40caa74110478. Full PR test history.

The magic incantation to run this job again is @k8s-bot kubemark e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@k8s-ci-robot
Copy link
Contributor

Jenkins GCE e2e failed for commit 2688fed3f4a8475596b437bdd5c40caa74110478. Full PR test history.

The magic incantation to run this job again is @k8s-bot cvm gce e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@kerneltime
Copy link

cc @saad-ali we have reviewed the changes internally, let us know how we can help. Ref: vmware-archive#21

@k8s-ci-robot
Copy link
Contributor

Jenkins GCI GCE e2e failed for commit 3326b6b7a8c5af592ca7c173d9391398ab9c90d0. Full PR test history.

The magic incantation to run this job again is @k8s-bot gci gce e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 3, 2016
@@ -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 {
Copy link
Contributor

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?

Copy link
Author

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)
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Contributor

@brendandburns brendandburns left a 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" {
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 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)
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 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)
Copy link
Contributor

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)
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, I'm going to stop commenting, but please just return err everywhere.

}

//TODO: add handling of certification enabled situation
options := &photon.ClientOptions{
Copy link
Contributor

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)
Copy link
Contributor

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()
Copy link
Contributor

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?

Copy link
Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

// scan scsi path to discover the new disk
scsiHostScan()

ticker := time.NewTicker(checkSleepDuration)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Author

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)
Copy link
Contributor

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.

Copy link
Author

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.

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 4, 2016
@luomiao
Copy link
Author

luomiao commented Nov 4, 2016

@brendandburns
Hi Brendan,
I have incorporated most of your comments and please see otherwise reply inline.
Please let me know if you have further suggestions. Thank you!

@brendandburns brendandburns added release-note Denotes a PR that will be considered when it comes time to generate release notes. lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed release-note-label-needed labels Nov 4, 2016
@brendandburns
Copy link
Contributor

LGTM. The risk is low, this is largely factored outside of the main code-paths.

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 6, 2016
@k8s-ci-robot
Copy link
Contributor

Jenkins verification failed for commit be20162540b61ee87ef32bdbad67f08f2443373d. Full PR test history.

The magic incantation to run this job again is @k8s-bot verify test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@brendandburns brendandburns added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 6, 2016
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 7, 2016
@k8s-github-robot k8s-github-robot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Nov 7, 2016
@k8s-ci-robot
Copy link
Contributor

Jenkins unit/integration failed for commit e3082e8adc45937eed8fee9f7e65e88ca321f690. Full PR test history.

The magic incantation to run this job again is @k8s-bot unit test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@luomiao luomiao added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 7, 2016
@saad-ali
Copy link
Member

saad-ali commented Nov 8, 2016

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.

@saad-ali saad-ali added this to the v1.5 milestone Nov 8, 2016
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 8, 2016
@k8s-github-robot k8s-github-robot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Nov 8, 2016
@k8s-ci-robot
Copy link
Contributor

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. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@luomiao
Copy link
Author

luomiao commented Nov 8, 2016

@k8s-bot gci gke e2e test this

@saad-ali saad-ali added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 8, 2016
@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

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"`
Copy link
Member

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?

Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API 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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants