Add support for flex volume. Flex volume adds support for thirdparty(vendor)

volumes and custom mounts.
pull/6/head
Chakravarthy Nelluri 2015-09-30 11:31:53 -07:00
parent 56f72aeb45
commit fa76de79e5
47 changed files with 40874 additions and 37685 deletions

View File

@ -13884,6 +13884,10 @@
"$ref": "v1.FlockerVolumeSource", "$ref": "v1.FlockerVolumeSource",
"description": "Flocker represents a Flocker volume attached to a kubelet's host machine and exposed to the pod for its usage. This depends on the Flocker control service being running" "description": "Flocker represents a Flocker volume attached to a kubelet's host machine and exposed to the pod for its usage. This depends on the Flocker control service being running"
}, },
"flexVolume": {
"$ref": "v1.FlexVolumeSource",
"description": "FlexVolume represents a generic volume resource that is provisioned/attached using a exec based plugin. This is an alpha feature and may change in future."
},
"accessModes": { "accessModes": {
"type": "array", "type": "array",
"items": { "items": {
@ -14205,6 +14209,35 @@
} }
} }
}, },
"v1.FlexVolumeSource": {
"id": "v1.FlexVolumeSource",
"description": "FlexVolume represents a generic volume resource that is provisioned/attached using a exec based plugin. This is an alpha feature and may change in future.",
"required": [
"driver"
],
"properties": {
"driver": {
"type": "string",
"description": "Driver is the name of the driver to use for this volume."
},
"fsType": {
"type": "string",
"description": "Required: Filesystem type to mount. Must be a filesystem type supported by the host operating system. Ex. \"ext4\", \"xfs\", \"ntfs\""
},
"secretRef": {
"$ref": "v1.LocalObjectReference",
"description": "Optional: SecretRef is reference to the authentication secret for User, default is empty."
},
"readOnly": {
"type": "boolean",
"description": "Optional: Defaults to false (read/write). ReadOnly here will force the ReadOnly setting in VolumeMounts."
},
"options": {
"type": "any",
"description": "Optional: Extra command options if any."
}
}
},
"v1.PersistentVolumeStatus": { "v1.PersistentVolumeStatus": {
"id": "v1.PersistentVolumeStatus", "id": "v1.PersistentVolumeStatus",
"description": "PersistentVolumeStatus is the current status of a persistent volume.", "description": "PersistentVolumeStatus is the current status of a persistent volume.",
@ -14412,6 +14445,10 @@
"$ref": "v1.RBDVolumeSource", "$ref": "v1.RBDVolumeSource",
"description": "RBD represents a Rados Block Device mount on the host that shares a pod's lifetime. More info: http://releases.k8s.io/HEAD/examples/rbd/README.md" "description": "RBD represents a Rados Block Device mount on the host that shares a pod's lifetime. More info: http://releases.k8s.io/HEAD/examples/rbd/README.md"
}, },
"flexVolume": {
"$ref": "v1.FlexVolumeSource",
"description": "FlexVolume represents a generic volume resource that is provisioned/attached using a exec based plugin. This is an alpha feature and may change in future."
},
"cinder": { "cinder": {
"$ref": "v1.CinderVolumeSource", "$ref": "v1.CinderVolumeSource",
"description": "Cinder represents a cinder volume attached and mounted on kubelets host machine More info: http://releases.k8s.io/HEAD/examples/mysql-cinder-pd/README.md" "description": "Cinder represents a cinder volume attached and mounted on kubelets host machine More info: http://releases.k8s.io/HEAD/examples/mysql-cinder-pd/README.md"

View File

@ -3429,6 +3429,10 @@
"$ref": "v1.RBDVolumeSource", "$ref": "v1.RBDVolumeSource",
"description": "RBD represents a Rados Block Device mount on the host that shares a pod's lifetime. More info: http://releases.k8s.io/HEAD/examples/rbd/README.md" "description": "RBD represents a Rados Block Device mount on the host that shares a pod's lifetime. More info: http://releases.k8s.io/HEAD/examples/rbd/README.md"
}, },
"flexVolume": {
"$ref": "v1.FlexVolumeSource",
"description": "FlexVolume represents a generic volume resource that is provisioned/attached using a exec based plugin. This is an alpha feature and may change in future."
},
"cinder": { "cinder": {
"$ref": "v1.CinderVolumeSource", "$ref": "v1.CinderVolumeSource",
"description": "Cinder represents a cinder volume attached and mounted on kubelets host machine More info: http://releases.k8s.io/HEAD/examples/mysql-cinder-pd/README.md" "description": "Cinder represents a cinder volume attached and mounted on kubelets host machine More info: http://releases.k8s.io/HEAD/examples/mysql-cinder-pd/README.md"
@ -3719,6 +3723,35 @@
} }
} }
}, },
"v1.FlexVolumeSource": {
"id": "v1.FlexVolumeSource",
"description": "FlexVolume represents a generic volume resource that is provisioned/attached using a exec based plugin. This is an alpha feature and may change in future.",
"required": [
"driver"
],
"properties": {
"driver": {
"type": "string",
"description": "Driver is the name of the driver to use for this volume."
},
"fsType": {
"type": "string",
"description": "Required: Filesystem type to mount. Must be a filesystem type supported by the host operating system. Ex. \"ext4\", \"xfs\", \"ntfs\""
},
"secretRef": {
"$ref": "v1.LocalObjectReference",
"description": "Optional: SecretRef is reference to the authentication secret for User, default is empty."
},
"readOnly": {
"type": "boolean",
"description": "Optional: Defaults to false (read/write). ReadOnly here will force the ReadOnly setting in VolumeMounts."
},
"options": {
"type": "any",
"description": "Optional: Extra command options if any."
}
}
},
"v1.CinderVolumeSource": { "v1.CinderVolumeSource": {
"id": "v1.CinderVolumeSource", "id": "v1.CinderVolumeSource",
"description": "Represents a cinder volume resource in Openstack. A Cinder volume must exist before mounting to a container. The volume must also be in the same region as the kubelet. Cinder volumes support ownership management and SELinux relabeling.", "description": "Represents a cinder volume resource in Openstack. A Cinder volume must exist before mounting to a container. The volume must also be in the same region as the kubelet. Cinder volumes support ownership management and SELinux relabeling.",

View File

@ -32,6 +32,7 @@ import (
"k8s.io/kubernetes/pkg/volume/downwardapi" "k8s.io/kubernetes/pkg/volume/downwardapi"
"k8s.io/kubernetes/pkg/volume/empty_dir" "k8s.io/kubernetes/pkg/volume/empty_dir"
"k8s.io/kubernetes/pkg/volume/fc" "k8s.io/kubernetes/pkg/volume/fc"
"k8s.io/kubernetes/pkg/volume/flexvolume"
"k8s.io/kubernetes/pkg/volume/flocker" "k8s.io/kubernetes/pkg/volume/flocker"
"k8s.io/kubernetes/pkg/volume/gce_pd" "k8s.io/kubernetes/pkg/volume/gce_pd"
"k8s.io/kubernetes/pkg/volume/git_repo" "k8s.io/kubernetes/pkg/volume/git_repo"
@ -47,7 +48,9 @@ import (
) )
// ProbeVolumePlugins collects all volume plugins into an easy to use list. // ProbeVolumePlugins collects all volume plugins into an easy to use list.
func ProbeVolumePlugins() []volume.VolumePlugin { // PluginDir specifies the directory to search for additional third party
// volume plugins.
func ProbeVolumePlugins(pluginDir string) []volume.VolumePlugin {
allPlugins := []volume.VolumePlugin{} allPlugins := []volume.VolumePlugin{}
// The list of plugins to probe is decided by the kubelet binary, not // The list of plugins to probe is decided by the kubelet binary, not
@ -72,6 +75,8 @@ func ProbeVolumePlugins() []volume.VolumePlugin {
allPlugins = append(allPlugins, downwardapi.ProbeVolumePlugins()...) allPlugins = append(allPlugins, downwardapi.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, fc.ProbeVolumePlugins()...) allPlugins = append(allPlugins, fc.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, flocker.ProbeVolumePlugins()...) allPlugins = append(allPlugins, flocker.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, flexvolume.ProbeVolumePlugins(pluginDir)...)
return allPlugins return allPlugins
} }

View File

@ -116,6 +116,7 @@ type KubeletServer struct {
MaxPods int MaxPods int
MinimumGCAge time.Duration MinimumGCAge time.Duration
NetworkPluginDir string NetworkPluginDir string
VolumePluginDir string
NetworkPluginName string NetworkPluginName string
NodeLabels []string NodeLabels []string
NodeLabelsFile string NodeLabelsFile string
@ -207,6 +208,7 @@ func NewKubeletServer() *KubeletServer {
MaxPods: 40, MaxPods: 40,
MinimumGCAge: 1 * time.Minute, MinimumGCAge: 1 * time.Minute,
NetworkPluginDir: "/usr/libexec/kubernetes/kubelet-plugins/net/exec/", NetworkPluginDir: "/usr/libexec/kubernetes/kubelet-plugins/net/exec/",
VolumePluginDir: "/usr/libexec/kubernetes/kubelet-plugins/volume/exec/",
NetworkPluginName: "", NetworkPluginName: "",
NodeLabels: []string{}, NodeLabels: []string{},
NodeLabelsFile: "", NodeLabelsFile: "",
@ -321,6 +323,7 @@ func (s *KubeletServer) AddFlags(fs *pflag.FlagSet) {
fs.IntVar(&s.LowDiskSpaceThresholdMB, "low-diskspace-threshold-mb", s.LowDiskSpaceThresholdMB, "The absolute free disk space, in MB, to maintain. When disk space falls below this threshold, new pods would be rejected. Default: 256") fs.IntVar(&s.LowDiskSpaceThresholdMB, "low-diskspace-threshold-mb", s.LowDiskSpaceThresholdMB, "The absolute free disk space, in MB, to maintain. When disk space falls below this threshold, new pods would be rejected. Default: 256")
fs.StringVar(&s.NetworkPluginName, "network-plugin", s.NetworkPluginName, "<Warning: Alpha feature> The name of the network plugin to be invoked for various events in kubelet/pod lifecycle") fs.StringVar(&s.NetworkPluginName, "network-plugin", s.NetworkPluginName, "<Warning: Alpha feature> The name of the network plugin to be invoked for various events in kubelet/pod lifecycle")
fs.StringVar(&s.NetworkPluginDir, "network-plugin-dir", s.NetworkPluginDir, "<Warning: Alpha feature> The full path of the directory in which to search for network plugins") fs.StringVar(&s.NetworkPluginDir, "network-plugin-dir", s.NetworkPluginDir, "<Warning: Alpha feature> The full path of the directory in which to search for network plugins")
fs.StringVar(&s.VolumePluginDir, "volume-plugin-dir", s.VolumePluginDir, "<Warning: Alpha feature> The full path of the directory in which to search for additional third party volume plugins")
fs.StringVar(&s.CloudProvider, "cloud-provider", s.CloudProvider, "The provider for cloud services. Empty string for no provider.") fs.StringVar(&s.CloudProvider, "cloud-provider", s.CloudProvider, "The provider for cloud services. Empty string for no provider.")
fs.StringVar(&s.CloudConfigFile, "cloud-config", s.CloudConfigFile, "The path to the cloud provider configuration file. Empty string for no configuration file.") fs.StringVar(&s.CloudConfigFile, "cloud-config", s.CloudConfigFile, "The path to the cloud provider configuration file. Empty string for no configuration file.")
fs.StringVar(&s.ResourceContainer, "resource-container", s.ResourceContainer, "Absolute name of the resource-only container to create and run the Kubelet in (Default: /kubelet).") fs.StringVar(&s.ResourceContainer, "resource-container", s.ResourceContainer, "Absolute name of the resource-only container to create and run the Kubelet in (Default: /kubelet).")
@ -482,7 +485,7 @@ func (s *KubeletServer) UnsecuredKubeletConfig() (*KubeletConfig, error) {
SystemContainer: s.SystemContainer, SystemContainer: s.SystemContainer,
TLSOptions: tlsOptions, TLSOptions: tlsOptions,
Writer: writer, Writer: writer,
VolumePlugins: ProbeVolumePlugins(), VolumePlugins: ProbeVolumePlugins(s.VolumePluginDir),
ExperimentalFlannelOverlay: s.ExperimentalFlannelOverlay, ExperimentalFlannelOverlay: s.ExperimentalFlannelOverlay,
}, nil }, nil

View File

@ -139,9 +139,10 @@ kubelet
--system-container="": Optional resource-only container in which to place all non-kernel processes that are not already in a container. Empty for no container. Rolling back the flag requires a reboot. (Default: ""). --system-container="": Optional resource-only container in which to place all non-kernel processes that are not already in a container. Empty for no container. Rolling back the flag requires a reboot. (Default: "").
--tls-cert-file="": File containing x509 Certificate for HTTPS. (CA cert, if any, concatenated after server cert). If --tls-cert-file and --tls-private-key-file are not provided, a self-signed certificate and key are generated for the public address and saved to the directory passed to --cert-dir. --tls-cert-file="": File containing x509 Certificate for HTTPS. (CA cert, if any, concatenated after server cert). If --tls-cert-file and --tls-private-key-file are not provided, a self-signed certificate and key are generated for the public address and saved to the directory passed to --cert-dir.
--tls-private-key-file="": File containing x509 private key matching --tls-cert-file. --tls-private-key-file="": File containing x509 private key matching --tls-cert-file.
--volume-plugin-dir="/usr/libexec/kubernetes/kubelet-plugins/volume/exec/": <Warning: Alpha feature> The full path of the directory in which to search for additional third party volume plugins
``` ```
###### Auto generated by spf13/cobra on 8-Dec-2015 ###### Auto generated by spf13/cobra on 11-Dec-2015
<!-- BEGIN MUNGE: GENERATED_ANALYTICS --> <!-- BEGIN MUNGE: GENERATED_ANALYTICS -->

View File

@ -2969,6 +2969,68 @@ Populated by the system when a graceful deletion is requested. Read-only. More i
</tbody> </tbody>
</table> </table>
</div>
<div class="sect2">
<h3 id="_v1_flexvolumesource">v1.FlexVolumeSource</h3>
<div class="paragraph">
<p>FlexVolume represents a generic volume resource that is provisioned/attached using a exec based plugin. This is an alpha feature and may change in future.</p>
</div>
<table class="tableblock frame-all grid-all" style="width:100%; ">
<colgroup>
<col style="width:20%;">
<col style="width:20%;">
<col style="width:20%;">
<col style="width:20%;">
<col style="width:20%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Name</th>
<th class="tableblock halign-left valign-top">Description</th>
<th class="tableblock halign-left valign-top">Required</th>
<th class="tableblock halign-left valign-top">Schema</th>
<th class="tableblock halign-left valign-top">Default</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">driver</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Driver is the name of the driver to use for this volume.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">true</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">fsType</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Required: Filesystem type to mount. Must be a filesystem type supported by the host operating system. Ex. "ext4", "xfs", "ntfs"</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">secretRef</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Optional: SecretRef is reference to the authentication secret for User, default is empty.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="#_v1_localobjectreference">v1.LocalObjectReference</a></p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">readOnly</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Optional: Defaults to false (read/write). ReadOnly here will force the ReadOnly setting in VolumeMounts.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">boolean</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">options</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Optional: Extra command options if any.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="#_any">any</a></p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
</tbody>
</table>
</div> </div>
<div class="sect2"> <div class="sect2">
<h3 id="_v1beta1_jobcondition">v1beta1.JobCondition</h3> <h3 id="_v1beta1_jobcondition">v1beta1.JobCondition</h3>
@ -3277,6 +3339,13 @@ Populated by the system when a graceful deletion is requested. Read-only. More i
<td class="tableblock halign-left valign-top"></td> <td class="tableblock halign-left valign-top"></td>
</tr> </tr>
<tr> <tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">flexVolume</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">FlexVolume represents a generic volume resource that is provisioned/attached using a exec based plugin. This is an alpha feature and may change in future.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="#_v1_flexvolumesource">v1.FlexVolumeSource</a></p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">cinder</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">cinder</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Cinder represents a cinder volume attached and mounted on kubelets host machine More info: <a href="http://releases.k8s.io/HEAD/examples/mysql-cinder-pd/README.md">http://releases.k8s.io/HEAD/examples/mysql-cinder-pd/README.md</a></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">Cinder represents a cinder volume attached and mounted on kubelets host machine More info: <a href="http://releases.k8s.io/HEAD/examples/mysql-cinder-pd/README.md">http://releases.k8s.io/HEAD/examples/mysql-cinder-pd/README.md</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
@ -4292,7 +4361,7 @@ Populated by the system when a graceful deletion is requested. Read-only. More i
</div> </div>
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Last updated 2015-12-17 23:51:47 UTC Last updated 2015-12-18 08:02:33 UTC
</div> </div>
</div> </div>
</body> </body>

View File

@ -2525,6 +2525,68 @@ The resulting set of endpoints can be viewed as:<br>
</tbody> </tbody>
</table> </table>
</div>
<div class="sect2">
<h3 id="_v1_flexvolumesource">v1.FlexVolumeSource</h3>
<div class="paragraph">
<p>FlexVolume represents a generic volume resource that is provisioned/attached using a exec based plugin. This is an alpha feature and may change in future.</p>
</div>
<table class="tableblock frame-all grid-all" style="width:100%; ">
<colgroup>
<col style="width:20%;">
<col style="width:20%;">
<col style="width:20%;">
<col style="width:20%;">
<col style="width:20%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Name</th>
<th class="tableblock halign-left valign-top">Description</th>
<th class="tableblock halign-left valign-top">Required</th>
<th class="tableblock halign-left valign-top">Schema</th>
<th class="tableblock halign-left valign-top">Default</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">driver</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Driver is the name of the driver to use for this volume.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">true</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">fsType</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Required: Filesystem type to mount. Must be a filesystem type supported by the host operating system. Ex. "ext4", "xfs", "ntfs"</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">secretRef</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Optional: SecretRef is reference to the authentication secret for User, default is empty.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="#_v1_localobjectreference">v1.LocalObjectReference</a></p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">readOnly</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Optional: Defaults to false (read/write). ReadOnly here will force the ReadOnly setting in VolumeMounts.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">boolean</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">options</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Optional: Extra command options if any.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="#_any">any</a></p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
</tbody>
</table>
</div> </div>
<div class="sect2"> <div class="sect2">
<h3 id="_v1_envvarsource">v1.EnvVarSource</h3> <h3 id="_v1_envvarsource">v1.EnvVarSource</h3>
@ -2995,6 +3057,13 @@ The resulting set of endpoints can be viewed as:<br>
<td class="tableblock halign-left valign-top"></td> <td class="tableblock halign-left valign-top"></td>
</tr> </tr>
<tr> <tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">flexVolume</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">FlexVolume represents a generic volume resource that is provisioned/attached using a exec based plugin. This is an alpha feature and may change in future.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="#_v1_flexvolumesource">v1.FlexVolumeSource</a></p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">cinder</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">cinder</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Cinder represents a cinder volume attached and mounted on kubelets host machine More info: <a href="http://releases.k8s.io/HEAD/examples/mysql-cinder-pd/README.md">http://releases.k8s.io/HEAD/examples/mysql-cinder-pd/README.md</a></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">Cinder represents a cinder volume attached and mounted on kubelets host machine More info: <a href="http://releases.k8s.io/HEAD/examples/mysql-cinder-pd/README.md">http://releases.k8s.io/HEAD/examples/mysql-cinder-pd/README.md</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
@ -4871,6 +4940,13 @@ The resulting set of endpoints can be viewed as:<br>
<td class="tableblock halign-left valign-top"></td> <td class="tableblock halign-left valign-top"></td>
</tr> </tr>
<tr> <tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">flexVolume</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">FlexVolume represents a generic volume resource that is provisioned/attached using a exec based plugin. This is an alpha feature and may change in future.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="#_v1_flexvolumesource">v1.FlexVolumeSource</a></p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">accessModes</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">accessModes</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">AccessModes contains all ways the volume can be mounted. More info: <a href="http://releases.k8s.io/HEAD/docs/user-guide/persistent-volumes.md#access-modes">http://releases.k8s.io/HEAD/docs/user-guide/persistent-volumes.md#access-modes</a></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">AccessModes contains all ways the volume can be mounted. More info: <a href="http://releases.k8s.io/HEAD/docs/user-guide/persistent-volumes.md#access-modes">http://releases.k8s.io/HEAD/docs/user-guide/persistent-volumes.md#access-modes</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
@ -5247,61 +5323,6 @@ The resulting set of endpoints can be viewed as:<br>
</tbody> </tbody>
</table> </table>
</div>
<div class="sect2">
<h3 id="_v1_binding">v1.Binding</h3>
<div class="paragraph">
<p>Binding ties one object to another. For example, a pod is bound to a node by a scheduler.</p>
</div>
<table class="tableblock frame-all grid-all" style="width:100%; ">
<colgroup>
<col style="width:20%;">
<col style="width:20%;">
<col style="width:20%;">
<col style="width:20%;">
<col style="width:20%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Name</th>
<th class="tableblock halign-left valign-top">Description</th>
<th class="tableblock halign-left valign-top">Required</th>
<th class="tableblock halign-left valign-top">Schema</th>
<th class="tableblock halign-left valign-top">Default</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">kind</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: <a href="http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds">http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">apiVersion</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: <a href="http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#resources">http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#resources</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">metadata</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Standard object&#8217;s metadata. More info: <a href="http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata">http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="#_v1_objectmeta">v1.ObjectMeta</a></p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">target</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The target object that you want to bind to the standard object.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">true</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="#_v1_objectreference">v1.ObjectReference</a></p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
</tbody>
</table>
</div> </div>
<div class="sect2"> <div class="sect2">
<h3 id="_v1_containerstateterminated">v1.ContainerStateTerminated</h3> <h3 id="_v1_containerstateterminated">v1.ContainerStateTerminated</h3>
@ -5378,6 +5399,61 @@ The resulting set of endpoints can be viewed as:<br>
</tbody> </tbody>
</table> </table>
</div>
<div class="sect2">
<h3 id="_v1_binding">v1.Binding</h3>
<div class="paragraph">
<p>Binding ties one object to another. For example, a pod is bound to a node by a scheduler.</p>
</div>
<table class="tableblock frame-all grid-all" style="width:100%; ">
<colgroup>
<col style="width:20%;">
<col style="width:20%;">
<col style="width:20%;">
<col style="width:20%;">
<col style="width:20%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Name</th>
<th class="tableblock halign-left valign-top">Description</th>
<th class="tableblock halign-left valign-top">Required</th>
<th class="tableblock halign-left valign-top">Schema</th>
<th class="tableblock halign-left valign-top">Default</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">kind</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: <a href="http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds">http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">apiVersion</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: <a href="http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#resources">http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#resources</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">metadata</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Standard object&#8217;s metadata. More info: <a href="http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata">http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="#_v1_objectmeta">v1.ObjectMeta</a></p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">target</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The target object that you want to bind to the standard object.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">true</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a href="#_v1_objectreference">v1.ObjectReference</a></p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
</tbody>
</table>
</div> </div>
<div class="sect2"> <div class="sect2">
<h3 id="_v1_cindervolumesource">v1.CinderVolumeSource</h3> <h3 id="_v1_cindervolumesource">v1.CinderVolumeSource</h3>
@ -6925,7 +7001,7 @@ The resulting set of endpoints can be viewed as:<br>
</div> </div>
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Last updated 2015-12-17 12:59:31 UTC Last updated 2015-12-18 08:02:17 UTC
</div> </div>
</div> </div>
</body> </body>

View File

@ -66,6 +66,7 @@ Familiarity with [pods](pods.md) is suggested.
- [secret](#secret) - [secret](#secret)
- [persistentVolumeClaim](#persistentvolumeclaim) - [persistentVolumeClaim](#persistentvolumeclaim)
- [downwardAPI](#downwardapi) - [downwardAPI](#downwardapi)
- [FlexVolume](#flexvolume)
- [Resources](#resources) - [Resources](#resources)
<!-- END MUNGE: GENERATED_TOC --> <!-- END MUNGE: GENERATED_TOC -->
@ -420,6 +421,14 @@ It mounts a directory and writes the requested data in plain text files.
See the [`downwardAPI` volume example](downward-api/volume/README.md) for more details. See the [`downwardAPI` volume example](downward-api/volume/README.md) for more details.
### FlexVolume
A `FlexVolume` enables users to mount vendor volumes into a pod. It expects vendor
drivers are installed in the volume plugin path on each kubelet node. This is
an alpha feature and may change in future.
More details are in [here](../../examples/flexvolume/README.md)
## Resources ## Resources
The storage media (Disk, SSD, etc) of an `emptyDir` volume is determined by the The storage media (Disk, SSD, etc) of an `emptyDir` volume is determined by the

View File

@ -0,0 +1,73 @@
<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
<!-- BEGIN STRIP_FOR_RELEASE -->
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
width="25" height="25">
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
width="25" height="25">
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
width="25" height="25">
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
width="25" height="25">
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
width="25" height="25">
<h2>PLEASE NOTE: This document applies to the HEAD of the source tree</h2>
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.
Documentation for other releases can be found at
[releases.k8s.io](http://releases.k8s.io).
</strong>
--
<!-- END STRIP_FOR_RELEASE -->
<!-- END MUNGE: UNVERSIONED_WARNING -->
# Flexvolume
Flexvolume enables users to mount vendor volumes into kubernetes. It expects vendor drivers are installed in the volume plugin path on every kubelet node.
It allows for vendors to develop their own drivers to mount volumes on nodes.
*Note: Flexvolume is an alpha feature and is most likely to change in future*
## Prerequisites
Install the vendor driver on all nodes in the kubelet plugin path. Path for installing the plugin: /usr/libexec/kubernetes/kubelet-plugins/volume/exec/\<vendor~driver\>/\<driver\>
For example to add a 'cifs' driver, by vendor 'foo' install the driver at: /usr/libexec/kubernetes/kubelet-plugins/volume/exec/\<foo~cifs\>/cifs
## Plugin details
Driver will be invoked with 'Init' to initalize the driver. It will be invoked with 'attach' to attach the volume and with 'detach' to detach the volume from the kubelet node. It also supports custom mounts using 'mount' and 'unmount' callouts to the driver.
### Driver invocation model:
Init:
\<driver executable\> init
Attach:
\<driver executable\> attach \<json options\>
Detach:
\<driver executable\> detach \<mount device\>
Mount:
\<driver executable\> mount \<target mount dir\> \<mount device\> \<json options\>
Unmount:
\<driver executable\> unmount \<mount dir\>
See lvm[lvm] for a quick example on how to write a simple flexvolume driver.
### Example of Flexvolume
See nginx.yaml[nginx.yaml] for a quick example on how to use Flexvolume in a pod.
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/examples/flexvolume/README.md?pixel)]()
<!-- END MUNGE: GENERATED_ANALYTICS -->

146
examples/flexvolume/lvm Executable file
View File

@ -0,0 +1,146 @@
#!/bin/bash
# Copyright 2015 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
usage() {
err "Invalid usage. Usage: "
err "\t$0 init"
err "\t$0 attach <json params>"
err "\t$0 detach <mount device>"
err "\t$0 mount <mount dir> <mount device> <json params>"
err "\t$0 unmount <mount dir>"
exit 1
}
err() {
echo -ne $* 1>&2
}
log() {
echo -ne $* >&1
}
ismounted() {
MOUNT=`findmnt -n ${MNTPATH} 2>/dev/null | cut -d' ' -f1`
if [ "${MOUNT}" == "${MNTPATH}" ]; then
echo "1"
else
echo "0"
fi
}
attach() {
VOLUMEID=$(echo $1 | jq -r '.volumeID')
SIZE=$(echo $1 | jq -r '.size')
VG=$(echo $1|jq -r '.volumegroup')
DMDEV="/dev/mapper/${VG}-${VOLUMEID}"
if [ ! -b "${DMDEV}" ]; then
err "{\"status\": \"Failure\", \"message\": \"Volume ${VOLUMEID} does not exist\"}"
exit 1
fi
log "{\"status\": \"Success\", \"device\":\"${DMDEV}\"}"
exit 0
}
detach() {
log "{\"status\": \"Success\"}"
exit 0
}
domount() {
MNTPATH=$1
DMDEV=$2
FSTYPE=$(echo $3|jq -r '.["kubernetes.io/fsType"]')
if [ ! -b "${DMDEV}" ]; then
err "{\"status\": \"Failure\", \"message\": \"${DMDEV} does not exist\"}"
exit 1
fi
if [ $(ismounted) -eq 1 ] ; then
log "{\"status\": \"Success\"}"
exit 0
fi
VOLFSTYPE=`blkid -o udev ${DMDEV} 2>/dev/null|grep "ID_FS_TYPE"|cut -d"=" -f2`
if [ "${VOLFSTYPE}" == "" ]; then
mkfs -t ${FSTYPE} ${DMDEV}
if [ $? -ne 0 ]; then
err "{ \"status\": \"Failure\", \"message\": \"Failed to create fs ${FSTYPE} on device ${DMDEV}\"}"
exit 1
fi
fi
mkdir -p ${MNTPATH} &> /dev/null
mount ${DMDEV} ${MNTPATH} &> /dev/null
if [ $? -ne 0 ]; then
err "{ \"status\": \"Failure\", \"message\": \"Failed to mount device ${DMDEV} at ${MNTPATH}\"}"
exit 1
fi
log "{\"status\": \"Success\"}"
exit 0
}
unmount() {
MNTPATH=$1
if [ $(ismounted) -eq 0 ] ; then
log "{\"status\": \"Success\"}"
exit 0
fi
umount ${MNTPATH} &> /dev/null
if [ $? -ne 0 ]; then
err "{ \"status\": \"Failed\", \"message\": \"Failed to unmount volume at ${MNTPATH}\"}"
exit 1
fi
rmdir ${MNTPATH} &> /dev/null
log "{\"status\": \"Success\"}"
exit 0
}
op=$1
if [ "$op" = "init" ]; then
log "{\"status\": \"Success\"}"
exit 0
fi
if [ $# -lt 2 ]; then
usage
fi
shift
case "$op" in
attach)
attach $*
;;
detach)
detach $*
;;
mount)
domount $*
;;
unmount)
unmount $*
;;
*)
usage
esac
exit 1

View File

@ -0,0 +1,23 @@
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx
volumeMounts:
- name: test
mountPath: /data
ports:
- containerPort: 80
volumes:
- name: test
flexVolume:
driver: "kubernetes.io/lvm"
fsType: "ext4"
options:
volumeID: "vol1"
size: "1000m"
volumegroup: "kube_vg"

View File

@ -337,6 +337,7 @@ upgrade-target
use-kubernetes-cluster-service use-kubernetes-cluster-service
user-whitelist user-whitelist
verify-only verify-only
volume-plugin-dir
watch-cache watch-cache
watch-only watch-only
whitelist-override-label whitelist-override-label

View File

@ -573,6 +573,29 @@ func deepCopy_api_FCVolumeSource(in FCVolumeSource, out *FCVolumeSource, c *conv
return nil return nil
} }
func deepCopy_api_FlexVolumeSource(in FlexVolumeSource, out *FlexVolumeSource, c *conversion.Cloner) error {
out.Driver = in.Driver
out.FSType = in.FSType
if in.SecretRef != nil {
out.SecretRef = new(LocalObjectReference)
if err := deepCopy_api_LocalObjectReference(*in.SecretRef, out.SecretRef, c); err != nil {
return err
}
} else {
out.SecretRef = nil
}
out.ReadOnly = in.ReadOnly
if in.Options != nil {
out.Options = make(map[string]string)
for key, val := range in.Options {
out.Options[key] = val
}
} else {
out.Options = nil
}
return nil
}
func deepCopy_api_FlockerVolumeSource(in FlockerVolumeSource, out *FlockerVolumeSource, c *conversion.Cloner) error { func deepCopy_api_FlockerVolumeSource(in FlockerVolumeSource, out *FlockerVolumeSource, c *conversion.Cloner) error {
out.DatasetName = in.DatasetName out.DatasetName = in.DatasetName
return nil return nil
@ -1298,6 +1321,14 @@ func deepCopy_api_PersistentVolumeSource(in PersistentVolumeSource, out *Persist
} else { } else {
out.ISCSI = nil out.ISCSI = nil
} }
if in.FlexVolume != nil {
out.FlexVolume = new(FlexVolumeSource)
if err := deepCopy_api_FlexVolumeSource(*in.FlexVolume, out.FlexVolume, c); err != nil {
return err
}
} else {
out.FlexVolume = nil
}
if in.Cinder != nil { if in.Cinder != nil {
out.Cinder = new(CinderVolumeSource) out.Cinder = new(CinderVolumeSource)
if err := deepCopy_api_CinderVolumeSource(*in.Cinder, out.Cinder, c); err != nil { if err := deepCopy_api_CinderVolumeSource(*in.Cinder, out.Cinder, c); err != nil {
@ -2284,6 +2315,14 @@ func deepCopy_api_VolumeSource(in VolumeSource, out *VolumeSource, c *conversion
} else { } else {
out.RBD = nil out.RBD = nil
} }
if in.FlexVolume != nil {
out.FlexVolume = new(FlexVolumeSource)
if err := deepCopy_api_FlexVolumeSource(*in.FlexVolume, out.FlexVolume, c); err != nil {
return err
}
} else {
out.FlexVolume = nil
}
if in.Cinder != nil { if in.Cinder != nil {
out.Cinder = new(CinderVolumeSource) out.Cinder = new(CinderVolumeSource)
if err := deepCopy_api_CinderVolumeSource(*in.Cinder, out.Cinder, c); err != nil { if err := deepCopy_api_CinderVolumeSource(*in.Cinder, out.Cinder, c); err != nil {
@ -2403,6 +2442,7 @@ func init() {
deepCopy_api_EventSource, deepCopy_api_EventSource,
deepCopy_api_ExecAction, deepCopy_api_ExecAction,
deepCopy_api_FCVolumeSource, deepCopy_api_FCVolumeSource,
deepCopy_api_FlexVolumeSource,
deepCopy_api_FlockerVolumeSource, deepCopy_api_FlockerVolumeSource,
deepCopy_api_GCEPersistentDiskVolumeSource, deepCopy_api_GCEPersistentDiskVolumeSource,
deepCopy_api_GitRepoVolumeSource, deepCopy_api_GitRepoVolumeSource,

File diff suppressed because it is too large Load Diff

View File

@ -198,6 +198,10 @@ type VolumeSource struct {
PersistentVolumeClaim *PersistentVolumeClaimVolumeSource `json:"persistentVolumeClaim,omitempty"` PersistentVolumeClaim *PersistentVolumeClaimVolumeSource `json:"persistentVolumeClaim,omitempty"`
// RBD represents a Rados Block Device mount on the host that shares a pod's lifetime // RBD represents a Rados Block Device mount on the host that shares a pod's lifetime
RBD *RBDVolumeSource `json:"rbd,omitempty"` RBD *RBDVolumeSource `json:"rbd,omitempty"`
// FlexVolume represents a generic volume resource that is
// provisioned/attached using a exec based plugin. This is an alpha feature and may change in future.
FlexVolume *FlexVolumeSource `json:"flexVolume,omitempty"`
// Cinder represents a cinder volume attached and mounted on kubelets host machine // Cinder represents a cinder volume attached and mounted on kubelets host machine
Cinder *CinderVolumeSource `json:"cinder,omitempty"` Cinder *CinderVolumeSource `json:"cinder,omitempty"`
@ -236,6 +240,9 @@ type PersistentVolumeSource struct {
// ISCSIVolumeSource represents an ISCSI resource that is attached to a // ISCSIVolumeSource represents an ISCSI resource that is attached to a
// kubelet's host machine and then exposed to the pod. // kubelet's host machine and then exposed to the pod.
ISCSI *ISCSIVolumeSource `json:"iscsi,omitempty"` ISCSI *ISCSIVolumeSource `json:"iscsi,omitempty"`
// FlexVolume represents a generic volume resource that is
// provisioned/attached using a exec based plugin. This is an alpha feature and may change in future.
FlexVolume *FlexVolumeSource `json:"flexVolume,omitempty"`
// Cinder represents a cinder volume attached and mounted on kubelets host machine // Cinder represents a cinder volume attached and mounted on kubelets host machine
Cinder *CinderVolumeSource `json:"cinder,omitempty"` Cinder *CinderVolumeSource `json:"cinder,omitempty"`
// CephFS represents a Ceph FS mount on the host that shares a pod's lifetime // CephFS represents a Ceph FS mount on the host that shares a pod's lifetime
@ -490,6 +497,24 @@ type FCVolumeSource struct {
ReadOnly bool `json:"readOnly,omitempty"` ReadOnly bool `json:"readOnly,omitempty"`
} }
// FlexVolume represents a generic volume resource that is
// provisioned/attached using a exec based plugin. This is an alpha feature and may change in future.
type FlexVolumeSource struct {
// Driver is the name of the driver to use for this volume.
Driver string `json:"driver"`
// Required: Filesystem type to mount.
// Must be a filesystem type supported by the host operating system.
// Ex. "ext4", "xfs", "ntfs"
FSType string `json:"fsType,omitempty"`
// Optional: SecretRef is reference to the authentication secret for User, default is empty.
SecretRef *LocalObjectReference `json:"secretRef,omitempty"`
// Optional: Defaults to false (read/write). ReadOnly here will force
// the ReadOnly setting in VolumeMounts.
ReadOnly bool `json:"readOnly,omitempty"`
// Optional: Extra driver options if any.
Options map[string]string `json:"options,omitempty"`
}
// Represents a Persistent Disk resource in AWS. // Represents a Persistent Disk resource in AWS.
// //
// An AWS EBS disk must exist and be formatted before mounting to a container. // An AWS EBS disk must exist and be formatted before mounting to a container.

View File

@ -793,6 +793,36 @@ func convert_api_FCVolumeSource_To_v1_FCVolumeSource(in *api.FCVolumeSource, out
return autoconvert_api_FCVolumeSource_To_v1_FCVolumeSource(in, out, s) return autoconvert_api_FCVolumeSource_To_v1_FCVolumeSource(in, out, s)
} }
func autoconvert_api_FlexVolumeSource_To_v1_FlexVolumeSource(in *api.FlexVolumeSource, out *FlexVolumeSource, s conversion.Scope) error {
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
defaulting.(func(*api.FlexVolumeSource))(in)
}
out.Driver = in.Driver
out.FSType = in.FSType
if in.SecretRef != nil {
out.SecretRef = new(LocalObjectReference)
if err := convert_api_LocalObjectReference_To_v1_LocalObjectReference(in.SecretRef, out.SecretRef, s); err != nil {
return err
}
} else {
out.SecretRef = nil
}
out.ReadOnly = in.ReadOnly
if in.Options != nil {
out.Options = make(map[string]string)
for key, val := range in.Options {
out.Options[key] = val
}
} else {
out.Options = nil
}
return nil
}
func convert_api_FlexVolumeSource_To_v1_FlexVolumeSource(in *api.FlexVolumeSource, out *FlexVolumeSource, s conversion.Scope) error {
return autoconvert_api_FlexVolumeSource_To_v1_FlexVolumeSource(in, out, s)
}
func autoconvert_api_FlockerVolumeSource_To_v1_FlockerVolumeSource(in *api.FlockerVolumeSource, out *FlockerVolumeSource, s conversion.Scope) error { func autoconvert_api_FlockerVolumeSource_To_v1_FlockerVolumeSource(in *api.FlockerVolumeSource, out *FlockerVolumeSource, s conversion.Scope) error {
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found { if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
defaulting.(func(*api.FlockerVolumeSource))(in) defaulting.(func(*api.FlockerVolumeSource))(in)
@ -1788,6 +1818,14 @@ func autoconvert_api_PersistentVolumeSource_To_v1_PersistentVolumeSource(in *api
} else { } else {
out.ISCSI = nil out.ISCSI = nil
} }
if in.FlexVolume != nil {
out.FlexVolume = new(FlexVolumeSource)
if err := convert_api_FlexVolumeSource_To_v1_FlexVolumeSource(in.FlexVolume, out.FlexVolume, s); err != nil {
return err
}
} else {
out.FlexVolume = nil
}
if in.Cinder != nil { if in.Cinder != nil {
out.Cinder = new(CinderVolumeSource) out.Cinder = new(CinderVolumeSource)
if err := convert_api_CinderVolumeSource_To_v1_CinderVolumeSource(in.Cinder, out.Cinder, s); err != nil { if err := convert_api_CinderVolumeSource_To_v1_CinderVolumeSource(in.Cinder, out.Cinder, s); err != nil {
@ -3019,6 +3057,14 @@ func autoconvert_api_VolumeSource_To_v1_VolumeSource(in *api.VolumeSource, out *
} else { } else {
out.RBD = nil out.RBD = nil
} }
if in.FlexVolume != nil {
out.FlexVolume = new(FlexVolumeSource)
if err := convert_api_FlexVolumeSource_To_v1_FlexVolumeSource(in.FlexVolume, out.FlexVolume, s); err != nil {
return err
}
} else {
out.FlexVolume = nil
}
if in.Cinder != nil { if in.Cinder != nil {
out.Cinder = new(CinderVolumeSource) out.Cinder = new(CinderVolumeSource)
if err := convert_api_CinderVolumeSource_To_v1_CinderVolumeSource(in.Cinder, out.Cinder, s); err != nil { if err := convert_api_CinderVolumeSource_To_v1_CinderVolumeSource(in.Cinder, out.Cinder, s); err != nil {
@ -3864,6 +3910,36 @@ func convert_v1_FCVolumeSource_To_api_FCVolumeSource(in *FCVolumeSource, out *ap
return autoconvert_v1_FCVolumeSource_To_api_FCVolumeSource(in, out, s) return autoconvert_v1_FCVolumeSource_To_api_FCVolumeSource(in, out, s)
} }
func autoconvert_v1_FlexVolumeSource_To_api_FlexVolumeSource(in *FlexVolumeSource, out *api.FlexVolumeSource, s conversion.Scope) error {
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
defaulting.(func(*FlexVolumeSource))(in)
}
out.Driver = in.Driver
out.FSType = in.FSType
if in.SecretRef != nil {
out.SecretRef = new(api.LocalObjectReference)
if err := convert_v1_LocalObjectReference_To_api_LocalObjectReference(in.SecretRef, out.SecretRef, s); err != nil {
return err
}
} else {
out.SecretRef = nil
}
out.ReadOnly = in.ReadOnly
if in.Options != nil {
out.Options = make(map[string]string)
for key, val := range in.Options {
out.Options[key] = val
}
} else {
out.Options = nil
}
return nil
}
func convert_v1_FlexVolumeSource_To_api_FlexVolumeSource(in *FlexVolumeSource, out *api.FlexVolumeSource, s conversion.Scope) error {
return autoconvert_v1_FlexVolumeSource_To_api_FlexVolumeSource(in, out, s)
}
func autoconvert_v1_FlockerVolumeSource_To_api_FlockerVolumeSource(in *FlockerVolumeSource, out *api.FlockerVolumeSource, s conversion.Scope) error { func autoconvert_v1_FlockerVolumeSource_To_api_FlockerVolumeSource(in *FlockerVolumeSource, out *api.FlockerVolumeSource, s conversion.Scope) error {
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found { if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
defaulting.(func(*FlockerVolumeSource))(in) defaulting.(func(*FlockerVolumeSource))(in)
@ -4891,6 +4967,14 @@ func autoconvert_v1_PersistentVolumeSource_To_api_PersistentVolumeSource(in *Per
} else { } else {
out.Flocker = nil out.Flocker = nil
} }
if in.FlexVolume != nil {
out.FlexVolume = new(api.FlexVolumeSource)
if err := convert_v1_FlexVolumeSource_To_api_FlexVolumeSource(in.FlexVolume, out.FlexVolume, s); err != nil {
return err
}
} else {
out.FlexVolume = nil
}
return nil return nil
} }
@ -6093,6 +6177,14 @@ func autoconvert_v1_VolumeSource_To_api_VolumeSource(in *VolumeSource, out *api.
} else { } else {
out.RBD = nil out.RBD = nil
} }
if in.FlexVolume != nil {
out.FlexVolume = new(api.FlexVolumeSource)
if err := convert_v1_FlexVolumeSource_To_api_FlexVolumeSource(in.FlexVolume, out.FlexVolume, s); err != nil {
return err
}
} else {
out.FlexVolume = nil
}
if in.Cinder != nil { if in.Cinder != nil {
out.Cinder = new(api.CinderVolumeSource) out.Cinder = new(api.CinderVolumeSource)
if err := convert_v1_CinderVolumeSource_To_api_CinderVolumeSource(in.Cinder, out.Cinder, s); err != nil { if err := convert_v1_CinderVolumeSource_To_api_CinderVolumeSource(in.Cinder, out.Cinder, s); err != nil {
@ -6174,6 +6266,7 @@ func init() {
autoconvert_api_Event_To_v1_Event, autoconvert_api_Event_To_v1_Event,
autoconvert_api_ExecAction_To_v1_ExecAction, autoconvert_api_ExecAction_To_v1_ExecAction,
autoconvert_api_FCVolumeSource_To_v1_FCVolumeSource, autoconvert_api_FCVolumeSource_To_v1_FCVolumeSource,
autoconvert_api_FlexVolumeSource_To_v1_FlexVolumeSource,
autoconvert_api_FlockerVolumeSource_To_v1_FlockerVolumeSource, autoconvert_api_FlockerVolumeSource_To_v1_FlockerVolumeSource,
autoconvert_api_GCEPersistentDiskVolumeSource_To_v1_GCEPersistentDiskVolumeSource, autoconvert_api_GCEPersistentDiskVolumeSource_To_v1_GCEPersistentDiskVolumeSource,
autoconvert_api_GitRepoVolumeSource_To_v1_GitRepoVolumeSource, autoconvert_api_GitRepoVolumeSource_To_v1_GitRepoVolumeSource,
@ -6294,6 +6387,7 @@ func init() {
autoconvert_v1_ExecAction_To_api_ExecAction, autoconvert_v1_ExecAction_To_api_ExecAction,
autoconvert_v1_ExportOptions_To_unversioned_ExportOptions, autoconvert_v1_ExportOptions_To_unversioned_ExportOptions,
autoconvert_v1_FCVolumeSource_To_api_FCVolumeSource, autoconvert_v1_FCVolumeSource_To_api_FCVolumeSource,
autoconvert_v1_FlexVolumeSource_To_api_FlexVolumeSource,
autoconvert_v1_FlockerVolumeSource_To_api_FlockerVolumeSource, autoconvert_v1_FlockerVolumeSource_To_api_FlockerVolumeSource,
autoconvert_v1_GCEPersistentDiskVolumeSource_To_api_GCEPersistentDiskVolumeSource, autoconvert_v1_GCEPersistentDiskVolumeSource_To_api_GCEPersistentDiskVolumeSource,
autoconvert_v1_GitRepoVolumeSource_To_api_GitRepoVolumeSource, autoconvert_v1_GitRepoVolumeSource_To_api_GitRepoVolumeSource,

View File

@ -616,6 +616,29 @@ func deepCopy_v1_FCVolumeSource(in FCVolumeSource, out *FCVolumeSource, c *conve
return nil return nil
} }
func deepCopy_v1_FlexVolumeSource(in FlexVolumeSource, out *FlexVolumeSource, c *conversion.Cloner) error {
out.Driver = in.Driver
out.FSType = in.FSType
if in.SecretRef != nil {
out.SecretRef = new(LocalObjectReference)
if err := deepCopy_v1_LocalObjectReference(*in.SecretRef, out.SecretRef, c); err != nil {
return err
}
} else {
out.SecretRef = nil
}
out.ReadOnly = in.ReadOnly
if in.Options != nil {
out.Options = make(map[string]string)
for key, val := range in.Options {
out.Options[key] = val
}
} else {
out.Options = nil
}
return nil
}
func deepCopy_v1_FlockerVolumeSource(in FlockerVolumeSource, out *FlockerVolumeSource, c *conversion.Cloner) error { func deepCopy_v1_FlockerVolumeSource(in FlockerVolumeSource, out *FlockerVolumeSource, c *conversion.Cloner) error {
out.DatasetName = in.DatasetName out.DatasetName = in.DatasetName
return nil return nil
@ -1357,6 +1380,14 @@ func deepCopy_v1_PersistentVolumeSource(in PersistentVolumeSource, out *Persiste
} else { } else {
out.Flocker = nil out.Flocker = nil
} }
if in.FlexVolume != nil {
out.FlexVolume = new(FlexVolumeSource)
if err := deepCopy_v1_FlexVolumeSource(*in.FlexVolume, out.FlexVolume, c); err != nil {
return err
}
} else {
out.FlexVolume = nil
}
return nil return nil
} }
@ -2325,6 +2356,14 @@ func deepCopy_v1_VolumeSource(in VolumeSource, out *VolumeSource, c *conversion.
} else { } else {
out.RBD = nil out.RBD = nil
} }
if in.FlexVolume != nil {
out.FlexVolume = new(FlexVolumeSource)
if err := deepCopy_v1_FlexVolumeSource(*in.FlexVolume, out.FlexVolume, c); err != nil {
return err
}
} else {
out.FlexVolume = nil
}
if in.Cinder != nil { if in.Cinder != nil {
out.Cinder = new(CinderVolumeSource) out.Cinder = new(CinderVolumeSource)
if err := deepCopy_v1_CinderVolumeSource(*in.Cinder, out.Cinder, c); err != nil { if err := deepCopy_v1_CinderVolumeSource(*in.Cinder, out.Cinder, c); err != nil {
@ -2426,6 +2465,7 @@ func init() {
deepCopy_v1_ExecAction, deepCopy_v1_ExecAction,
deepCopy_v1_ExportOptions, deepCopy_v1_ExportOptions,
deepCopy_v1_FCVolumeSource, deepCopy_v1_FCVolumeSource,
deepCopy_v1_FlexVolumeSource,
deepCopy_v1_FlockerVolumeSource, deepCopy_v1_FlockerVolumeSource,
deepCopy_v1_GCEPersistentDiskVolumeSource, deepCopy_v1_GCEPersistentDiskVolumeSource,
deepCopy_v1_GitRepoVolumeSource, deepCopy_v1_GitRepoVolumeSource,

File diff suppressed because it is too large Load Diff

View File

@ -243,6 +243,10 @@ type VolumeSource struct {
// RBD represents a Rados Block Device mount on the host that shares a pod's lifetime. // RBD represents a Rados Block Device mount on the host that shares a pod's lifetime.
// More info: http://releases.k8s.io/HEAD/examples/rbd/README.md // More info: http://releases.k8s.io/HEAD/examples/rbd/README.md
RBD *RBDVolumeSource `json:"rbd,omitempty"` RBD *RBDVolumeSource `json:"rbd,omitempty"`
// FlexVolume represents a generic volume resource that is
// provisioned/attached using a exec based plugin. This is an
// alpha feature and may change in future.
FlexVolume *FlexVolumeSource `json:"flexVolume,omitempty"`
// Cinder represents a cinder volume attached and mounted on kubelets host machine // Cinder represents a cinder volume attached and mounted on kubelets host machine
// More info: http://releases.k8s.io/HEAD/examples/mysql-cinder-pd/README.md // More info: http://releases.k8s.io/HEAD/examples/mysql-cinder-pd/README.md
Cinder *CinderVolumeSource `json:"cinder,omitempty"` Cinder *CinderVolumeSource `json:"cinder,omitempty"`
@ -311,6 +315,10 @@ type PersistentVolumeSource struct {
FC *FCVolumeSource `json:"fc,omitempty"` FC *FCVolumeSource `json:"fc,omitempty"`
// Flocker represents a Flocker volume attached to a kubelet's host machine and exposed to the pod for its usage. This depends on the Flocker control service being running // Flocker represents a Flocker volume attached to a kubelet's host machine and exposed to the pod for its usage. This depends on the Flocker control service being running
Flocker *FlockerVolumeSource `json:"flocker,omitempty"` Flocker *FlockerVolumeSource `json:"flocker,omitempty"`
// FlexVolume represents a generic volume resource that is
// provisioned/attached using a exec based plugin. This is an
// alpha feature and may change in future.
FlexVolume *FlexVolumeSource `json:"flexVolume,omitempty"`
} }
// PersistentVolume (PV) is a storage resource provisioned by an administrator. // PersistentVolume (PV) is a storage resource provisioned by an administrator.
@ -650,6 +658,24 @@ type GCEPersistentDiskVolumeSource struct {
ReadOnly bool `json:"readOnly,omitempty"` ReadOnly bool `json:"readOnly,omitempty"`
} }
// FlexVolume represents a generic volume resource that is
// provisioned/attached using a exec based plugin. This is an alpha feature and may change in future.
type FlexVolumeSource struct {
// Driver is the name of the driver to use for this volume.
Driver string `json:"driver"`
// Required: Filesystem type to mount.
// Must be a filesystem type supported by the host operating system.
// Ex. "ext4", "xfs", "ntfs"
FSType string `json:"fsType,omitempty"`
// Optional: SecretRef is reference to the authentication secret for User, default is empty.
SecretRef *LocalObjectReference `json:"secretRef,omitempty"`
// Optional: Defaults to false (read/write). ReadOnly here will force
// the ReadOnly setting in VolumeMounts.
ReadOnly bool `json:"readOnly,omitempty"`
// Optional: Extra command options if any.
Options map[string]string `json:"options,omitempty"`
}
// Represents a Persistent Disk resource in AWS. // Represents a Persistent Disk resource in AWS.
// //
// An AWS EBS disk must exist and be formatted before mounting to a container. // An AWS EBS disk must exist and be formatted before mounting to a container.

View File

@ -401,6 +401,19 @@ func (FCVolumeSource) SwaggerDoc() map[string]string {
return map_FCVolumeSource return map_FCVolumeSource
} }
var map_FlexVolumeSource = map[string]string{
"": "FlexVolume represents a generic volume resource that is provisioned/attached using a exec based plugin. This is an alpha feature and may change in future.",
"driver": "Driver is the name of the driver to use for this volume.",
"fsType": "Required: Filesystem type to mount. Must be a filesystem type supported by the host operating system. Ex. \"ext4\", \"xfs\", \"ntfs\"",
"secretRef": "Optional: SecretRef is reference to the authentication secret for User, default is empty.",
"readOnly": "Optional: Defaults to false (read/write). ReadOnly here will force the ReadOnly setting in VolumeMounts.",
"options": "Optional: Extra command options if any.",
}
func (FlexVolumeSource) SwaggerDoc() map[string]string {
return map_FlexVolumeSource
}
var map_FlockerVolumeSource = map[string]string{ var map_FlockerVolumeSource = map[string]string{
"": "Represents a Flocker volume mounted by the Flocker agent. Flocker volumes do not support ownership management or SELinux relabeling.", "": "Represents a Flocker volume mounted by the Flocker agent. Flocker volumes do not support ownership management or SELinux relabeling.",
"datasetName": "Required: the volume name. This is going to be store on metadata -> name on the payload for Flocker", "datasetName": "Required: the volume name. This is going to be store on metadata -> name on the payload for Flocker",
@ -873,6 +886,7 @@ var map_PersistentVolumeSource = map[string]string{
"cephfs": "CephFS represents a Ceph FS mount on the host that shares a pod's lifetime", "cephfs": "CephFS represents a Ceph FS mount on the host that shares a pod's lifetime",
"fc": "FC represents a Fibre Channel resource that is attached to a kubelet's host machine and then exposed to the pod.", "fc": "FC represents a Fibre Channel resource that is attached to a kubelet's host machine and then exposed to the pod.",
"flocker": "Flocker represents a Flocker volume attached to a kubelet's host machine and exposed to the pod for its usage. This depends on the Flocker control service being running", "flocker": "Flocker represents a Flocker volume attached to a kubelet's host machine and exposed to the pod for its usage. This depends on the Flocker control service being running",
"flexVolume": "FlexVolume represents a generic volume resource that is provisioned/attached using a exec based plugin. This is an alpha feature and may change in future.",
} }
func (PersistentVolumeSource) SwaggerDoc() map[string]string { func (PersistentVolumeSource) SwaggerDoc() map[string]string {
@ -1399,6 +1413,7 @@ var map_VolumeSource = map[string]string{
"glusterfs": "Glusterfs represents a Glusterfs mount on the host that shares a pod's lifetime. More info: http://releases.k8s.io/HEAD/examples/glusterfs/README.md", "glusterfs": "Glusterfs represents a Glusterfs mount on the host that shares a pod's lifetime. More info: http://releases.k8s.io/HEAD/examples/glusterfs/README.md",
"persistentVolumeClaim": "PersistentVolumeClaimVolumeSource represents a reference to a PersistentVolumeClaim in the same namespace. More info: http://releases.k8s.io/HEAD/docs/user-guide/persistent-volumes.md#persistentvolumeclaims", "persistentVolumeClaim": "PersistentVolumeClaimVolumeSource represents a reference to a PersistentVolumeClaim in the same namespace. More info: http://releases.k8s.io/HEAD/docs/user-guide/persistent-volumes.md#persistentvolumeclaims",
"rbd": "RBD represents a Rados Block Device mount on the host that shares a pod's lifetime. More info: http://releases.k8s.io/HEAD/examples/rbd/README.md", "rbd": "RBD represents a Rados Block Device mount on the host that shares a pod's lifetime. More info: http://releases.k8s.io/HEAD/examples/rbd/README.md",
"flexVolume": "FlexVolume represents a generic volume resource that is provisioned/attached using a exec based plugin. This is an alpha feature and may change in future.",
"cinder": "Cinder represents a cinder volume attached and mounted on kubelets host machine More info: http://releases.k8s.io/HEAD/examples/mysql-cinder-pd/README.md", "cinder": "Cinder represents a cinder volume attached and mounted on kubelets host machine More info: http://releases.k8s.io/HEAD/examples/mysql-cinder-pd/README.md",
"cephfs": "CephFS represents a Ceph FS mount on the host that shares a pod's lifetime", "cephfs": "CephFS represents a Ceph FS mount on the host that shares a pod's lifetime",
"flocker": "Flocker represents a Flocker volume attached to a kubelet's host machine. This depends on the Flocker control service being running", "flocker": "Flocker represents a Flocker volume attached to a kubelet's host machine. This depends on the Flocker control service being running",

View File

@ -484,6 +484,10 @@ func validateVolumeSource(source *api.VolumeSource, fldPath *field.Path) field.E
allErrs = append(allErrs, validateFCVolumeSource(source.FC, fldPath.Child("fc"))...) allErrs = append(allErrs, validateFCVolumeSource(source.FC, fldPath.Child("fc"))...)
} }
} }
if source.FlexVolume != nil {
numVolumes++
allErrs = append(allErrs, validateFlexVolumeSource(source.FlexVolume, fldPath.Child("FlexVolume"))...)
}
if numVolumes == 0 { if numVolumes == 0 {
allErrs = append(allErrs, field.Required(fldPath, "must specify a volume type")) allErrs = append(allErrs, field.Required(fldPath, "must specify a volume type"))
} }
@ -697,6 +701,17 @@ func validateCephFSVolumeSource(cephfs *api.CephFSVolumeSource, fldPath *field.P
return allErrs return allErrs
} }
func validateFlexVolumeSource(fv *api.FlexVolumeSource, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
if len(fv.Driver) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("driver"), ""))
}
if len(fv.FSType) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("fsType"), ""))
}
return allErrs
}
func ValidatePersistentVolumeName(name string, prefix bool) (bool, string) { func ValidatePersistentVolumeName(name string, prefix bool) (bool, string) {
return NameIsDNSSubdomain(name, prefix) return NameIsDNSSubdomain(name, prefix)
} }
@ -817,6 +832,10 @@ func ValidatePersistentVolume(pv *api.PersistentVolume) field.ErrorList {
allErrs = append(allErrs, validateFCVolumeSource(pv.Spec.FC, specPath.Child("fc"))...) allErrs = append(allErrs, validateFCVolumeSource(pv.Spec.FC, specPath.Child("fc"))...)
} }
} }
if pv.Spec.FlexVolume != nil {
numVolumes++
allErrs = append(allErrs, validateFlexVolumeSource(pv.Spec.FlexVolume, specPath.Child("flexVolume"))...)
}
if numVolumes == 0 { if numVolumes == 0 {
allErrs = append(allErrs, field.Required(specPath, "must specify a volume type")) allErrs = append(allErrs, field.Required(specPath, "must specify a volume type"))
} }

View File

@ -508,12 +508,13 @@ func TestValidateVolumes(t *testing.T) {
FieldPath: "metadata.labels"}}, FieldPath: "metadata.labels"}},
}}}}, }}}},
{Name: "fc", VolumeSource: api.VolumeSource{FC: &api.FCVolumeSource{[]string{"some_wwn"}, &lun, "ext4", false}}}, {Name: "fc", VolumeSource: api.VolumeSource{FC: &api.FCVolumeSource{[]string{"some_wwn"}, &lun, "ext4", false}}},
{Name: "flexvolume", VolumeSource: api.VolumeSource{FlexVolume: &api.FlexVolumeSource{Driver: "kubernetes.io/blue", FSType: "ext4"}}},
} }
names, errs := validateVolumes(successCase, field.NewPath("field")) names, errs := validateVolumes(successCase, field.NewPath("field"))
if len(errs) != 0 { if len(errs) != 0 {
t.Errorf("expected success: %v", errs) t.Errorf("expected success: %v", errs)
} }
if len(names) != len(successCase) || !names.HasAll("abc", "123", "abc-123", "empty", "gcepd", "gitrepo", "secret", "iscsidisk", "cinder", "cephfs", "fc") { if len(names) != len(successCase) || !names.HasAll("abc", "123", "abc-123", "empty", "gcepd", "gitrepo", "secret", "iscsidisk", "cinder", "cephfs", "flexvolume", "fc") {
t.Errorf("wrong names result: %v", names) t.Errorf("wrong names result: %v", names)
} }
emptyVS := api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}} emptyVS := api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}

