Skip to content

Commit

Permalink
Merge pull request kubernetes#627 from mqliang/aliyun-disk
Browse files Browse the repository at this point in the history
Aliyun disk
  • Loading branch information
keontang committed Feb 7, 2017
2 parents e628af5 + a429fa2 commit 022b8e5
Show file tree
Hide file tree
Showing 17 changed files with 1,737 additions and 190 deletions.
13 changes: 13 additions & 0 deletions cmd/kube-controller-manager/app/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ import (
"k8s.io/kubernetes/pkg/volume/quobyte"
"k8s.io/kubernetes/pkg/volume/rbd"
"k8s.io/kubernetes/pkg/volume/vsphere_volume"
<<<<<<< HEAD
=======

"github.com/golang/glog"
"k8s.io/kubernetes/pkg/cloudprovider/providers/aliyun"
"k8s.io/kubernetes/pkg/volume/aliyun_pd"
>>>>>>> 9258ebd... add aliyun disk driver
)

// ProbeAttachableVolumePlugins collects all volume plugins for the attach/
Expand All @@ -67,6 +74,8 @@ func ProbeAttachableVolumePlugins(config componentconfig.VolumeConfiguration) []

allPlugins = append(allPlugins, aws_ebs.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, gce_pd.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, anchnet_pd.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, aliyun_pd.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, cinder.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, flexvolume.ProbeVolumePlugins(config.FlexVolumePluginDir)...)
allPlugins = append(allPlugins, vsphere_volume.ProbeVolumePlugins()...)
Expand Down Expand Up @@ -133,6 +142,8 @@ func ProbeControllerVolumePlugins(cloud cloudprovider.Interface, config componen
allPlugins = append(allPlugins, photon_pd.ProbeVolumePlugins()...)
case anchnet_pd.ProviderName == cloud.ProviderName():
allPlugins = append(allPlugins, anchnet_pd.ProbeVolumePlugins()...)
case aliyun_pd.ProviderName == cloud.ProviderName():
allPlugins = append(allPlugins, aliyun_pd.ProbeVolumePlugins()...)
}
}

