Commit fa76de79 authored by Chakravarthy Nelluri's avatar Chakravarthy Nelluri

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

volumes and custom mounts.
parent 56f72aeb
...@@ -13884,6 +13884,10 @@ ...@@ -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 @@ ...@@ -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 @@ ...@@ -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"
......
...@@ -3429,6 +3429,10 @@ ...@@ -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 @@ ...@@ -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.",
......
...@@ -32,6 +32,7 @@ import ( ...@@ -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 ( ...@@ -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 { ...@@ -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
} }
......
...@@ -116,6 +116,7 @@ type KubeletServer struct { ...@@ -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 { ...@@ -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) { ...@@ -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) { ...@@ -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
......
...@@ -139,9 +139,10 @@ kubelet ...@@ -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 -->
......
...@@ -2971,6 +2971,68 @@ Populated by the system when a graceful deletion is requested. Read-only. More i ...@@ -2971,6 +2971,68 @@ Populated by the system when a graceful deletion is requested. Read-only. More i
</div> </div>
<div class="sect2"> <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 class="sect2">
<h3 id="_v1beta1_jobcondition">v1beta1.JobCondition</h3> <h3 id="_v1beta1_jobcondition">v1beta1.JobCondition</h3>
<div class="paragraph"> <div class="paragraph">
<p>JobCondition describes current state of a job.</p> <p>JobCondition describes current state of a job.</p>
...@@ -3277,6 +3339,13 @@ Populated by the system when a graceful deletion is requested. Read-only. More i ...@@ -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 ...@@ -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>
......
...@@ -66,6 +66,7 @@ Familiarity with [pods](pods.md) is suggested. ...@@ -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. ...@@ -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
......
<!-- 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 -->
#!/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
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"
...@@ -337,6 +337,7 @@ upgrade-target ...@@ -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
......
...@@ -573,6 +573,29 @@ func deepCopy_api_FCVolumeSource(in FCVolumeSource, out *FCVolumeSource, c *conv ...@@ -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 ...@@ -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 ...@@ -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() { ...@@ -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,
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -198,6 +198,10 @@ type VolumeSource struct { ...@@ -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 { ...@@ -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 { ...@@ -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.
......
...@@ -793,6 +793,36 @@ func convert_api_FCVolumeSource_To_v1_FCVolumeSource(in *api.FCVolumeSource, out ...@@ -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 ...@@ -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 * ...@@ -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 ...@@ -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 ...@@ -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. ...@@ -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() { ...@@ -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() { ...@@ -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,
......
...@@ -616,6 +616,29 @@ func deepCopy_v1_FCVolumeSource(in FCVolumeSource, out *FCVolumeSource, c *conve ...@@ -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 ...@@ -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. ...@@ -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() { ...@@ -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,
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -243,6 +243,10 @@ type VolumeSource struct { ...@@ -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 { ...@@ -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 { ...@@ -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.
......
...@@ -401,6 +401,19 @@ func (FCVolumeSource) SwaggerDoc() map[string]string { ...@@ -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{ ...@@ -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{ ...@@ -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",
......
...@@ -484,6 +484,10 @@ func validateVolumeSource(source *api.VolumeSource, fldPath *field.Path) field.E ...@@ -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 ...@@ -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 { ...@@ -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"))
} }
......
...@@ -508,12 +508,13 @@ func TestValidateVolumes(t *testing.T) { ...@@ -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{}}
......
...@@ -274,6 +274,29 @@ func deepCopy_api_FCVolumeSource(in api.FCVolumeSource, out *api.FCVolumeSource, ...@@ -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 ...@@ -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() { ...@@ -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,
......
...@@ -364,6 +364,36 @@ func convert_api_FCVolumeSource_To_v1_FCVolumeSource(in *api.FCVolumeSource, out ...@@ -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 * ...@@ -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 ...@@ -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 ...@@ -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() { ...@@ -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() { ...@@ -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,
......
...@@ -310,6 +310,29 @@ func deepCopy_v1_FCVolumeSource(in v1.FCVolumeSource, out *v1.FCVolumeSource, c ...@@ -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 ...@@ -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() { ...@@ -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,
......
...@@ -20,6 +20,19 @@ import ( ...@@ -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
......
...@@ -53,8 +53,9 @@ const ( ...@@ -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 {
......
...@@ -43,8 +43,9 @@ const ( ...@@ -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 {
......
...@@ -51,8 +51,9 @@ const ( ...@@ -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 {
......
...@@ -51,8 +51,9 @@ type downwardAPIPlugin struct { ...@@ -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 {
......
...@@ -54,8 +54,10 @@ const ( ...@@ -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 {
......
...@@ -46,8 +46,9 @@ const ( ...@@ -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 {
......
/*
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
}
...@@ -61,8 +61,9 @@ type flocker struct { ...@@ -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 {
......
...@@ -50,8 +50,9 @@ const ( ...@@ -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 {
......
...@@ -45,8 +45,9 @@ const ( ...@@ -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 {
......
...@@ -47,8 +47,9 @@ const ( ...@@ -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 {
......
...@@ -73,8 +73,9 @@ const ( ...@@ -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 {
......
...@@ -46,8 +46,9 @@ const ( ...@@ -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 {
......
...@@ -58,8 +58,9 @@ const ( ...@@ -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 {
......
...@@ -40,8 +40,9 @@ const ( ...@@ -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 {
......
...@@ -59,7 +59,7 @@ type VolumePlugin interface { ...@@ -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) ...@@ -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)
} }
......
...@@ -45,8 +45,9 @@ const ( ...@@ -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 {
......
...@@ -47,8 +47,9 @@ type secretPlugin struct { ...@@ -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 {
......
...@@ -129,8 +129,9 @@ var _ RecyclableVolumePlugin = &FakeVolumePlugin{} ...@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment