SetUp now returns an error.

SetUp returns an error, kubelet now skips pod if error occurs.
This commit is contained in:
Danny Jones 2014-07-24 13:45:55 -07:00
parent 41eb15bcff
commit 1117da4a55
2 changed files with 22 additions and 13 deletions

View File

@ -223,7 +223,10 @@ func (kl *Kubelet) mountExternalVolumes(manifest *api.ContainerManifest) (volume
continue continue
} }
podVolumes[vol.Name] = extVolume podVolumes[vol.Name] = extVolume
extVolume.SetUp() err = extVolume.SetUp()
if err != nil {
return nil, err
}
} }
return podVolumes, nil return podVolumes, nil
} }
@ -319,7 +322,8 @@ func (kl *Kubelet) syncPod(pod *Pod, dockerContainers DockerContainers, keepChan
podVolumes, err := kl.mountExternalVolumes(&pod.Manifest) podVolumes, err := kl.mountExternalVolumes(&pod.Manifest)
if err != nil { if err != nil {
glog.Errorf("Unable to mount volumes for pod %s: (%v)", podFullName, err) glog.Errorf("Unable to mount volumes for pod %s: (%v) Skipping pod.", podFullName, err)
return err
} }
for _, container := range pod.Manifest.Containers { for _, container := range pod.Manifest.Containers {

View File

@ -22,7 +22,6 @@ import (
"path" "path"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/golang/glog"
) )
// All volume types are expected to implement this interface // All volume types are expected to implement this interface
@ -30,12 +29,12 @@ type Interface interface {
// Prepares and mounts/unpacks the volume to a directory path. // Prepares and mounts/unpacks the volume to a directory path.
// This procedure must be idempotent. // This procedure must be idempotent.
// TODO(jonesdl) SetUp should return an error if it fails. // TODO(jonesdl) SetUp should return an error if it fails.
SetUp() SetUp() error
// Returns the directory path the volume is mounted to. // Returns the directory path the volume is mounted to.
GetPath() string GetPath() string
// Unmounts the volume and removes traces of the SetUp procedure. // Unmounts the volume and removes traces of the SetUp procedure.
// This procedure must be idempotent. // This procedure must be idempotent.
TearDown() TearDown() error
} }
// Host Directory volumes represent a bare host directory mount. // Host Directory volumes represent a bare host directory mount.
@ -46,9 +45,13 @@ type HostDirectory struct {
// Host directory mounts require no setup or cleanup, but still // Host directory mounts require no setup or cleanup, but still
// need to fulfill the interface definitions. // need to fulfill the interface definitions.
func (hostVol *HostDirectory) SetUp() {} func (hostVol *HostDirectory) SetUp() error {
return nil
}
func (hostVol *HostDirectory) TearDown() {} func (hostVol *HostDirectory) TearDown() error {
return nil
}
func (hostVol *HostDirectory) GetPath() string { func (hostVol *HostDirectory) GetPath() string {
return hostVol.Path return hostVol.Path
@ -63,18 +66,20 @@ type EmptyDirectory struct {
} }
// SetUp creates the new directory. // SetUp creates the new directory.
func (emptyDir *EmptyDirectory) SetUp() { func (emptyDir *EmptyDirectory) SetUp() error {
path := emptyDir.GetPath() path := emptyDir.GetPath()
if _, err := os.Stat(path); os.IsNotExist(err) { err := os.MkdirAll(path, 0750)
os.MkdirAll(path, 0750) if err != nil {
} else { return err
glog.Warningf("Directory already exists: (%v)", path)
} }
return nil
} }
// TODO(jonesdl) when we can properly invoke TearDown(), we should delete // TODO(jonesdl) when we can properly invoke TearDown(), we should delete
// the directory created by SetUp. // the directory created by SetUp.
func (emptyDir *EmptyDirectory) TearDown() {} func (emptyDir *EmptyDirectory) TearDown() error {
return nil
}
func (emptyDir *EmptyDirectory) GetPath() string { func (emptyDir *EmptyDirectory) GetPath() string {
return path.Join(emptyDir.RootDir, emptyDir.PodID, "volumes", "empty", emptyDir.Name) return path.Join(emptyDir.RootDir, emptyDir.PodID, "volumes", "empty", emptyDir.Name)