Expand Down Expand Up @@ -167,6 +178,8 @@ func NewAlphaVolumeProvisioner(cloud cloudprovider.Interface, config componentco
return getProvisionablePluginFromVolumePlugins(photon_pd.ProbeVolumePlugins())
case cloud != nil && anchnet_cloud.ProviderName == cloud.ProviderName():
return getProvisionablePluginFromVolumePlugins(anchnet_pd.ProbeVolumePlugins())
case cloud != nil && aliyun.ProviderName == cloud.ProviderName():
return getProvisionablePluginFromVolumePlugins(aliyun_pd.ProbeVolumePlugins())
}
return nil, nil
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/kubelet/app/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"k8s.io/kubernetes/pkg/kubelet/network/kubenet"
// Volume plugins
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/aliyun_pd"
"k8s.io/kubernetes/pkg/volume/anchnet_pd"
"k8s.io/kubernetes/pkg/volume/aws_ebs"
"k8s.io/kubernetes/pkg/volume/azure_dd"
Expand Down Expand Up @@ -69,6 +70,7 @@ func ProbeVolumePlugins(pluginDir string) []volume.VolumePlugin {
// Kubelet does not currently need to configure volume plugins.
// If/when it does, see kube-controller-manager/app/plugins.go for example of using volume.VolumeConfig
allPlugins = append(allPlugins, anchnet_pd.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, aliyun_pd.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, aws_ebs.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, empty_dir.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, gce_pd.ProbeVolumePlugins()...)
Expand Down
27 changes: 27 additions & 0 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ type VolumeSource struct {
// AnchnetPersistentDisk represents an Anchnet Disk resource that is attached to a
// kubelet's host machine and then exposed to the pod.
AnchnetPersistentDisk *AnchnetPersistentDiskVolumeSource `json:"anchnetPersistentDisk,omitempty"`
// AliyunPersistentDisk represents an Aliyun Disk resource that is attached to a
// kubelet's host machine and then exposed to the pod.
AliyunPersistentDisk *AliyunPersistentDiskVolumeSource `json:"aliyunPersistentDisk,omitempty"`
// HostPath represents file or directory on the host machine that is
// directly exposed to the container. This is generally used for system
// agents or other privileged things that are allowed to see the host
Expand Down Expand Up @@ -359,6 +362,9 @@ type PersistentVolumeSource struct {
// AnchnetPersistentDisk represents an Anchnet Disk resource that is attached to a
// kubelet's host machine and then exposed to the pod.
AnchnetPersistentDisk *AnchnetPersistentDiskVolumeSource `json:"anchnetPersistentDisk,omitempty"`
// AliyunPersistentDisk represents an Aliyun Disk resource that is attached to a
// kubelet's host machine and then exposed to the pod.
AliyunPersistentDisk *AliyunPersistentDiskVolumeSource `json:"aliyunPersistentDisk,omitempty"`
}

type PersistentVolumeClaimVolumeSource struct {
Expand Down Expand Up @@ -596,6 +602,27 @@ type AnchnetPersistentDiskVolumeSource struct {
ReadOnly bool `json:"readOnly,omitempty"`
}

// AliyunPersistentDiskVolumeSource represents a Persistent Disk resource in Aliyun.
//
// An aliyun PD must exist and be formatted before mounting to a container.
// An aliyun PD can only be mounted as read/write once.
type AliyunPersistentDiskVolumeSource struct {
// Unique name of the PD resource. Used to identify the disk in aliyun
VolumeID string `json:"volumeID" protobuf:"bytes,1,opt,name=volumeID"`
// Required: Filesystem type to mount.
// Must be a filesystem type supported by the host operating system.
// Ex. "ext4", "xfs", "ntfs"
// TODO: how do we prevent errors in the filesystem from compromising the machine
FSType string `json:"fsType,omitempty" protobuf:"bytes,2,opt,name=fsType"`
// Optional: Partition on the disk to mount.
// If omitted, kubelet will attempt to mount the device name.
// Ex. For /dev/sda1, this field is "1", for /dev/sda, this field is 0 or empty.
Partition int32 `json:"partition,omitempty" protobuf:"varint,3,opt,name=partition"`
// Optional: Defaults to false (read/write). ReadOnly here will force
// the ReadOnly setting in VolumeMounts.
ReadOnly bool `json:"readOnly,omitempty" protobuf:"varint,4,opt,name=readOnly"`
}

// Represents a Persistent Disk resource in Google Compute Engine.
//
// A GCE PD must exist before mounting to a container. The disk must
Expand Down
27 changes: 27 additions & 0 deletions pkg/api/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ type VolumeSource struct {
// AnchnetPersistentDisk represents an Anchnet Disk resource that is attached to a
// kubelet's host machine and then exposed to the pod.
AnchnetPersistentDisk *AnchnetPersistentDiskVolumeSource `json:"anchnetPersistentDisk,omitempty" protobuf:"bytes,24,opt,name=anchnetPersistentDisk"`
// AliyunPersistentDisk represents an Aliyun Disk resource that is attached to a
// kubelet's host machine and then exposed to the pod.
AliyunPersistentDisk *AliyunPersistentDiskVolumeSource `json:"aliyunPersistentDisk,omitempty" protobuf:"bytes,25,opt,name=aliyunPersistentDisk"`
}

// PersistentVolumeClaimVolumeSource references the user's PVC in the same namespace.
Expand Down Expand Up @@ -415,6 +418,9 @@ type PersistentVolumeSource struct {
// AnchnetPersistentDisk represents an Anchnet Disk resource that is attached to a
// kubelet's host machine and then exposed to the pod.
AnchnetPersistentDisk *AnchnetPersistentDiskVolumeSource `json:"anchnetPersistentDisk,omitempty" protobuf:"bytes,18,opt,name=anchnetPersistentDisk"`
// AliyunPersistentDisk represents an Aliyun Disk resource that is attached to a
// kubelet's host machine and then exposed to the pod.
AliyunPersistentDisk *AliyunPersistentDiskVolumeSource `json:"aliyunPersistentDisk,omitempty" protobuf:"bytes,19,opt,name=aliyunPersistentDisk"`
}

// +genclient=true
Expand Down Expand Up @@ -803,6 +809,27 @@ type AnchnetPersistentDiskVolumeSource struct {
ReadOnly bool `json:"readOnly,omitempty" protobuf:"varint,4,opt,name=readOnly"`
}

// AliyunPersistentDiskVolumeSource represents a Persistent Disk resource in Aliyun.
//
// An aliyun PD must exist and be formatted before mounting to a container.
// An aliyun PD can only be mounted as read/write once.
type AliyunPersistentDiskVolumeSource struct {
// Unique name of the PD resource. Used to identify the disk in aliyun
VolumeID string `json:"volumeID" protobuf:"bytes,1,opt,name=volumeID"`
// Required: Filesystem type to mount.
// Must be a filesystem type supported by the host operating system.
// Ex. "ext4", "xfs", "ntfs"
// TODO: how do we prevent errors in the filesystem from compromising the machine
FSType string `json:"fsType,omitempty" protobuf:"bytes,2,opt,name=fsType"`
// Optional: Partition on the disk to mount.
// If omitted, kubelet will attempt to mount the device name.
// Ex. For /dev/sda1, this field is "1", for /dev/sda, this field is 0 or empty.
Partition int32 `json:"partition,omitempty" protobuf:"varint,3,opt,name=partition"`
// Optional: Defaults to false (read/write). ReadOnly here will force
// the ReadOnly setting in VolumeMounts.
ReadOnly bool `json:"readOnly,omitempty" protobuf:"varint,4,opt,name=readOnly"`
}

// Represents a Persistent Disk resource in Google Compute Engine.
//
// A GCE PD must exist before mounting to a container. The disk must
Expand Down
27 changes: 27 additions & 0 deletions pkg/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,14 @@ func validateVolumeSource(source *api.VolumeSource, fldPath *field.Path) field.E
allErrs = append(allErrs, validateAnchnetPersistentDiskVolumeSource(source.AnchnetPersistentDisk, fldPath.Child("anchnetPersistentDisk"))...)
}
}
if source.AliyunPersistentDisk != nil {
if numVolumes > 0 {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("aliyunPersistentDisk"), "may not specify more than 1 volume type"))
} else {
numVolumes++
allErrs = append(allErrs, validateAliyunPersistentDiskVolumeSource(source.AliyunPersistentDisk, fldPath.Child("aliyunPersistentDisk"))...)
}
}
if source.HostPath != nil {
if numVolumes > 0 {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("hostPath"), "may not specify more than 1 volume type"))
Expand Down Expand Up @@ -704,6 +712,17 @@ func validateAnchnetPersistentDiskVolumeSource(disk *api.AnchnetPersistentDiskVo
return allErrs
}

