2014-11-23 15:47:25 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors.
|
2014-11-23 15:47:25 +00:00
|
|
|
|
|
|
|
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 gce_pd
|
|
|
|
|
|
|
|
import (
|
2015-12-14 14:50:13 +00:00
|
|
|
"fmt"
|
2014-11-23 15:47:25 +00:00
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"strconv"
|
|
|
|
|
2015-08-05 22:05:17 +00:00
|
|
|
"github.com/golang/glog"
|
2017-06-22 18:24:23 +00:00
|
|
|
"k8s.io/api/core/v1"
|
2017-01-25 13:13:07 +00:00
|
|
|
"k8s.io/apimachinery/pkg/api/resource"
|
2017-01-17 03:38:19 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2017-01-11 14:09:48 +00:00
|
|
|
"k8s.io/apimachinery/pkg/types"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/util/mount"
|
2017-02-01 14:23:10 +00:00
|
|
|
kstrings "k8s.io/kubernetes/pkg/util/strings"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/volume"
|
2016-12-20 00:40:55 +00:00
|
|
|
"k8s.io/kubernetes/pkg/volume/util"
|
2017-05-25 01:54:48 +00:00
|
|
|
"k8s.io/kubernetes/pkg/volume/util/volumehelper"
|
2014-11-23 15:47:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// This is the primary entrypoint for volume plugins.
|
2015-03-19 05:18:31 +00:00
|
|
|
func ProbeVolumePlugins() []volume.VolumePlugin {
|
2015-07-22 18:50:11 +00:00
|
|
|
return []volume.VolumePlugin{&gcePersistentDiskPlugin{nil}}
|
2014-11-23 15:47:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type gcePersistentDiskPlugin struct {
|
2015-07-22 18:50:11 +00:00
|
|
|
host volume.VolumeHost
|
2014-11-23 15:47:25 +00:00
|
|
|
}
|
|
|
|
|
2015-03-19 05:18:31 +00:00
|
|
|
var _ volume.VolumePlugin = &gcePersistentDiskPlugin{}
|
2015-06-26 20:37:11 +00:00
|
|
|
var _ volume.PersistentVolumePlugin = &gcePersistentDiskPlugin{}
|
2015-12-14 14:50:13 +00:00
|
|
|
var _ volume.DeletableVolumePlugin = &gcePersistentDiskPlugin{}
|
|
|
|
var _ volume.ProvisionableVolumePlugin = &gcePersistentDiskPlugin{}
|
2017-11-20 18:02:13 +00:00
|
|
|
var _ volume.ExpandableVolumePlugin = &gcePersistentDiskPlugin{}
|
2014-11-23 15:47:25 +00:00
|
|
|
|
|
|
|
const (
|
2015-07-22 18:50:11 +00:00
|
|
|
gcePersistentDiskPluginName = "kubernetes.io/gce-pd"
|
2014-11-23 15:47:25 +00:00
|
|
|
)
|
|
|
|
|
2016-05-19 01:13:04 +00:00
|
|
|
func getPath(uid types.UID, volName string, host volume.VolumeHost) string {
|
2017-02-01 14:23:10 +00:00
|
|
|
return host.GetPodVolumeDir(uid, kstrings.EscapeQualifiedNameForDisk(gcePersistentDiskPluginName), volName)
|
2016-05-19 01:13:04 +00:00
|
|
|
}
|
|
|
|
|
2015-09-30 18:31:53 +00:00
|
|
|
func (plugin *gcePersistentDiskPlugin) Init(host volume.VolumeHost) error {
|
2014-11-23 15:47:25 +00:00
|
|
|
plugin.host = host
|
2015-09-30 18:31:53 +00:00
|
|
|
return nil
|
2014-11-23 15:47:25 +00:00
|
|
|
}
|
|
|
|
|
2016-05-30 22:48:21 +00:00
|
|
|
func (plugin *gcePersistentDiskPlugin) GetPluginName() string {
|
2014-11-23 15:47:25 +00:00
|
|
|
return gcePersistentDiskPluginName
|
|
|
|
}
|
|
|
|
|
2016-05-30 22:48:21 +00:00
|
|
|
func (plugin *gcePersistentDiskPlugin) GetVolumeName(spec *volume.Spec) (string, error) {
|
2016-05-30 02:22:22 +00:00
|
|
|
volumeSource, _, err := getVolumeSource(spec)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
2016-05-30 22:48:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return volumeSource.PDName, nil
|
|
|
|
}
|
|
|
|
|
2015-04-14 16:29:33 +00:00
|
|
|
func (plugin *gcePersistentDiskPlugin) CanSupport(spec *volume.Spec) bool {
|
2015-08-12 19:11:03 +00:00
|
|
|
return (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.GCEPersistentDisk != nil) ||
|
|
|
|
(spec.Volume != nil && spec.Volume.GCEPersistentDisk != nil)
|
2014-11-23 15:47:25 +00:00
|
|
|
}
|
|
|
|
|
2016-05-30 02:22:22 +00:00
|
|
|
func (plugin *gcePersistentDiskPlugin) RequiresRemount() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-02-21 18:19:48 +00:00
|
|
|
func (plugin *gcePersistentDiskPlugin) SupportsMountOption() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2017-02-13 04:40:30 +00:00
|
|
|
func (plugin *gcePersistentDiskPlugin) SupportsBulkVolumeVerification() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2016-11-18 20:58:56 +00:00
|
|
|
func (plugin *gcePersistentDiskPlugin) GetAccessModes() []v1.PersistentVolumeAccessMode {
|
|
|
|
return []v1.PersistentVolumeAccessMode{
|
|
|
|
v1.ReadWriteOnce,
|
|
|
|
v1.ReadOnlyMany,
|
2015-03-12 19:37:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-18 20:58:56 +00:00
|
|
|
func (plugin *gcePersistentDiskPlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, _ volume.VolumeOptions) (volume.Mounter, error) {
|
2014-11-23 15:47:25 +00:00
|
|
|
// Inject real implementations here, test through the internal function.
|
2017-08-14 10:16:26 +00:00
|
|
|
return plugin.newMounterInternal(spec, pod.UID, &GCEDiskUtil{}, plugin.host.GetMounter(plugin.GetPluginName()))
|
2014-11-23 15:47:25 +00:00
|
|
|
}
|
|
|
|
|
2016-05-30 02:22:22 +00:00
|
|
|
func getVolumeSource(
|
2016-11-18 20:58:56 +00:00
|
|
|
spec *volume.Spec) (*v1.GCEPersistentDiskVolumeSource, bool, error) {
|
2015-08-12 19:11:03 +00:00
|
|
|
if spec.Volume != nil && spec.Volume.GCEPersistentDisk != nil {
|
2016-05-30 02:22:22 +00:00
|
|
|
return spec.Volume.GCEPersistentDisk, spec.Volume.GCEPersistentDisk.ReadOnly, nil
|
|
|
|
} else if spec.PersistentVolume != nil &&
|
|
|
|
spec.PersistentVolume.Spec.GCEPersistentDisk != nil {
|
|
|
|
return spec.PersistentVolume.Spec.GCEPersistentDisk, spec.ReadOnly, nil
|
2015-04-14 16:29:33 +00:00
|
|
|
}
|
2016-05-30 02:22:22 +00:00
|
|
|
|
|
|
|
return nil, false, fmt.Errorf("Spec does not reference a GCE volume type")
|
2016-02-19 21:27:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (plugin *gcePersistentDiskPlugin) newMounterInternal(spec *volume.Spec, podUID types.UID, manager pdManager, mounter mount.Interface) (volume.Mounter, error) {
|
|
|
|
// GCEPDs used directly in a pod have a ReadOnly flag set by the pod author.
|
|
|
|
// GCEPDs used as a PersistentVolume gets the ReadOnly flag indirectly through the persistent-claim volume used to mount the PV
|
2016-05-30 02:22:22 +00:00
|
|
|
volumeSource, readOnly, err := getVolumeSource(spec)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-02-19 21:27:41 +00:00
|
|
|
|
|
|
|
pdName := volumeSource.PDName
|
2014-11-23 15:47:25 +00:00
|
|
|
partition := ""
|
2016-02-19 21:27:41 +00:00
|
|
|
if volumeSource.Partition != 0 {
|
|
|
|
partition = strconv.Itoa(int(volumeSource.Partition))
|
2014-11-23 15:47:25 +00:00
|
|
|
}
|
|
|
|
|
2016-03-23 05:12:21 +00:00
|
|
|
return &gcePersistentDiskMounter{
|
2015-07-19 19:12:53 +00:00
|
|
|
gcePersistentDisk: &gcePersistentDisk{
|
2016-05-19 01:13:04 +00:00
|
|
|
podUID: podUID,
|
|
|
|
volName: spec.Name(),
|
|
|
|
pdName: pdName,
|
|
|
|
partition: partition,
|
|
|
|
mounter: mounter,
|
|
|
|
manager: manager,
|
|
|
|
plugin: plugin,
|
|
|
|
MetricsProvider: volume.NewMetricsStatFS(getPath(podUID, spec.Name(), plugin.host)),
|
2015-07-19 19:12:53 +00:00
|
|
|
},
|
2016-02-19 21:27:41 +00:00
|
|
|
readOnly: readOnly}, nil
|
2014-11-23 15:47:25 +00:00
|
|
|
}
|
|
|
|
|
2016-03-23 05:12:21 +00:00
|
|
|
func (plugin *gcePersistentDiskPlugin) NewUnmounter(volName string, podUID types.UID) (volume.Unmounter, error) {
|
2014-11-23 15:47:25 +00:00
|
|
|
// Inject real implementations here, test through the internal function.
|
2017-08-14 10:16:26 +00:00
|
|
|
return plugin.newUnmounterInternal(volName, podUID, &GCEDiskUtil{}, plugin.host.GetMounter(plugin.GetPluginName()))
|
2014-11-23 15:47:25 +00:00
|
|
|
}
|
|
|
|
|
2016-03-23 05:12:21 +00:00
|
|
|
func (plugin *gcePersistentDiskPlugin) newUnmounterInternal(volName string, podUID types.UID, manager pdManager, mounter mount.Interface) (volume.Unmounter, error) {
|
|
|
|
return &gcePersistentDiskUnmounter{&gcePersistentDisk{
|
2016-05-19 01:13:04 +00:00
|
|
|
podUID: podUID,
|
|
|
|
volName: volName,
|
|
|
|
manager: manager,
|
|
|
|
mounter: mounter,
|
|
|
|
plugin: plugin,
|
|
|
|
MetricsProvider: volume.NewMetricsStatFS(getPath(podUID, volName, plugin.host)),
|
2015-07-19 19:12:53 +00:00
|
|
|
}}, nil
|
2014-11-23 15:47:25 +00:00
|
|
|
}
|
|
|
|
|
2015-12-14 14:50:13 +00:00
|
|
|
func (plugin *gcePersistentDiskPlugin) NewDeleter(spec *volume.Spec) (volume.Deleter, error) {
|
|
|
|
return plugin.newDeleterInternal(spec, &GCEDiskUtil{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (plugin *gcePersistentDiskPlugin) newDeleterInternal(spec *volume.Spec, manager pdManager) (volume.Deleter, error) {
|
|
|
|
if spec.PersistentVolume != nil && spec.PersistentVolume.Spec.GCEPersistentDisk == nil {
|
|
|
|
return nil, fmt.Errorf("spec.PersistentVolumeSource.GCEPersistentDisk is nil")
|
|
|
|
}
|
|
|
|
return &gcePersistentDiskDeleter{
|
|
|
|
gcePersistentDisk: &gcePersistentDisk{
|
|
|
|
volName: spec.Name(),
|
|
|
|
pdName: spec.PersistentVolume.Spec.GCEPersistentDisk.PDName,
|
|
|
|
manager: manager,
|
|
|
|
plugin: plugin,
|
|
|
|
}}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (plugin *gcePersistentDiskPlugin) NewProvisioner(options volume.VolumeOptions) (volume.Provisioner, error) {
|
|
|
|
return plugin.newProvisionerInternal(options, &GCEDiskUtil{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (plugin *gcePersistentDiskPlugin) newProvisionerInternal(options volume.VolumeOptions, manager pdManager) (volume.Provisioner, error) {
|
|
|
|
return &gcePersistentDiskProvisioner{
|
|
|
|
gcePersistentDisk: &gcePersistentDisk{
|
|
|
|
manager: manager,
|
|
|
|
plugin: plugin,
|
|
|
|
},
|
|
|
|
options: options,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2017-11-20 18:02:13 +00:00
|
|
|
func (plugin *gcePersistentDiskPlugin) RequiresFSResize() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (plugin *gcePersistentDiskPlugin) ExpandVolumeDevice(
|
|
|
|
spec *volume.Spec,
|
|
|
|
newSize resource.Quantity,
|
|
|
|
oldSize resource.Quantity) (resource.Quantity, error) {
|
|
|
|
cloud, err := getCloudProvider(plugin.host.GetCloudProvider())
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return oldSize, err
|
|
|
|
}
|
|
|
|
pdName := spec.PersistentVolume.Spec.GCEPersistentDisk.PDName
|
|
|
|
updatedQuantity, err := cloud.ResizeDisk(pdName, oldSize, newSize)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return oldSize, err
|
|
|
|
}
|
|
|
|
return updatedQuantity, nil
|
|
|
|
}
|
|
|
|
|
2016-06-23 19:46:21 +00:00
|
|
|
func (plugin *gcePersistentDiskPlugin) ConstructVolumeSpec(volumeName, mountPath string) (*volume.Spec, error) {
|
2017-08-14 10:16:26 +00:00
|
|
|
mounter := plugin.host.GetMounter(plugin.GetPluginName())
|
2016-06-23 19:46:21 +00:00
|
|
|
pluginDir := plugin.host.GetPluginDir(plugin.GetPluginName())
|
|
|
|
sourceName, err := mounter.GetDeviceNameFromMount(mountPath, pluginDir)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-11-18 20:58:56 +00:00
|
|
|
gceVolume := &v1.Volume{
|
2016-06-23 19:46:21 +00:00
|
|
|
Name: volumeName,
|
2016-11-18 20:58:56 +00:00
|
|
|
VolumeSource: v1.VolumeSource{
|
|
|
|
GCEPersistentDisk: &v1.GCEPersistentDiskVolumeSource{
|
2016-06-23 19:46:21 +00:00
|
|
|
PDName: sourceName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return volume.NewSpecFromVolume(gceVolume), nil
|
|
|
|
}
|
|
|
|
|
2014-11-23 15:47:25 +00:00
|
|
|
// Abstract interface to PD operations.
|
|
|
|
type pdManager interface {
|
2015-12-14 14:50:13 +00:00
|
|
|
// Creates a volume
|
2017-02-01 14:23:10 +00:00
|
|
|
CreateVolume(provisioner *gcePersistentDiskProvisioner) (volumeID string, volumeSizeGB int, labels map[string]string, fstype string, err error)
|
2015-12-14 14:50:13 +00:00
|
|
|
// Deletes a volume
|
|
|
|
DeleteVolume(deleter *gcePersistentDiskDeleter) error
|
2014-11-23 15:47:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// gcePersistentDisk volumes are disk resources provided by Google Compute Engine
|
|
|
|
// that are attached to the kubelet's host machine and exposed to the pod.
|
|
|
|
type gcePersistentDisk struct {
|
|
|
|
volName string
|
|
|
|
podUID types.UID
|
|
|
|
// Unique identifier of the PD, used to find the disk resource in the provider.
|
|
|
|
pdName string
|
|
|
|
// Specifies the partition to mount
|
|
|
|
partition string
|
2016-02-19 21:27:41 +00:00
|
|
|
// Utility interface to provision and delete disks
|
2014-11-23 15:47:25 +00:00
|
|
|
manager pdManager
|
2015-02-06 20:41:21 +00:00
|
|
|
// Mounter interface that provides system calls to mount the global path to the pod local path.
|
|
|
|
mounter mount.Interface
|
2015-07-19 19:12:53 +00:00
|
|
|
plugin *gcePersistentDiskPlugin
|
2016-05-19 01:13:04 +00:00
|
|
|
volume.MetricsProvider
|
2014-11-23 15:47:25 +00:00
|
|
|
}
|
|
|
|
|
2016-03-23 05:12:21 +00:00
|
|
|
type gcePersistentDiskMounter struct {
|
2015-07-19 19:12:53 +00:00
|
|
|
*gcePersistentDisk
|
2016-02-19 21:27:41 +00:00
|
|
|
// Specifies whether the disk will be mounted as read-only.
|
2015-07-19 19:12:53 +00:00
|
|
|
readOnly bool
|
|
|
|
}
|
|
|
|
|
2016-03-23 05:12:21 +00:00
|
|
|
var _ volume.Mounter = &gcePersistentDiskMounter{}
|
2015-07-19 19:12:53 +00:00
|
|
|
|
2016-03-23 05:12:21 +00:00
|
|
|
func (b *gcePersistentDiskMounter) GetAttributes() volume.Attributes {
|
2015-10-30 20:25:36 +00:00
|
|
|
return volume.Attributes{
|
2016-01-11 16:10:55 +00:00
|
|
|
ReadOnly: b.readOnly,
|
|
|
|
Managed: !b.readOnly,
|
|
|
|
SupportsSELinux: true,
|
2015-10-30 20:25:36 +00:00
|
|
|
}
|
2015-10-20 18:49:39 +00:00
|
|
|
}
|
|
|
|
|
2016-11-03 19:15:52 +00:00
|
|
|
// Checks prior to mount operations to verify that the required components (binaries, etc.)
|
|
|
|
// to mount the volume are available on the underlying node.
|
|
|
|
// If not, it returns an error
|
|
|
|
func (b *gcePersistentDiskMounter) CanMount() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-02-19 21:27:41 +00:00
|
|
|
// SetUp bind mounts the disk global mount to the volume path.
|
2017-06-21 07:13:36 +00:00
|
|
|
func (b *gcePersistentDiskMounter) SetUp(fsGroup *int64) error {
|
2015-12-18 15:55:11 +00:00
|
|
|
return b.SetUpAt(b.GetPath(), fsGroup)
|
2015-03-07 21:38:50 +00:00
|
|
|
}
|
|
|
|
|
2016-02-19 21:27:41 +00:00
|
|
|
// SetUp bind mounts the disk global mount to the give volume path.
|
2017-06-21 07:13:36 +00:00
|
|
|
func (b *gcePersistentDiskMounter) SetUpAt(dir string, fsGroup *int64) error {
|
2014-11-23 15:47:25 +00:00
|
|
|
// TODO: handle failed mounts here.
|
2015-04-16 23:49:53 +00:00
|
|
|
notMnt, err := b.mounter.IsLikelyNotMountPoint(dir)
|
2016-09-27 23:12:57 +00:00
|
|
|
glog.V(4).Infof("GCE PersistentDisk set up: Dir (%s) PD name (%q) Mounted (%t) Error (%v), ReadOnly (%t)", dir, b.pdName, !notMnt, err, b.readOnly)
|
2014-11-23 15:47:25 +00:00
|
|
|
if err != nil && !os.IsNotExist(err) {
|
2016-04-22 15:59:36 +00:00
|
|
|
glog.Errorf("cannot validate mount point: %s %v", dir, err)
|
2014-11-23 15:47:25 +00:00
|
|
|
return err
|
|
|
|
}
|
2015-04-16 23:49:53 +00:00
|
|
|
if !notMnt {
|
2014-11-23 15:47:25 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-03-07 21:38:50 +00:00
|
|
|
if err := os.MkdirAll(dir, 0750); err != nil {
|
2016-04-22 15:59:36 +00:00
|
|
|
glog.Errorf("mkdir failed on disk %s (%v)", dir, err)
|
2014-11-23 15:47:25 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform a bind mount to the full path to allow duplicate mounts of the same PD.
|
2015-04-03 01:08:04 +00:00
|
|
|
options := []string{"bind"}
|
2015-07-19 19:12:53 +00:00
|
|
|
if b.readOnly {
|
2015-04-03 01:08:04 +00:00
|
|
|
options = append(options, "ro")
|
|
|
|
}
|
2016-02-19 21:27:41 +00:00
|
|
|
|
|
|
|
globalPDPath := makeGlobalPDName(b.plugin.host, b.pdName)
|
2016-04-22 15:59:36 +00:00
|
|
|
glog.V(4).Infof("attempting to mount %s", dir)
|
|
|
|
|
2015-07-19 19:12:53 +00:00
|
|
|
err = b.mounter.Mount(globalPDPath, dir, "", options)
|
2014-11-23 15:47:25 +00:00
|
|
|
if err != nil {
|
2015-04-16 23:49:53 +00:00
|
|
|
notMnt, mntErr := b.mounter.IsLikelyNotMountPoint(dir)
|
2015-01-30 02:10:13 +00:00
|
|
|
if mntErr != nil {
|
2015-04-16 23:49:53 +00:00
|
|
|
glog.Errorf("IsLikelyNotMountPoint check failed: %v", mntErr)
|
2015-01-30 02:10:13 +00:00
|
|
|
return err
|
|
|
|
}
|
2015-04-16 23:49:53 +00:00
|
|
|
if !notMnt {
|
2015-07-19 19:12:53 +00:00
|
|
|
if mntErr = b.mounter.Unmount(dir); mntErr != nil {
|
2015-01-30 02:10:13 +00:00
|
|
|
glog.Errorf("Failed to unmount: %v", mntErr)
|
|
|
|
return err
|
|
|
|
}
|
2015-04-16 23:49:53 +00:00
|
|
|
notMnt, mntErr := b.mounter.IsLikelyNotMountPoint(dir)
|
2015-01-30 02:10:13 +00:00
|
|
|
if mntErr != nil {
|
2015-04-16 23:49:53 +00:00
|
|
|
glog.Errorf("IsLikelyNotMountPoint check failed: %v", mntErr)
|
2015-01-30 02:10:13 +00:00
|
|
|
return err
|
|
|
|
}
|
2015-04-16 23:49:53 +00:00
|
|
|
if !notMnt {
|
2015-01-30 02:10:13 +00:00
|
|
|
// This is very odd, we don't expect it. We'll try again next sync loop.
|
2015-03-07 21:38:50 +00:00
|
|
|
glog.Errorf("%s is still mounted, despite call to unmount(). Will try again next sync loop.", dir)
|
2015-01-30 02:10:13 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2015-03-07 21:38:50 +00:00
|
|
|
os.Remove(dir)
|
2016-04-22 15:59:36 +00:00
|
|
|
glog.Errorf("Mount of disk %s failed: %v", dir, err)
|
2014-11-23 15:47:25 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-12-18 18:57:25 +00:00
|
|
|
if !b.readOnly {
|
|
|
|
volume.SetVolumeOwnership(b, fsGroup)
|
|
|
|
}
|
|
|
|
|
2016-04-22 15:59:36 +00:00
|
|
|
glog.V(4).Infof("Successfully mounted %s", dir)
|
2014-11-23 15:47:25 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-03-19 05:18:31 +00:00
|
|
|
func makeGlobalPDName(host volume.VolumeHost, devName string) string {
|
2016-11-15 19:54:50 +00:00
|
|
|
return path.Join(host.GetPluginDir(gcePersistentDiskPluginName), mount.MountsInGlobalPDPath, devName)
|
2014-11-23 15:47:25 +00:00
|
|
|
}
|
|
|
|
|
2016-05-19 01:13:04 +00:00
|
|
|
func (b *gcePersistentDiskMounter) GetPath() string {
|
|
|
|
return getPath(b.podUID, b.volName, b.plugin.host)
|
2014-11-23 15:47:25 +00:00
|
|
|
}
|
|
|
|
|
2016-03-23 05:12:21 +00:00
|
|
|
type gcePersistentDiskUnmounter struct {
|
2015-07-19 19:12:53 +00:00
|
|
|
*gcePersistentDisk
|
|
|
|
}
|
|
|
|
|
2016-03-23 05:12:21 +00:00
|
|
|
var _ volume.Unmounter = &gcePersistentDiskUnmounter{}
|
2015-07-19 19:12:53 +00:00
|
|
|
|
2016-05-19 01:13:04 +00:00
|
|
|
func (c *gcePersistentDiskUnmounter) GetPath() string {
|
|
|
|
return getPath(c.podUID, c.volName, c.plugin.host)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmounts the bind mount, and detaches the disk only if the PD
|
|
|
|
// resource was the last reference to that disk on the kubelet.
|
2016-03-23 05:12:21 +00:00
|
|
|
func (c *gcePersistentDiskUnmounter) TearDown() error {
|
2015-07-19 19:12:53 +00:00
|
|
|
return c.TearDownAt(c.GetPath())
|
2015-03-07 21:38:50 +00:00
|
|
|
}
|
|
|
|
|
2016-02-19 21:27:41 +00:00
|
|
|
// TearDownAt unmounts the bind mount
|
2016-03-23 05:12:21 +00:00
|
|
|
func (c *gcePersistentDiskUnmounter) TearDownAt(dir string) error {
|
2016-12-20 00:40:55 +00:00
|
|
|
return util.UnmountPath(dir, c.mounter)
|
2014-11-23 15:47:25 +00:00
|
|
|
}
|
2015-12-14 14:50:13 +00:00
|
|
|
|
|
|
|
type gcePersistentDiskDeleter struct {
|
|
|
|
*gcePersistentDisk
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ volume.Deleter = &gcePersistentDiskDeleter{}
|
|
|
|
|
|
|
|
func (d *gcePersistentDiskDeleter) GetPath() string {
|
2016-05-19 01:13:04 +00:00
|
|
|
return getPath(d.podUID, d.volName, d.plugin.host)
|
2015-12-14 14:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *gcePersistentDiskDeleter) Delete() error {
|
|
|
|
return d.manager.DeleteVolume(d)
|
|
|
|
}
|
|
|
|
|
|
|
|
type gcePersistentDiskProvisioner struct {
|
|
|
|
*gcePersistentDisk
|
|
|
|
options volume.VolumeOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ volume.Provisioner = &gcePersistentDiskProvisioner{}
|
|
|
|
|
2016-11-18 20:58:56 +00:00
|
|
|
func (c *gcePersistentDiskProvisioner) Provision() (*v1.PersistentVolume, error) {
|
2017-06-09 21:59:08 +00:00
|
|
|
if !volume.AccessModesContainedInAll(c.plugin.GetAccessModes(), c.options.PVC.Spec.AccessModes) {
|
|
|
|
return nil, fmt.Errorf("invalid AccessModes %v: only AccessModes %v are supported", c.options.PVC.Spec.AccessModes, c.plugin.GetAccessModes())
|
|
|
|
}
|
|
|
|
|
2017-02-01 14:23:10 +00:00
|
|
|
volumeID, sizeGB, labels, fstype, err := c.manager.CreateVolume(c)
|
2015-12-14 14:50:13 +00:00
|
|
|
if err != nil {
|
2016-05-17 12:55:24 +00:00
|
|
|
return nil, err
|
2015-12-14 14:50:13 +00:00
|
|
|
}
|
2016-03-05 23:11:17 +00:00
|
|
|
|
2017-02-01 14:23:10 +00:00
|
|
|
if fstype == "" {
|
|
|
|
fstype = "ext4"
|
|
|
|
}
|
|
|
|
|
2016-11-18 20:58:56 +00:00
|
|
|
pv := &v1.PersistentVolume{
|
2017-01-17 03:38:19 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2016-05-17 12:55:24 +00:00
|
|
|
Name: c.options.PVName,
|
|
|
|
Labels: map[string]string{},
|
2015-12-14 14:50:13 +00:00
|
|
|
Annotations: map[string]string{
|
2017-05-25 01:54:48 +00:00
|
|
|
volumehelper.VolumeDynamicallyCreatedByKey: "gce-pd-dynamic-provisioner",
|
2015-12-14 14:50:13 +00:00
|
|
|
},
|
|
|
|
},
|
2016-11-18 20:58:56 +00:00
|
|
|
Spec: v1.PersistentVolumeSpec{
|
2015-12-14 14:50:13 +00:00
|
|
|
PersistentVolumeReclaimPolicy: c.options.PersistentVolumeReclaimPolicy,
|
2016-10-12 10:22:01 +00:00
|
|
|
AccessModes: c.options.PVC.Spec.AccessModes,
|
2016-11-18 20:58:56 +00:00
|
|
|
Capacity: v1.ResourceList{
|
2017-11-30 01:28:13 +00:00
|
|
|
v1.ResourceName(v1.ResourceStorage): resource.MustParse(fmt.Sprintf("%dG", sizeGB)),
|
2015-12-14 14:50:13 +00:00
|
|
|
},
|
2016-11-18 20:58:56 +00:00
|
|
|
PersistentVolumeSource: v1.PersistentVolumeSource{
|
|
|
|
GCEPersistentDisk: &v1.GCEPersistentDiskVolumeSource{
|
2016-05-17 12:55:24 +00:00
|
|
|
PDName: volumeID,
|
2015-12-14 14:50:13 +00:00
|
|
|
Partition: 0,
|
|
|
|
ReadOnly: false,
|
2017-02-01 14:23:10 +00:00
|
|
|
FSType: fstype,
|
2015-12-14 14:50:13 +00:00
|
|
|
},
|
|
|
|
},
|
2017-08-23 21:29:54 +00:00
|
|
|
MountOptions: c.options.MountOptions,
|
2015-12-14 14:50:13 +00:00
|
|
|
},
|
2016-05-17 12:55:24 +00:00
|
|
|
}
|
2016-10-12 10:22:01 +00:00
|
|
|
if len(c.options.PVC.Spec.AccessModes) == 0 {
|
|
|
|
pv.Spec.AccessModes = c.plugin.GetAccessModes()
|
|
|
|
}
|
2016-05-17 12:55:24 +00:00
|
|
|
|
|
|
|
if len(labels) != 0 {
|
|
|
|
if pv.Labels == nil {
|
|
|
|
pv.Labels = make(map[string]string)
|
|
|
|
}
|
|
|
|
for k, v := range labels {
|
|
|
|
pv.Labels[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pv, nil
|
2015-12-14 14:50:13 +00:00
|
|
|
}
|