Merge pull request #36686 from rkouj/check-gluster-fs-binaries

Automatic merge from submit-queue

Implement CanMount() for gfsMounter for linux

**What this PR does / why we need it**:
To implement CanMount() check for glusterfs. If mount binaries are not present on the underlying node, the mount will not proceed and return an error message stating so.

Related to issue : https://github.com/kubernetes/kubernetes/issues/36098


Related to similar change for NFS : 
https://github.com/kubernetes/kubernetes/pull/36280

**Release note**:
`Check binaries for GlusterFS on the underlying node before doing mount`





Sample output from testing in GCE/GCI:

rkouj@rkouj0:~/go/src/k8s.io/kubernetes$ kubectl describe pods
Name:		glusterfs
Namespace:	default
Node:		e2e-test-rkouj-minion-group-kjq3/10.240.0.3
Start Time:	Fri, 11 Nov 2016 17:22:04 -0800
Labels:		<none>
Status:		Pending
IP:		
Controllers:	<none>
Containers:
  glusterfs:
    Container ID:	
    Image:		gcr.io/google_containers/busybox
    Image ID:		
    Port:		
    QoS Tier:
      cpu:	Burstable
      memory:	BestEffort
    Requests:
      cpu:		100m
    State:		Waiting
      Reason:		ContainerCreating
    Ready:		False
    Restart Count:	0
    Environment Variables:
Conditions:
  Type		Status
  Initialized 	True 
  Ready 	False 
  PodScheduled 	True 
Volumes:
  glusterfs:
    Type:		Glusterfs (a Glusterfs mount on the host that shares a pod's lifetime)
    EndpointsName:	glusterfs-cluster
    Path:		kube_vol
    ReadOnly:		true
  default-token-2zcao:
    Type:	Secret (a volume populated by a Secret)
    SecretName:	default-token-2zcao
Events:
  FirstSeen	LastSeen	Count	From						SubobjectPath	Type		Reason		Message
  ---------	--------	-----	----						-------------	--------	------		-------
  8s		8s		1	{default-scheduler }						Normal		Scheduled	Successfully assigned glusterfs to e2e-test-rkouj-minion-group-kjq3
  7s		4s		4	{kubelet e2e-test-rkouj-minion-group-kjq3}			Warning		FailedMount	Unable to mount volume kubernetes.io/glusterfs/6bb04587-a876-11e6-a712-42010af00002-glusterfs (spec.Name: glusterfs) on pod glusterfs (UID: 6bb04587-a876-11e6-a712-42010af00002). Verify that your node machine has the required components before attempting to mount this volume type. Required binary /sbin/mount.glusterfs is missing
This commit is contained in:
Kubernetes Submit Queue 2016-11-14 15:40:45 -08:00 committed by GitHub
commit 9be1191aba

View File

@ -35,6 +35,7 @@ import (
"k8s.io/kubernetes/pkg/util/strings"
"k8s.io/kubernetes/pkg/volume"
volutil "k8s.io/kubernetes/pkg/volume/util"
"runtime"
)
// This is the primary entrypoint for volume plugins.
@ -55,17 +56,18 @@ var _ volume.Provisioner = &glusterfsVolumeProvisioner{}
var _ volume.Deleter = &glusterfsVolumeDeleter{}
const (
glusterfsPluginName = "kubernetes.io/glusterfs"
volPrefix = "vol_"
dynamicEpSvcPrefix = "glusterfs-dynamic-"
replicaCount = 3
durabilityType = "replicate"
secretKeyName = "key" // key name used in secret
annGlusterURL = "glusterfs.kubernetes.io/url"
annGlusterSecretName = "glusterfs.kubernetes.io/secretname"
annGlusterSecretNamespace = "glusterfs.kubernetes.io/secretnamespace"
annGlusterUserKey = "glusterfs.kubernetes.io/userkey"
annGlusterUser = "glusterfs.kubernetes.io/userid"
glusterfsPluginName = "kubernetes.io/glusterfs"
volPrefix = "vol_"
dynamicEpSvcPrefix = "glusterfs-dynamic-"
replicaCount = 3
durabilityType = "replicate"
secretKeyName = "key" // key name used in secret
annGlusterURL = "glusterfs.kubernetes.io/url"
annGlusterSecretName = "glusterfs.kubernetes.io/secretname"
annGlusterSecretNamespace = "glusterfs.kubernetes.io/secretnamespace"
annGlusterUserKey = "glusterfs.kubernetes.io/userkey"
annGlusterUser = "glusterfs.kubernetes.io/userid"
gciGlusterMountBinariesPath = "/sbin/mount.glusterfs"
)
func (plugin *glusterfsPlugin) Init(host volume.VolumeHost) error {
@ -211,6 +213,13 @@ func (b *glusterfsMounter) GetAttributes() volume.Attributes {
// to mount the volume are available on the underlying node.
// If not, it returns an error
func (b *glusterfsMounter) CanMount() error {
exe := exec.New()
switch runtime.GOOS {
case "linux":
if _, err := exe.Command("/bin/ls", gciGlusterMountBinariesPath).CombinedOutput(); err != nil {
return fmt.Errorf("Required binary %s is missing", gciGlusterMountBinariesPath)
}
}
return nil
}