View File

@ -274,6 +274,29 @@ func deepCopy_api_FCVolumeSource(in api.FCVolumeSource, out *api.FCVolumeSource,
return nil return nil
} }
func deepCopy_api_FlexVolumeSource(in api.FlexVolumeSource, out *api.FlexVolumeSource, c *conversion.Cloner) error {
out.Driver = in.Driver
out.FSType = in.FSType
if in.SecretRef != nil {
out.SecretRef = new(api.LocalObjectReference)
if err := deepCopy_api_LocalObjectReference(*in.SecretRef, out.SecretRef, c); err != nil {
return err
}
} else {
out.SecretRef = nil
}
out.ReadOnly = in.ReadOnly
if in.Options != nil {
out.Options = make(map[string]string)
for key, val := range in.Options {
out.Options[key] = val
}
} else {
out.Options = nil
}
return nil
}
func deepCopy_api_FlockerVolumeSource(in api.FlockerVolumeSource, out *api.FlockerVolumeSource, c *conversion.Cloner) error { func deepCopy_api_FlockerVolumeSource(in api.FlockerVolumeSource, out *api.FlockerVolumeSource, c *conversion.Cloner) error {
out.DatasetName = in.DatasetName out.DatasetName = in.DatasetName
return nil return nil
@ -807,6 +830,14 @@ func deepCopy_api_VolumeSource(in api.VolumeSource, out *api.VolumeSource, c *co
} else { } else {
out.RBD = nil out.RBD = nil
} }
if in.FlexVolume != nil {
out.FlexVolume = new(api.FlexVolumeSource)
if err := deepCopy_api_FlexVolumeSource(*in.FlexVolume, out.FlexVolume, c); err != nil {
return err
}
} else {
out.FlexVolume = nil
}
if in.Cinder != nil { if in.Cinder != nil {
out.Cinder = new(api.CinderVolumeSource) out.Cinder = new(api.CinderVolumeSource)
if err := deepCopy_api_CinderVolumeSource(*in.Cinder, out.Cinder, c); err != nil { if err := deepCopy_api_CinderVolumeSource(*in.Cinder, out.Cinder, c); err != nil {
@ -1639,6 +1670,7 @@ func init() {
deepCopy_api_EnvVarSource, deepCopy_api_EnvVarSource,
deepCopy_api_ExecAction, deepCopy_api_ExecAction,
deepCopy_api_FCVolumeSource, deepCopy_api_FCVolumeSource,
deepCopy_api_FlexVolumeSource,
deepCopy_api_FlockerVolumeSource, deepCopy_api_FlockerVolumeSource,
deepCopy_api_GCEPersistentDiskVolumeSource, deepCopy_api_GCEPersistentDiskVolumeSource,
deepCopy_api_GitRepoVolumeSource, deepCopy_api_GitRepoVolumeSource,

View File

@ -364,6 +364,36 @@ func convert_api_FCVolumeSource_To_v1_FCVolumeSource(in *api.FCVolumeSource, out
return autoconvert_api_FCVolumeSource_To_v1_FCVolumeSource(in, out, s) return autoconvert_api_FCVolumeSource_To_v1_FCVolumeSource(in, out, s)
} }
func autoconvert_api_FlexVolumeSource_To_v1_FlexVolumeSource(in *api.FlexVolumeSource, out *v1.FlexVolumeSource, s conversion.Scope) error {
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
defaulting.(func(*api.FlexVolumeSource))(in)
}
out.Driver = in.Driver
out.FSType = in.FSType
if in.SecretRef != nil {
out.SecretRef = new(v1.LocalObjectReference)
if err := convert_api_LocalObjectReference_To_v1_LocalObjectReference(in.SecretRef, out.SecretRef, s); err != nil {
return err
}
} else {
out.SecretRef = nil
}
out.ReadOnly = in.ReadOnly
if in.Options != nil {
out.Options = make(map[string]string)
for key, val := range in.Options {
out.Options[key] = val
}
} else {
out.Options = nil
}
return nil
}
func convert_api_FlexVolumeSource_To_v1_FlexVolumeSource(in *api.FlexVolumeSource, out *v1.FlexVolumeSource, s conversion.Scope) error {
return autoconvert_api_FlexVolumeSource_To_v1_FlexVolumeSource(in, out, s)
}
func autoconvert_api_FlockerVolumeSource_To_v1_FlockerVolumeSource(in *api.FlockerVolumeSource, out *v1.FlockerVolumeSource, s conversion.Scope) error { func autoconvert_api_FlockerVolumeSource_To_v1_FlockerVolumeSource(in *api.FlockerVolumeSource, out *v1.FlockerVolumeSource, s conversion.Scope) error {
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found { if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
defaulting.(func(*api.FlockerVolumeSource))(in) defaulting.(func(*api.FlockerVolumeSource))(in)
@ -1070,6 +1100,14 @@ func autoconvert_api_VolumeSource_To_v1_VolumeSource(in *api.VolumeSource, out *
} else { } else {
out.RBD = nil out.RBD = nil
} }
if in.FlexVolume != nil {
out.FlexVolume = new(v1.FlexVolumeSource)
if err := convert_api_FlexVolumeSource_To_v1_FlexVolumeSource(in.FlexVolume, out.FlexVolume, s); err != nil {
return err
}
} else {
out.FlexVolume = nil
}
if in.Cinder != nil { if in.Cinder != nil {
out.Cinder = new(v1.CinderVolumeSource) out.Cinder = new(v1.CinderVolumeSource)
if err := convert_api_CinderVolumeSource_To_v1_CinderVolumeSource(in.Cinder, out.Cinder, s); err != nil { if err := convert_api_CinderVolumeSource_To_v1_CinderVolumeSource(in.Cinder, out.Cinder, s); err != nil {
@ -1453,6 +1491,36 @@ func convert_v1_FCVolumeSource_To_api_FCVolumeSource(in *v1.FCVolumeSource, out
return autoconvert_v1_FCVolumeSource_To_api_FCVolumeSource(in, out, s) return autoconvert_v1_FCVolumeSource_To_api_FCVolumeSource(in, out, s)
} }
func autoconvert_v1_FlexVolumeSource_To_api_FlexVolumeSource(in *v1.FlexVolumeSource, out *api.FlexVolumeSource, s conversion.Scope) error {
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
defaulting.(func(*v1.FlexVolumeSource))(in)
}
out.Driver = in.Driver
out.FSType = in.FSType
if in.SecretRef != nil {
out.SecretRef = new(api.LocalObjectReference)
if err := convert_v1_LocalObjectReference_To_api_LocalObjectReference(in.SecretRef, out.SecretRef, s); err != nil {
return err
}
} else {
out.SecretRef = nil
}
out.ReadOnly = in.ReadOnly
if in.Options != nil {
out.Options = make(map[string]string)
for key, val := range in.Options {
out.Options[key] = val
}
} else {
out.Options = nil
}
return nil
}
func convert_v1_FlexVolumeSource_To_api_FlexVolumeSource(in *v1.FlexVolumeSource, out *api.FlexVolumeSource, s conversion.Scope) error {
return autoconvert_v1_FlexVolumeSource_To_api_FlexVolumeSource(in, out, s)
}
func autoconvert_v1_FlockerVolumeSource_To_api_FlockerVolumeSource(in *v1.FlockerVolumeSource, out *api.FlockerVolumeSource, s conversion.Scope) error { func autoconvert_v1_FlockerVolumeSource_To_api_FlockerVolumeSource(in *v1.FlockerVolumeSource, out *api.FlockerVolumeSource, s conversion.Scope) error {
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found { if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
defaulting.(func(*v1.FlockerVolumeSource))(in) defaulting.(func(*v1.FlockerVolumeSource))(in)
@ -2135,6 +2203,14 @@ func autoconvert_v1_VolumeSource_To_api_VolumeSource(in *v1.VolumeSource, out *a
} else { } else {
out.RBD = nil out.RBD = nil
} }
if in.FlexVolume != nil {
out.FlexVolume = new(api.FlexVolumeSource)
if err := convert_v1_FlexVolumeSource_To_api_FlexVolumeSource(in.FlexVolume, out.FlexVolume, s); err != nil {
return err
}
} else {
out.FlexVolume = nil
}
if in.Cinder != nil { if in.Cinder != nil {
out.Cinder = new(api.CinderVolumeSource) out.Cinder = new(api.CinderVolumeSource)
if err := convert_v1_CinderVolumeSource_To_api_CinderVolumeSource(in.Cinder, out.Cinder, s); err != nil { if err := convert_v1_CinderVolumeSource_To_api_CinderVolumeSource(in.Cinder, out.Cinder, s); err != nil {
@ -4291,6 +4367,7 @@ func init() {
autoconvert_api_EnvVar_To_v1_EnvVar, autoconvert_api_EnvVar_To_v1_EnvVar,
autoconvert_api_ExecAction_To_v1_ExecAction, autoconvert_api_ExecAction_To_v1_ExecAction,
autoconvert_api_FCVolumeSource_To_v1_FCVolumeSource, autoconvert_api_FCVolumeSource_To_v1_FCVolumeSource,
autoconvert_api_FlexVolumeSource_To_v1_FlexVolumeSource,
autoconvert_api_FlockerVolumeSource_To_v1_FlockerVolumeSource, autoconvert_api_FlockerVolumeSource_To_v1_FlockerVolumeSource,
autoconvert_api_GCEPersistentDiskVolumeSource_To_v1_GCEPersistentDiskVolumeSource, autoconvert_api_GCEPersistentDiskVolumeSource_To_v1_GCEPersistentDiskVolumeSource,
autoconvert_api_GitRepoVolumeSource_To_v1_GitRepoVolumeSource, autoconvert_api_GitRepoVolumeSource_To_v1_GitRepoVolumeSource,
@ -4380,6 +4457,7 @@ func init() {
autoconvert_v1_EnvVar_To_api_EnvVar, autoconvert_v1_EnvVar_To_api_EnvVar,
autoconvert_v1_ExecAction_To_api_ExecAction, autoconvert_v1_ExecAction_To_api_ExecAction,
autoconvert_v1_FCVolumeSource_To_api_FCVolumeSource, autoconvert_v1_FCVolumeSource_To_api_FCVolumeSource,
autoconvert_v1_FlexVolumeSource_To_api_FlexVolumeSource,
autoconvert_v1_FlockerVolumeSource_To_api_FlockerVolumeSource, autoconvert_v1_FlockerVolumeSource_To_api_FlockerVolumeSource,
autoconvert_v1_GCEPersistentDiskVolumeSource_To_api_GCEPersistentDiskVolumeSource, autoconvert_v1_GCEPersistentDiskVolumeSource_To_api_GCEPersistentDiskVolumeSource,
autoconvert_v1_GitRepoVolumeSource_To_api_GitRepoVolumeSource, autoconvert_v1_GitRepoVolumeSource_To_api_GitRepoVolumeSource,

View File

@ -310,6 +310,29 @@ func deepCopy_v1_FCVolumeSource(in v1.FCVolumeSource, out *v1.FCVolumeSource, c
return nil return nil
} }
func deepCopy_v1_FlexVolumeSource(in v1.FlexVolumeSource, out *v1.FlexVolumeSource, c *conversion.Cloner) error {
out.Driver = in.Driver
out.FSType = in.FSType
if in.SecretRef != nil {
out.SecretRef = new(v1.LocalObjectReference)
if err := deepCopy_v1_LocalObjectReference(*in.SecretRef, out.SecretRef, c); err != nil {
return err
}
} else {
out.SecretRef = nil
}
out.ReadOnly = in.ReadOnly
if in.Options != nil {
out.Options = make(map[string]string)
for key, val := range in.Options {
out.Options[key] = val
}
} else {
out.Options = nil
}
return nil
}
func deepCopy_v1_FlockerVolumeSource(in v1.FlockerVolumeSource, out *v1.FlockerVolumeSource, c *conversion.Cloner) error { func deepCopy_v1_FlockerVolumeSource(in v1.FlockerVolumeSource, out *v1.FlockerVolumeSource, c *conversion.Cloner) error {
out.DatasetName = in.DatasetName out.DatasetName = in.DatasetName
return nil return nil
@ -844,6 +867,14 @@ func deepCopy_v1_VolumeSource(in v1.VolumeSource, out *v1.VolumeSource, c *conve
} else { } else {
out.RBD = nil out.RBD = nil
} }
if in.FlexVolume != nil {
out.FlexVolume = new(v1.FlexVolumeSource)
if err := deepCopy_v1_FlexVolumeSource(*in.FlexVolume, out.FlexVolume, c); err != nil {
return err
}
} else {
out.FlexVolume = nil
}
if in.Cinder != nil { if in.Cinder != nil {
out.Cinder = new(v1.CinderVolumeSource) out.Cinder = new(v1.CinderVolumeSource)
if err := deepCopy_v1_CinderVolumeSource(*in.Cinder, out.Cinder, c); err != nil { if err := deepCopy_v1_CinderVolumeSource(*in.Cinder, out.Cinder, c); err != nil {
@ -1682,6 +1713,7 @@ func init() {
deepCopy_v1_EnvVarSource, deepCopy_v1_EnvVarSource,
deepCopy_v1_ExecAction, deepCopy_v1_ExecAction,
deepCopy_v1_FCVolumeSource, deepCopy_v1_FCVolumeSource,
deepCopy_v1_FlexVolumeSource,
deepCopy_v1_FlockerVolumeSource, deepCopy_v1_FlockerVolumeSource,
deepCopy_v1_GCEPersistentDiskVolumeSource, deepCopy_v1_GCEPersistentDiskVolumeSource,
deepCopy_v1_GitRepoVolumeSource, deepCopy_v1_GitRepoVolumeSource,

View File

@ -20,6 +20,19 @@ import (
"strings" "strings"
) )
// EscapePluginName converts a plugin name in the format
// vendor/pluginname into a proper ondisk vendor~pluginname plugin directory
// format.
func EscapePluginName(in string) string {
return strings.Replace(in, "/", "~", -1)
}
// EscapeQualifiedPluginName converts a plugin directory name in the format
// vendor~pluginname into a proper vendor/pluginname.
func UnescapePluginName(in string) string {
return strings.Replace(in, "~", "/", -1)
}
// EscapeQualifiedNameForDisk converts a plugin name, which might contain a / into a // EscapeQualifiedNameForDisk converts a plugin name, which might contain a / into a
// string that is safe to use on-disk. This assumes that the input has already // string that is safe to use on-disk. This assumes that the input has already
// been validates as a qualified name. we use "~" rather than ":" here in case // been validates as a qualified name. we use "~" rather than ":" here in case

View File

@ -53,8 +53,9 @@ const (
awsElasticBlockStorePluginName = "kubernetes.io/aws-ebs" awsElasticBlockStorePluginName = "kubernetes.io/aws-ebs"
) )
func (plugin *awsElasticBlockStorePlugin) Init(host volume.VolumeHost) { func (plugin *awsElasticBlockStorePlugin) Init(host volume.VolumeHost) error {
plugin.host = host plugin.host = host
return nil
} }
func (plugin *awsElasticBlockStorePlugin) Name() string { func (plugin *awsElasticBlockStorePlugin) Name() string {

View File

@ -43,8 +43,9 @@ const (
cephfsPluginName = "kubernetes.io/cephfs" cephfsPluginName = "kubernetes.io/cephfs"
) )
func (plugin *cephfsPlugin) Init(host volume.VolumeHost) { func (plugin *cephfsPlugin) Init(host volume.VolumeHost) error {
plugin.host = host plugin.host = host
return nil
} }
func (plugin *cephfsPlugin) Name() string { func (plugin *cephfsPlugin) Name() string {

View File

@ -51,8 +51,9 @@ const (
cinderVolumePluginName = "kubernetes.io/cinder" cinderVolumePluginName = "kubernetes.io/cinder"
) )
func (plugin *cinderPlugin) Init(host volume.VolumeHost) { func (plugin *cinderPlugin) Init(host volume.VolumeHost) error {
plugin.host = host plugin.host = host
return nil
} }
func (plugin *cinderPlugin) Name() string { func (plugin *cinderPlugin) Name() string {

View File

@ -51,8 +51,9 @@ type downwardAPIPlugin struct {
var _ volume.VolumePlugin = &downwardAPIPlugin{} var _ volume.VolumePlugin = &downwardAPIPlugin{}
func (plugin *downwardAPIPlugin) Init(host volume.VolumeHost) { func (plugin *downwardAPIPlugin) Init(host volume.VolumeHost) error {
plugin.host = host plugin.host = host
return nil
} }
func (plugin *downwardAPIPlugin) Name() string { func (plugin *downwardAPIPlugin) Name() string {

View File

@ -54,8 +54,10 @@ const (
emptyDirPluginName = "kubernetes.io/empty-dir" emptyDirPluginName = "kubernetes.io/empty-dir"
) )
func (plugin *emptyDirPlugin) Init(host volume.VolumeHost) { func (plugin *emptyDirPlugin) Init(host volume.VolumeHost) error {
plugin.host = host plugin.host = host
return nil
} }
func (plugin *emptyDirPlugin) Name() string { func (plugin *emptyDirPlugin) Name() string {

View File

@ -46,8 +46,9 @@ const (
fcPluginName = "kubernetes.io/fc" fcPluginName = "kubernetes.io/fc"
) )
func (plugin *fcPlugin) Init(host volume.VolumeHost) { func (plugin *fcPlugin) Init(host volume.VolumeHost) error {
plugin.host = host plugin.host = host
return nil
} }
func (plugin *fcPlugin) Name() string { func (plugin *fcPlugin) Name() string {

View File

@ -0,0 +1,388 @@
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package flexvolume
import (
"fmt"
"io/ioutil"
"os"
"path"
"strings"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/exec"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/volume"
)
// This is the primary entrypoint for volume plugins.
func ProbeVolumePlugins(pluginDir string) []volume.VolumePlugin {
plugins := []volume.VolumePlugin{}
files, _ := ioutil.ReadDir(pluginDir)
for _, f := range files {
// only directories are counted as plugins
// and pluginDir/dirname/dirname should be an executable
// unless dirname contains '~' for escaping namespace
// e.g. dirname = vendor~cifs
// then, executable will be pluginDir/dirname/cifs
if f.IsDir() {
execPath := path.Join(pluginDir, f.Name())
plugins = append(plugins, &flexVolumePlugin{driverName: util.UnescapePluginName(f.Name()), execPath: execPath})
}
}
return plugins
}
// FlexVolumePlugin object.
type flexVolumePlugin struct {
driverName string
execPath string
host volume.VolumeHost
}
// Init intializes the plugin.
func (plugin *flexVolumePlugin) Init(host volume.VolumeHost) error {
plugin.host = host
// call the init script
u := &flexVolumeUtil{}
return u.init(plugin)
}
func (plugin *flexVolumePlugin) getExecutable() string {
parts := strings.Split(plugin.driverName, "/")
execName := parts[len(parts)-1]
return path.Join(plugin.execPath, execName)
}
func (plugin *flexVolumePlugin) Name() string {
return plugin.driverName
}
// CanSupport checks whether the plugin can support the input volume spec.
func (plugin *flexVolumePlugin) CanSupport(spec *volume.Spec) bool {
source := plugin.getVolumeSource(spec)
return (source != nil) && (source.Driver == plugin.driverName)
}
// GetAccessModes gets the allowed access modes for this plugin.
func (plugin *flexVolumePlugin) GetAccessModes() []api.PersistentVolumeAccessMode {
return []api.PersistentVolumeAccessMode{
api.ReadWriteOnce,
api.ReadOnlyMany,
}
}
func (plugin *flexVolumePlugin) getVolumeSource(spec *volume.Spec) *api.FlexVolumeSource {
var source *api.FlexVolumeSource
if spec.Volume != nil && spec.Volume.FlexVolume != nil {
source = spec.Volume.FlexVolume
} else if spec.PersistentVolume != nil && spec.PersistentVolume.Spec.FlexVolume != nil {
source = spec.PersistentVolume.Spec.FlexVolume
}
return source
}
// NewBuilder is the builder routine to build the volume.
func (plugin *flexVolumePlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ volume.VolumeOptions) (volume.Builder, error) {
fv := plugin.getVolumeSource(spec)
secret := ""
if fv.SecretRef != nil {
kubeClient := plugin.host.GetKubeClient()
if kubeClient == nil {
return nil, fmt.Errorf("Cannot get kube client")
}
secretName, err := kubeClient.Secrets(pod.Namespace).Get(fv.SecretRef.Name)
if err != nil {
err = fmt.Errorf("Couldn't get secret %v/%v err: %v", pod.Namespace, fv.SecretRef, err)
return nil, err
}
for name, data := range secretName.Data {
secret = string(data)
glog.V(1).Infof("found flex volume secret info: %s", name)
}
}
return plugin.newBuilderInternal(spec, pod, &flexVolumeUtil{}, plugin.host.GetMounter(), exec.New(), secret)
}
// newBuilderInternal is the internal builder routine to build the volume.
func (plugin *flexVolumePlugin) newBuilderInternal(spec *volume.Spec, pod *api.Pod, manager flexVolumeManager, mounter mount.Interface, runner exec.Interface, secret string) (volume.Builder, error) {
source := plugin.getVolumeSource(spec)
return &flexVolumeBuilder{
flexVolumeDisk: &flexVolumeDisk{
podUID: pod.UID,
podNamespace: pod.Namespace,
podName: pod.Name,
volName: spec.Name(),
driverName: source.Driver,
execPath: plugin.getExecutable(),
mounter: mounter,
plugin: plugin,
secret: secret,
},
fsType: source.FSType,
readOnly: source.ReadOnly,
options: source.Options,
runner: runner,
manager: manager,
blockDeviceMounter: &mount.SafeFormatAndMount{mounter, runner},
}, nil
}
// NewCleaner is the cleaner routine to clean the volume.
func (plugin *flexVolumePlugin) NewCleaner(volName string, podUID types.UID) (volume.Cleaner, error) {
return plugin.newCleanerInternal(volName, podUID, &flexVolumeUtil{}, plugin.host.GetMounter(), exec.New())
}
// newCleanerInternal is the internal cleaner routine to clean the volume.
func (plugin *flexVolumePlugin) newCleanerInternal(volName string, podUID types.UID, manager flexVolumeManager, mounter mount.Interface, runner exec.Interface) (volume.Cleaner, error) {
return &flexVolumeCleaner{
flexVolumeDisk: &flexVolumeDisk{
podUID: podUID,
volName: volName,
driverName: plugin.driverName,
execPath: plugin.getExecutable(),
mounter: mounter,
plugin: plugin,
},
runner: runner,
manager: manager,
}, nil
}
// flexVolume is the disk resource provided by this plugin.
type flexVolumeDisk struct {
// podUID is the UID of the pod.
podUID types.UID
// podNamespace is the namespace of the pod.
podNamespace string
// podName is the name of the pod.
podName string
// volName is the name of the pod volume.
volName string
// driverName is the name of the plugin driverName.
driverName string
// Driver executable used to setup the volume.
execPath string
// mounter provides the interface that is used to mount the actual
// block device.
mounter mount.Interface
// secret for the volume.
secret string
plugin *flexVolumePlugin
}
// FlexVolumeCleaner is the disk that will be cleaned by this plugin.
type flexVolumeCleaner struct {
*flexVolumeDisk
// Runner used to teardown the volume.
runner exec.Interface
// manager is the utility interface that provides API calls to the
// driverName to setup & teardown disks
manager flexVolumeManager
volume.MetricsNil
}
// FlexVolumeBuilder is the disk that will be exposed by this plugin.
type flexVolumeBuilder struct {
*flexVolumeDisk
// fsType is the type of the filesystem to create on the volume.
fsType string
// readOnly specifies whether the disk will be setup as read-only.
readOnly bool
// options are the extra params that will be passed to the plugin
// driverName.
options map[string]string
// Runner used to setup the volume.
runner exec.Interface
// manager is the utility interface that provides API calls to the
// driverName to setup & teardown disks
manager flexVolumeManager
// blockDeviceMounter provides the interface to create filesystem if the
// filesystem doesn't exist.
blockDeviceMounter mount.Interface
volume.MetricsNil
}
// SetUp creates new directory.
func (f *flexVolumeBuilder) SetUp() error {
return f.SetUpAt(f.GetPath())
}
// GetAttributes get the flex volume attributes. The attributes will be queried
// using plugin callout after we finalize the callout syntax.
func (f flexVolumeBuilder) GetAttributes() volume.Attributes {
return volume.Attributes{
ReadOnly: f.readOnly,
Managed: false,
SupportsOwnershipManagement: false,
SupportsSELinux: false,
}
}
// flexVolumeManager is the abstract interface to flex volume ops.
type flexVolumeManager interface {
// Attaches the disk to the kubelet's host machine.
attach(builder *flexVolumeBuilder) (string, error)
// Detaches the disk from the kubelet's host machine.
detach(cleaner *flexVolumeCleaner, dir string) error
// Mounts the disk on the Kubelet's host machine.
mount(builder *flexVolumeBuilder, mnt, dir string) error
// Unmounts the disk from the Kubelet's host machine.
unmount(builder *flexVolumeCleaner, dir string) error
}
// SetUpAt creates new directory.
func (f *flexVolumeBuilder) SetUpAt(dir string) error {
notmnt, err := f.blockDeviceMounter.IsLikelyNotMountPoint(dir)
if err != nil && !os.IsNotExist(err) {
glog.Errorf("Cannot validate mountpoint: %s", dir)
return err
}
if !notmnt {
return nil
}
if f.options == nil {
f.options = make(map[string]string)
}
f.options[optionFSType] = f.fsType
// Read write mount options.
if f.readOnly {
f.options[optionReadWrite] = "ro"
} else {
f.options[optionReadWrite] = "rw"
}
// Extract secret and pass it as options.
if f.secret != "" {
f.options[optionKeySecret] = f.secret
}
device, err := f.manager.attach(f)
if err != nil {
if !isCmdNotSupportedErr(err) {
glog.Errorf("Failed to attach volume: %s", f.volName)
return err
}
// Attach not supported or required. Continue to mount.
}
if err := f.manager.mount(f, device, dir); err != nil {
if !isCmdNotSupportedErr(err) {
glog.Errorf("Failed to mount volume: %s", f.volName)
return err
}
options := make([]string, 0)
if f.readOnly {
options = append(options, "ro")
} else {
options = append(options, "rw")
}
// Extract secret and pass it as options.
if f.secret != "" {
options = append(options, "secret="+f.secret)
}
os.MkdirAll(dir, 0750)
// Mount not supported by driver. Use core mounting logic.
err = f.blockDeviceMounter.Mount(string(device), dir, f.fsType, options)
if err != nil {
glog.Errorf("Failed to mount the volume: %s, device: %s, error: %s", f.volName, device, err.Error())
return err
}
}
return nil
}
// IsReadOnly returns true if the volume is read only.
func (f *flexVolumeBuilder) IsReadOnly() bool {
return f.readOnly
}
// GetPathFromPlugin gets the actual volume mount directory based on plugin.
func (f *flexVolumeDisk) GetPath() string {
name := f.driverName
return f.plugin.host.GetPodVolumeDir(f.podUID, util.EscapeQualifiedNameForDisk(name), f.volName)
}
// TearDown simply deletes everything in the directory.
func (f *flexVolumeCleaner) TearDown() error {
path := f.GetPath()
return f.TearDownAt(path)
}
// TearDownAt simply deletes everything in the directory.
func (f *flexVolumeCleaner) TearDownAt(dir string) error {
notmnt, err := f.mounter.IsLikelyNotMountPoint(dir)
if err != nil {
glog.Errorf("Error checking mount point %s, error: %v", dir, err)
return err
}
if notmnt {
return os.Remove(dir)
}
device, refCount, err := mount.GetDeviceNameFromMount(f.mounter, dir)
if err != nil {
glog.Errorf("Failed to get reference count for volume: %s", dir)
return err
}
if err := f.manager.unmount(f, dir); err != nil {
if !isCmdNotSupportedErr(err) {
glog.Errorf("Failed to unmount volume %s", f.volName)
return err
}
// Unmount not supported by the driver. Use core unmount logic.
if err := f.mounter.Unmount(dir); err != nil {
glog.Errorf("Failed to unmount volume: %s, error: %s", dir, err.Error())
return err
}
}
if refCount == 1 {
if err := f.manager.detach(f, device); err != nil {
if !isCmdNotSupportedErr(err) {
glog.Errorf("Failed to teardown volume: %s, error: %s", dir, err.Error())
return err
}
// Teardown not supported by driver. Unmount is good enough.
}
}
notmnt, err = f.mounter.IsLikelyNotMountPoint(dir)
if err != nil {
glog.Errorf("Error checking mount point %s, error: %v", dir, err)
return err
}
if notmnt {
return os.Remove(dir)
}
return nil
}

View File

@ -0,0 +1,374 @@
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package flexvolume
import (
"bytes"
"fmt"
"os"
"path"
"testing"
"text/template"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util/exec"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/volume"
)
// The temp dir where test plugins will be stored.
const testPluginPath = "/tmp/fake/plugins/volume"
const execScriptTempl1 = `#!/bin/bash
if [ "$1" == "init" -a $# -eq 1 ]; then
echo -n '{
"status": "Success"
}'
exit 0
fi
PATH=$2
if [ "$1" == "attach" -a $# -eq 2 ]; then
echo -n '{
"device": "{{.DevicePath}}",
"status": "Success"
}'
exit 0
elif [ "$1" == "detach" -a $# -eq 2 ]; then
echo -n '{
"status": "Success"
}'
exit 0
elif [ "$1" == "mount" -a $# -eq 4 ]; then
echo -n '{
"status": "Not supported"
}'
exit 0
elif [ "$1" == "unmount" -a $# -eq 2 ]; then
echo -n '{
"status": "Not supported"
}'
exit 0
fi
echo -n '{
"status": "Failure",
"reason": "Invalid usage"
}'
exit 1
# Direct the arguments to a file to be tested against later
echo -n $@ &> {{.OutputFile}}
`
const execScriptTempl2 = `#!/bin/bash
if [ "$1" == "init" -a $# -eq 1 ]; then
echo -n '{
"status": "Success"
}'
exit 0
fi
if [ "$1" == "attach" -a $# -eq 2 ]; then
echo -n '{
"status": "Not supported"
}'
exit 0
elif [ "$1" == "detach" -a $# -eq 2 ]; then
echo -n '{
"status": "Not supported"
}'
exit 0
elif [ "$1" == "mount" -a $# -eq 4 ]; then
PATH=$2
/bin/mkdir -p $PATH
if [ $? -ne 0 ]; then
echo -n '{
"status": "Failure",
"reason": "Failed to create $PATH"
}'
exit 1
fi
echo -n '{
"status": "Success"
}'
exit 0
elif [ "$1" == "unmount" -a $# -eq 2 ]; then
PATH=$2
/bin/rm -r $PATH
if [ $? -ne 0 ]; then
echo -n '{
"status": "Failure",
"reason": "Failed to cleanup $PATH"
}'
exit 1
fi
echo -n '{
"status": "Success"
}'
exit 0
fi
echo -n '{
"status": "Failure",
"reason": "Invalid usage"
}'
exit 1
# Direct the arguments to a file to be tested against later
echo -n $@ &> {{.OutputFile}}
`
func installPluginUnderTest(t *testing.T, vendorName string, plugName string, execScriptTempl string, execTemplateData *map[string]interface{}) {
vendoredName := plugName
if vendorName != "" {
vendoredName = fmt.Sprintf("%s~%s", vendorName, plugName)
}
pluginDir := path.Join(testPluginPath, vendoredName)
err := os.MkdirAll(pluginDir, 0777)
if err != nil {
t.Errorf("Failed to create plugin: %v", err)
}
pluginExec := path.Join(pluginDir, plugName)
f, err := os.Create(pluginExec)
if err != nil {
t.Errorf("Failed to install plugin")
}
err = f.Chmod(0777)
if err != nil {
t.Errorf("Failed to set exec perms on plugin")
}
if execTemplateData == nil {
execTemplateData = &map[string]interface{}{
"DevicePath": "/dev/sdx",
"OutputFile": path.Join(pluginDir, plugName+".out"),
}
}
tObj := template.Must(template.New("test").Parse(execScriptTempl))
buf := &bytes.Buffer{}
if err := tObj.Execute(buf, *execTemplateData); err != nil {
t.Errorf("Error in executing script template - %v", err)
}
execScript := buf.String()
_, err = f.WriteString(execScript)
if err != nil {
t.Errorf("Failed to write plugin exec")
}
f.Close()
}
func TestCanSupport(t *testing.T) {
plugMgr := volume.VolumePluginMgr{}
installPluginUnderTest(t, "kubernetes.io", "fakeAttacher", execScriptTempl1, nil)
plugMgr.InitPlugins(ProbeVolumePlugins(testPluginPath), volume.NewFakeVolumeHost("fake", nil, nil))
plugin, err := plugMgr.FindPluginByName("kubernetes.io/fakeAttacher")
if err != nil {
t.Errorf("Can't find the plugin by name")
}
if plugin.Name() != "kubernetes.io/fakeAttacher" {
t.Errorf("Wrong name: %s", plugin.Name())
}
if !plugin.CanSupport(&volume.Spec{Volume: &api.Volume{VolumeSource: api.VolumeSource{FlexVolume: &api.FlexVolumeSource{Driver: "kubernetes.io/fakeAttacher"}}}}) {
t.Errorf("Expected true")
}
if !plugin.CanSupport(&volume.Spec{PersistentVolume: &api.PersistentVolume{Spec: api.PersistentVolumeSpec{PersistentVolumeSource: api.PersistentVolumeSource{FlexVolume: &api.FlexVolumeSource{Driver: "kubernetes.io/fakeAttacher"}}}}}) {
t.Errorf("Expected true")
}
if plugin.CanSupport(&volume.Spec{Volume: &api.Volume{VolumeSource: api.VolumeSource{}}}) {
t.Errorf("Expected false")
}
}
func TestGetAccessModes(t *testing.T) {
plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(ProbeVolumePlugins(testPluginPath), volume.NewFakeVolumeHost("fake", nil, nil))
plugin, err := plugMgr.FindPersistentPluginByName("kubernetes.io/fakeAttacher")
if err != nil {
t.Errorf("Can't find the plugin by name")
}
if !contains(plugin.GetAccessModes(), api.ReadWriteOnce) || !contains(plugin.GetAccessModes(), api.ReadOnlyMany) {
t.Errorf("Expected two AccessModeTypes: %s and %s", api.ReadWriteOnce, api.ReadOnlyMany)
}
}
func contains(modes []api.PersistentVolumeAccessMode, mode api.PersistentVolumeAccessMode) bool {
for _, m := range modes {
if m == mode {
return true
}
}
return false
}
func doTestPluginAttachDetach(t *testing.T, spec *volume.Spec) {
plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(ProbeVolumePlugins(testPluginPath), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
plugin, err := plugMgr.FindPluginByName("kubernetes.io/fakeAttacher")
if err != nil {
t.Errorf("Can't find the plugin by name")
}
fake := &mount.FakeMounter{}
pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: types.UID("poduid")}}
builder, err := plugin.(*flexVolumePlugin).newBuilderInternal(spec, pod, &flexVolumeUtil{}, fake, exec.New(), "")
volumePath := builder.GetPath()
if err != nil {
t.Errorf("Failed to make a new Builder: %v", err)
}
if builder == nil {
t.Errorf("Got a nil Builder")
}
path := builder.GetPath()
if path != "/tmp/fake/pods/poduid/volumes/kubernetes.io~fakeAttacher/vol1" {
t.Errorf("Got unexpected path: %s", path)
}
if err := builder.SetUp(); err != nil {
t.Errorf("Expected success, got: %v", err)
}
if _, err := os.Stat(volumePath); err != nil {
if os.IsNotExist(err) {
t.Errorf("SetUp() failed, volume path not created: %s", volumePath)
} else {
t.Errorf("SetUp() failed: %v", err)
}
}
t.Logf("Setup successful")
if builder.(*flexVolumeBuilder).readOnly {
t.Errorf("The volume source should not be read-only and it is.")
}
if len(fake.Log) != 1 {
t.Errorf("Mount was not called exactly one time. It was called %d times.", len(fake.Log))
} else {
if fake.Log[0].Action != mount.FakeActionMount {
t.Errorf("Unexpected mounter action: %#v", fake.Log[0])
}
}
fake.ResetLog()
cleaner, err := plugin.(*flexVolumePlugin).newCleanerInternal("vol1", types.UID("poduid"), &flexVolumeUtil{}, fake, exec.New())
if err != nil {
t.Errorf("Failed to make a new Cleaner: %v", err)
}
if cleaner == nil {
t.Errorf("Got a nil Cleaner")
}
if err := cleaner.TearDown(); err != nil {
t.Errorf("Expected success, got: %v", err)
}
if _, err := os.Stat(volumePath); err == nil {
t.Errorf("TearDown() failed, volume path still exists: %s", volumePath)
} else if !os.IsNotExist(err) {
t.Errorf("SetUp() failed: %v", err)
}
if len(fake.Log) != 1 {
t.Errorf("Unmount was not called exactly one time. It was called %d times.", len(fake.Log))
} else {
if fake.Log[0].Action != mount.FakeActionUnmount {
t.Errorf("Unexpected mounter action: %#v", fake.Log[0])
}
}
fake.ResetLog()
}
func doTestPluginMountUnmount(t *testing.T, spec *volume.Spec) {
plugMgr := volume.VolumePluginMgr{}
installPluginUnderTest(t, "kubernetes.io", "fakeMounter", execScriptTempl2, nil)
plugMgr.InitPlugins(ProbeVolumePlugins(testPluginPath), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
plugin, err := plugMgr.FindPluginByName("kubernetes.io/fakeMounter")
if err != nil {
t.Errorf("Can't find the plugin by name")
}
fake := &mount.FakeMounter{}
pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: types.UID("poduid")}}
builder, err := plugin.(*flexVolumePlugin).newBuilderInternal(spec, pod, &flexVolumeUtil{}, fake, exec.New(), "")
volumePath := builder.GetPath()
if err != nil {
t.Errorf("Failed to make a new Builder: %v", err)
}
if builder == nil {
t.Errorf("Got a nil Builder")
}
path := builder.GetPath()
if path != "/tmp/fake/pods/poduid/volumes/kubernetes.io~fakeMounter/vol1" {
t.Errorf("Got unexpected path: %s", path)
}
if err := builder.SetUp(); err != nil {
t.Errorf("Expected success, got: %v", err)
}
if _, err := os.Stat(volumePath); err != nil {
if os.IsNotExist(err) {
t.Errorf("SetUp() failed, volume path not created: %s", volumePath)
} else {
t.Errorf("SetUp() failed: %v", err)
}
}
t.Logf("Setup successful")
if builder.(*flexVolumeBuilder).readOnly {
t.Errorf("The volume source should not be read-only and it is.")
}
cleaner, err := plugin.(*flexVolumePlugin).newCleanerInternal("vol1", types.UID("poduid"), &flexVolumeUtil{}, fake, exec.New())
if err != nil {
t.Errorf("Failed to make a new Cleaner: %v", err)
}
if cleaner == nil {
t.Errorf("Got a nil Cleaner")
}
if err := cleaner.TearDown(); err != nil {
t.Errorf("Expected success, got: %v", err)
}
if _, err := os.Stat(volumePath); err == nil {
t.Errorf("TearDown() failed, volume path still exists: %s", volumePath)
} else if !os.IsNotExist(err) {
t.Errorf("SetUp() failed: %v", err)
}
}
func TestPluginVolumeAttacher(t *testing.T) {
vol := &api.Volume{
Name: "vol1",
VolumeSource: api.VolumeSource{FlexVolume: &api.FlexVolumeSource{Driver: "kubernetes.io/fakeAttacher", ReadOnly: false}},
}
doTestPluginAttachDetach(t, volume.NewSpecFromVolume(vol))
}
func TestPluginVolumeMounter(t *testing.T) {
vol := &api.Volume{
Name: "vol1",
VolumeSource: api.VolumeSource{FlexVolume: &api.FlexVolumeSource{Driver: "kubernetes.io/fakeMounter", ReadOnly: false}},
}
doTestPluginMountUnmount(t, volume.NewSpecFromVolume(vol))
}
func TestPluginPersistentVolume(t *testing.T) {
vol := &api.PersistentVolume{
ObjectMeta: api.ObjectMeta{
Name: "vol1",
},
Spec: api.PersistentVolumeSpec{
PersistentVolumeSource: api.PersistentVolumeSource{
FlexVolume: &api.FlexVolumeSource{Driver: "kubernetes.io/fakeAttacher", ReadOnly: false},
},
},
}
doTestPluginAttachDetach(t, volume.NewSpecFromPersistentVolume(vol, false))
}

View File

@ -0,0 +1,221 @@
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package flexvolume
import (
"encoding/json"
"errors"
"fmt"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/util/exec"
)
const (
initCmd = "init"
attachCmd = "attach"
detachCmd = "detach"
mountCmd = "mount"
unmountCmd = "unmount"
optionFSType = "kubernetes.io/fsType"
optionReadWrite = "kubernetes.io/readwrite"
optionKeySecret = "kubernetes.io/secret"
)
const (
// StatusSuccess represents the successful completion of command.
StatusSuccess = "Success"
// StatusFailed represents that the command failed.
StatusFailure = "Failed"
// StatusNotSupported represents that the command is not supported.
StatusNotSupported = "Not supported"
)
// FlexVolumeDriverStatus represents the return value of the driver callout.
type FlexVolumeDriverStatus struct {
// Status of the callout. One of "Success" or "Failure".
Status string
// Message is the reason for failure.
Message string
// Device assigned by the driver.
Device string `json:"device"`
}
// flexVolumeUtil is the utility structure to setup and teardown devices from
// the host.
type flexVolumeUtil struct{}
// isCmdNotSupportedErr checks if the error corresponds to command not supported by
// driver.
func isCmdNotSupportedErr(err error) bool {
if err.Error() == StatusNotSupported {
return true
}
return false
}
// handleCmdResponse processes the command output and returns the appropriate
// error code or message.
func handleCmdResponse(cmd string, output []byte) (*FlexVolumeDriverStatus, error) {
var status FlexVolumeDriverStatus
if err := json.Unmarshal(output, &status); err != nil {
glog.Errorf("Failed to unmarshal output for command: %s, output: %s, error: %s", cmd, output, err.Error())
return nil, err
} else if status.Status == StatusNotSupported {
glog.V(5).Infof("%s command is not supported by the driver", cmd)
return nil, errors.New(status.Status)
} else if status.Status != StatusSuccess {
errMsg := fmt.Sprintf("%s command failed, status: %s, reason: %s", cmd, status.Status, status.Message)
glog.Errorf(errMsg)
return nil, fmt.Errorf("%s", errMsg)
}
return &status, nil
}
// init initializes the plugin.
func (u *flexVolumeUtil) init(plugin *flexVolumePlugin) error {
// call the init script
output, err := exec.New().Command(plugin.getExecutable(), initCmd).CombinedOutput()
if err != nil {
glog.Errorf("Failed to init driver: %s, error: %s", plugin.driverName, err.Error())
_, err := handleCmdResponse(initCmd, output)
return err
}
glog.V(5).Infof("Successfully initialized driver %s", plugin.driverName)
return nil
}
// Attach exposes a volume on the host.
func (u *flexVolumeUtil) attach(f *flexVolumeBuilder) (string, error) {
execPath := f.execPath
var options string
if f.options != nil {
out, err := json.Marshal(f.options)
if err != nil {
glog.Errorf("Failed to marshal plugin options, error: %s", err.Error())
return "", err
}
if len(out) != 0 {
options = string(out)
} else {
options = ""
}
}
cmd := f.runner.Command(execPath, attachCmd, options)
output, err := cmd.CombinedOutput()
if err != nil {
glog.Errorf("Failed to attach volume %s, output: %s, error: %s", f.volName, output, err.Error())
_, err := handleCmdResponse(attachCmd, output)
return "", err
}
status, err := handleCmdResponse(attachCmd, output)
if err != nil {
return "", err
}
glog.Infof("Successfully attached volume %s on device: %s", f.volName, status.Device)
return status.Device, nil
}
// Detach detaches a volume from the host.
func (u *flexVolumeUtil) detach(f *flexVolumeCleaner, mntDevice string) error {
execPath := f.execPath
// Executable provider command.
cmd := f.runner.Command(execPath, detachCmd, mntDevice)
output, err := cmd.CombinedOutput()
if err != nil {
glog.Errorf("Failed to detach volume %s, output: %s, error: %s", f.volName, output, err.Error())
_, err := handleCmdResponse(detachCmd, output)
return err
}
_, err = handleCmdResponse(detachCmd, output)
if err != nil {
return err
}
glog.Infof("Successfully detached volume %s on device: %s", f.volName, mntDevice)
return nil
}
// Mount mounts the volume on the host.
func (u *flexVolumeUtil) mount(f *flexVolumeBuilder, mntDevice, dir string) error {
execPath := f.execPath
var options string
if f.options != nil {
out, err := json.Marshal(f.options)
if err != nil {
glog.Errorf("Failed to marshal plugin options, error: %s", err.Error())
return err
}
if len(out) != 0 {
options = string(out)
} else {
options = ""
}
}
// Executable provider command.
cmd := f.runner.Command(execPath, mountCmd, dir, mntDevice, options)
output, err := cmd.CombinedOutput()
if err != nil {
glog.Errorf("Failed to mount volume %s, output: %s, error: %s", f.volName, output, err.Error())
_, err := handleCmdResponse(mountCmd, output)
return err
}
_, err = handleCmdResponse(mountCmd, output)
if err != nil {
return err
}
glog.Infof("Successfully mounted volume %s on dir: %s", f.volName, dir)
return nil
}
// Unmount unmounts the volume on the host.
func (u *flexVolumeUtil) unmount(f *flexVolumeCleaner, dir string) error {
execPath := f.execPath
// Executable provider command.
cmd := f.runner.Command(execPath, unmountCmd, dir)
output, err := cmd.CombinedOutput()
if err != nil {
glog.Errorf("Failed to unmount volume %s, output: %s, error: %s", f.volName, output, err.Error())
_, err := handleCmdResponse(unmountCmd, output)
return err
}
_, err = handleCmdResponse(unmountCmd, output)
if err != nil {
return err
}
glog.Infof("Successfully unmounted volume %s on dir: %s", f.volName, dir)
return nil
}

View File

@ -61,8 +61,9 @@ type flocker struct {
plugin *flockerPlugin plugin *flockerPlugin
} }
func (p *flockerPlugin) Init(host volume.VolumeHost) { func (p *flockerPlugin) Init(host volume.VolumeHost) error {
p.host = host p.host = host
return nil
} }
func (p flockerPlugin) Name() string { func (p flockerPlugin) Name() string {

View File

@ -50,8 +50,9 @@ const (
gcePersistentDiskPluginName = "kubernetes.io/gce-pd" gcePersistentDiskPluginName = "kubernetes.io/gce-pd"
) )
func (plugin *gcePersistentDiskPlugin) Init(host volume.VolumeHost) { func (plugin *gcePersistentDiskPlugin) Init(host volume.VolumeHost) error {
plugin.host = host plugin.host = host
return nil
} }
func (plugin *gcePersistentDiskPlugin) Name() string { func (plugin *gcePersistentDiskPlugin) Name() string {

View File

@ -45,8 +45,9 @@ const (
gitRepoPluginName = "kubernetes.io/git-repo" gitRepoPluginName = "kubernetes.io/git-repo"
) )
func (plugin *gitRepoPlugin) Init(host volume.VolumeHost) { func (plugin *gitRepoPlugin) Init(host volume.VolumeHost) error {
plugin.host = host plugin.host = host
return nil
} }
func (plugin *gitRepoPlugin) Name() string { func (plugin *gitRepoPlugin) Name() string {

View File

@ -47,8 +47,9 @@ const (
glusterfsPluginName = "kubernetes.io/glusterfs" glusterfsPluginName = "kubernetes.io/glusterfs"
) )
func (plugin *glusterfsPlugin) Init(host volume.VolumeHost) { func (plugin *glusterfsPlugin) Init(host volume.VolumeHost) error {
plugin.host = host plugin.host = host
return nil
} }
func (plugin *glusterfsPlugin) Name() string { func (plugin *glusterfsPlugin) Name() string {

View File

@ -73,8 +73,9 @@ const (
hostPathPluginName = "kubernetes.io/host-path" hostPathPluginName = "kubernetes.io/host-path"
) )
func (plugin *hostPathPlugin) Init(host volume.VolumeHost) { func (plugin *hostPathPlugin) Init(host volume.VolumeHost) error {
plugin.host = host plugin.host = host
return nil
} }
func (plugin *hostPathPlugin) Name() string { func (plugin *hostPathPlugin) Name() string {

View File

@ -46,8 +46,9 @@ const (
iscsiPluginName = "kubernetes.io/iscsi" iscsiPluginName = "kubernetes.io/iscsi"
) )
func (plugin *iscsiPlugin) Init(host volume.VolumeHost) { func (plugin *iscsiPlugin) Init(host volume.VolumeHost) error {
plugin.host = host plugin.host = host
return nil
} }
func (plugin *iscsiPlugin) Name() string { func (plugin *iscsiPlugin) Name() string {

View File

@ -58,8 +58,9 @@ const (
nfsPluginName = "kubernetes.io/nfs" nfsPluginName = "kubernetes.io/nfs"
) )
func (plugin *nfsPlugin) Init(host volume.VolumeHost) { func (plugin *nfsPlugin) Init(host volume.VolumeHost) error {
plugin.host = host plugin.host = host
return nil
} }
func (plugin *nfsPlugin) Name() string { func (plugin *nfsPlugin) Name() string {

View File

@ -40,8 +40,9 @@ const (
persistentClaimPluginName = "kubernetes.io/persistent-claim" persistentClaimPluginName = "kubernetes.io/persistent-claim"
) )
func (plugin *persistentClaimPlugin) Init(host volume.VolumeHost) { func (plugin *persistentClaimPlugin) Init(host volume.VolumeHost) error {
plugin.host = host plugin.host = host
return nil
} }
func (plugin *persistentClaimPlugin) Name() string { func (plugin *persistentClaimPlugin) Name() string {

View File

@ -59,7 +59,7 @@ type VolumePlugin interface {
// Init initializes the plugin. This will be called exactly once // Init initializes the plugin. This will be called exactly once
// before any New* calls are made - implementations of plugins may // before any New* calls are made - implementations of plugins may
// depend on this. // depend on this.
Init(host VolumeHost) Init(host VolumeHost) error
// Name returns the plugin's name. Plugins should use namespaced names // Name returns the plugin's name. Plugins should use namespaced names
// such as "example.com/volume". The "kubernetes.io" namespace is // such as "example.com/volume". The "kubernetes.io" namespace is
@ -263,7 +263,12 @@ func (pm *VolumePluginMgr) InitPlugins(plugins []VolumePlugin, host VolumeHost)
allErrs = append(allErrs, fmt.Errorf("volume plugin %q was registered more than once", name)) allErrs = append(allErrs, fmt.Errorf("volume plugin %q was registered more than once", name))
continue continue
} }
plugin.Init(host) err := plugin.Init(host)
if err != nil {
glog.Errorf("Failed to load volume plugin %s, error: %s", plugin, err.Error())
allErrs = append(allErrs, err)
continue
}
pm.plugins[name] = plugin pm.plugins[name] = plugin
glog.V(1).Infof("Loaded volume plugin %q", name) glog.V(1).Infof("Loaded volume plugin %q", name)
} }

View File

@ -45,8 +45,9 @@ const (
rbdPluginName = "kubernetes.io/rbd" rbdPluginName = "kubernetes.io/rbd"
) )
func (plugin *rbdPlugin) Init(host volume.VolumeHost) { func (plugin *rbdPlugin) Init(host volume.VolumeHost) error {
plugin.host = host plugin.host = host
return nil
} }
func (plugin *rbdPlugin) Name() string { func (plugin *rbdPlugin) Name() string {

View File

@ -47,8 +47,9 @@ type secretPlugin struct {
var _ volume.VolumePlugin = &secretPlugin{} var _ volume.VolumePlugin = &secretPlugin{}
func (plugin *secretPlugin) Init(host volume.VolumeHost) { func (plugin *secretPlugin) Init(host volume.VolumeHost) error {
plugin.host = host plugin.host = host
return nil
} }
func (plugin *secretPlugin) Name() string { func (plugin *secretPlugin) Name() string {

View File

@ -129,8 +129,9 @@ var _ RecyclableVolumePlugin = &FakeVolumePlugin{}
var _ DeletableVolumePlugin = &FakeVolumePlugin{} var _ DeletableVolumePlugin = &FakeVolumePlugin{}
var _ ProvisionableVolumePlugin = &FakeVolumePlugin{} var _ ProvisionableVolumePlugin = &FakeVolumePlugin{}
func (plugin *FakeVolumePlugin) Init(host VolumeHost) { func (plugin *FakeVolumePlugin) Init(host VolumeHost) error {
plugin.Host = host plugin.Host = host
return nil
} }
func (plugin *FakeVolumePlugin) Name() string { func (plugin *FakeVolumePlugin) Name() string {