func validateAliyunPersistentDiskVolumeSource(disk *api.AliyunPersistentDiskVolumeSource, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
if len(disk.VolumeID) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("volumeID"), ""))
}
if disk.Partition < 0 || disk.Partition > 255 {
allErrs = append(allErrs, field.Invalid(fldPath.Child("partition"), disk.Partition, pdPartitionErrorMsg))
}
return allErrs
}

func validateHostPathVolumeSource(hostPath *api.HostPathVolumeSource, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
if len(hostPath.Path) == 0 {
Expand Down Expand Up @@ -1090,6 +1109,14 @@ func ValidatePersistentVolume(pv *api.PersistentVolume) field.ErrorList {
allErrs = append(allErrs, validateAnchnetPersistentDiskVolumeSource(pv.Spec.AnchnetPersistentDisk, specPath.Child("anchnetPersistentDisk"))...)
}
}
if pv.Spec.AliyunPersistentDisk != nil {
if numVolumes > 0 {
allErrs = append(allErrs, field.Forbidden(specPath.Child("aliyunPersistentDisk"), "may not specify more than 1 volume type"))
} else {
numVolumes++
allErrs = append(allErrs, validateAliyunPersistentDiskVolumeSource(pv.Spec.AliyunPersistentDisk, specPath.Child("aliyunPersistentDisk"))...)
}
}
if pv.Spec.HostPath != nil {
if numVolumes > 0 {
allErrs = append(allErrs, field.Forbidden(specPath.Child("hostPath"), "may not specify more than 1 volume type"))
Expand Down
Loading

0 comments on commit 022b8e5

Please sign in to comment.