Skip to content

Commit

Permalink
SetUp now returns an error.
Browse files Browse the repository at this point in the history
SetUp returns an error, kubelet now skips pod if error occurs.
  • Loading branch information
Sarsate committed Jul 24, 2014
1 parent 41eb15b commit 1117da4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
8 changes: 6 additions & 2 deletions pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@ func (kl *Kubelet) mountExternalVolumes(manifest *api.ContainerManifest) (volume
continue
}
podVolumes[vol.Name] = extVolume
extVolume.SetUp()
err = extVolume.SetUp()
if err != nil {
return nil, err
}
}
return podVolumes, nil
}
Expand Down Expand Up @@ -319,7 +322,8 @@ func (kl *Kubelet) syncPod(pod *Pod, dockerContainers DockerContainers, keepChan

podVolumes, err := kl.mountExternalVolumes(&pod.Manifest)
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 {
Expand Down
27 changes: 16 additions & 11 deletions pkg/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,19 @@ import (
"path"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/golang/glog"
)

// All volume types are expected to implement this interface
type Interface interface {
// Prepares and mounts/unpacks the volume to a directory path.
// This procedure must be idempotent.
// TODO(jonesdl) SetUp should return an error if it fails.
SetUp()
SetUp() error
// Returns the directory path the volume is mounted to.
GetPath() string
// Unmounts the volume and removes traces of the SetUp procedure.
// This procedure must be idempotent.
TearDown()
TearDown() error
}

// Host Directory volumes represent a bare host directory mount.
Expand All @@ -46,9 +45,13 @@ type HostDirectory struct {

// Host directory mounts require no setup or cleanup, but still
// 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 {
return hostVol.Path
Expand All @@ -63,18 +66,20 @@ type EmptyDirectory struct {
}

// SetUp creates the new directory.
func (emptyDir *EmptyDirectory) SetUp() {
func (emptyDir *EmptyDirectory) SetUp() error {
path := emptyDir.GetPath()
if _, err := os.Stat(path); os.IsNotExist(err) {
os.MkdirAll(path, 0750)
} else {
glog.Warningf("Directory already exists: (%v)", path)
err := os.MkdirAll(path, 0750)
if err != nil {
return err
}
return nil
}

// TODO(jonesdl) when we can properly invoke TearDown(), we should delete
// the directory created by SetUp.
func (emptyDir *EmptyDirectory) TearDown() {}
func (emptyDir *EmptyDirectory) TearDown() error {
return nil
}

func (emptyDir *EmptyDirectory) GetPath() string {
return path.Join(emptyDir.RootDir, emptyDir.PodID, "volumes", "empty", emptyDir.Name)
Expand Down

0 comments on commit 1117da4

Please sign in to comment.