Merge pull request #1525 from erictune/rename_dir

Directory renamed to Dir to match json property
This commit is contained in:
Tim Hockin 2014-10-02 11:28:27 -07:00
commit 1dda3072a4
10 changed files with 76 additions and 76 deletions

View File

@ -12,24 +12,24 @@ A process in a Container sees a filesystem view composed from two sources: a sin
Kubernetes currently supports two types of Volumes, but more may be added in the future. Kubernetes currently supports two types of Volumes, but more may be added in the future.
### EmptyDirectory ### EmptyDir
An EmptyDirectory volume is created when a Pod is bound to a Node. It is initially empty, when the first Container command starts. Containers in the same pod can all read and write the same files in the EmptyDirectory. When a Pod is unbound, the data in the EmptyDirectory is deleted forever. An EmptyDir volume is created when a Pod is bound to a Node. It is initially empty, when the first Container command starts. Containers in the same pod can all read and write the same files in the EmptyDir. When a Pod is unbound, the data in the EmptyDir is deleted forever.
Some uses for an EmptyDirectory are: Some uses for an EmptyDir are:
- scratch space, such as for a disk-based mergesort or checkpointing a long computation. - scratch space, such as for a disk-based mergesort or checkpointing a long computation.
- a directory that a content-manager container fills with data while a webserver container serves the data. - a directory that a content-manager container fills with data while a webserver container serves the data.
Currently, the user cannot control what kind of media is used for an EmptyDirectory. If the Kubelet is configured to use a disk drive, then all EmptyDirectories will be created on that disk drive. In the future, it is expected that Pods can control whether the EmptyDirectory is on a disk drive, SSD, or tmpfs. Currently, the user cannot control what kind of media is used for an EmptyDir. If the Kubelet is configured to use a disk drive, then all EmptyDirectories will be created on that disk drive. In the future, it is expected that Pods can control whether the EmptyDir is on a disk drive, SSD, or tmpfs.
### HostDirectory ### HostDir
A Volume with a HostDirectory property allows access to files on the current node. A Volume with a HostDir property allows access to files on the current node.
Some uses for a HostDirectory are: Some uses for a HostDir are:
- running a container that needs access to Docker internals; use a HostDirectory of /var/lib/docker. - running a container that needs access to Docker internals; use a HostDir of /var/lib/docker.
- running cAdvisor in a container; use a HostDirectory of /dev/cgroups. - running cAdvisor in a container; use a HostDir of /dev/cgroups.
Watch out when using this type of volume, because: Watch out when using this type of volume, because:
- pods with identical configuration (such as created from a podTemplate) may behave differently on different nodes due to different files on different nodes. - pods with identical configuration (such as created from a podTemplate) may behave differently on different nodes due to different files on different nodes.
- When Kubernetes adds resource-aware scheduling, as is planned, it will not be able to account for resources used by a HostDirectory. - When Kubernetes adds resource-aware scheduling, as is planned, it will not be able to account for resources used by a HostDir.

View File

@ -85,22 +85,22 @@ type Volume struct {
type VolumeSource struct { type VolumeSource struct {
// Only one of the following sources may be specified // Only one of the following sources may be specified
// HostDirectory represents a pre-existing directory on the host machine that is directly // HostDir represents a pre-existing directory on the host machine that is directly
// exposed to the container. This is generally used for system agents or other privileged // exposed to the container. This is generally used for system agents or other privileged
// things that are allowed to see the host machine. Most containers will NOT need this. // things that are allowed to see the host machine. Most containers will NOT need this.
// TODO(jonesdl) We need to restrict who can use host directory mounts and // TODO(jonesdl) We need to restrict who can use host directory mounts and
// who can/can not mount host directories as read/write. // who can/can not mount host directories as read/write.
HostDirectory *HostDirectory `yaml:"hostDir" json:"hostDir"` HostDir *HostDir `yaml:"hostDir" json:"hostDir"`
// EmptyDirectory represents a temporary directory that shares a pod's lifetime. // EmptyDir represents a temporary directory that shares a pod's lifetime.
EmptyDirectory *EmptyDirectory `yaml:"emptyDir" json:"emptyDir"` EmptyDir *EmptyDir `yaml:"emptyDir" json:"emptyDir"`
} }
// HostDirectory represents bare host directory volume. // HostDir represents bare host directory volume.
type HostDirectory struct { type HostDir struct {
Path string `yaml:"path" json:"path"` Path string `yaml:"path" json:"path"`
} }
type EmptyDirectory struct{} type EmptyDir struct{}
// Protocol defines network protocols supported for things like conatiner ports. // Protocol defines network protocols supported for things like conatiner ports.
type Protocol string type Protocol string

View File

@ -83,22 +83,22 @@ type Volume struct {
type VolumeSource struct { type VolumeSource struct {
// Only one of the following sources may be specified // Only one of the following sources may be specified
// HostDirectory represents a pre-existing directory on the host machine that is directly // HostDir represents a pre-existing directory on the host machine that is directly
// exposed to the container. This is generally used for system agents or other privileged // exposed to the container. This is generally used for system agents or other privileged
// things that are allowed to see the host machine. Most containers will NOT need this. // things that are allowed to see the host machine. Most containers will NOT need this.
// TODO(jonesdl) We need to restrict who can use host directory mounts and // TODO(jonesdl) We need to restrict who can use host directory mounts and
// who can/can not mount host directories as read/write. // who can/can not mount host directories as read/write.
HostDirectory *HostDirectory `yaml:"hostDir" json:"hostDir"` HostDir *HostDir `yaml:"hostDir" json:"hostDir"`
// EmptyDirectory represents a temporary directory that shares a pod's lifetime. // EmptyDir represents a temporary directory that shares a pod's lifetime.
EmptyDirectory *EmptyDirectory `yaml:"emptyDir" json:"emptyDir"` EmptyDir *EmptyDir `yaml:"emptyDir" json:"emptyDir"`
} }
// HostDirectory represents bare host directory volume. // HostDir represents bare host directory volume.
type HostDirectory struct { type HostDir struct {
Path string `yaml:"path" json:"path"` Path string `yaml:"path" json:"path"`
} }
type EmptyDirectory struct{} type EmptyDir struct{}
// Protocol defines network protocols supported for things like conatiner ports. // Protocol defines network protocols supported for things like conatiner ports.
type Protocol string type Protocol string

View File

@ -83,22 +83,22 @@ type Volume struct {
type VolumeSource struct { type VolumeSource struct {
// Only one of the following sources may be specified // Only one of the following sources may be specified
// HostDirectory represents a pre-existing directory on the host machine that is directly // HostDir represents a pre-existing directory on the host machine that is directly
// exposed to the container. This is generally used for system agents or other privileged // exposed to the container. This is generally used for system agents or other privileged
// things that are allowed to see the host machine. Most containers will NOT need this. // things that are allowed to see the host machine. Most containers will NOT need this.
// TODO(jonesdl) We need to restrict who can use host directory mounts and // TODO(jonesdl) We need to restrict who can use host directory mounts and
// who can/can not mount host directories as read/write. // who can/can not mount host directories as read/write.
HostDirectory *HostDirectory `yaml:"hostDir" json:"hostDir"` HostDir *HostDir `yaml:"hostDir" json:"hostDir"`
// EmptyDirectory represents a temporary directory that shares a pod's lifetime. // EmptyDir represents a temporary directory that shares a pod's lifetime.
EmptyDirectory *EmptyDirectory `yaml:"emptyDir" json:"emptyDir"` EmptyDir *EmptyDir `yaml:"emptyDir" json:"emptyDir"`
} }
// HostDirectory represents bare host directory volume. // HostDir represents bare host directory volume.
type HostDirectory struct { type HostDir struct {
Path string `yaml:"path" json:"path"` Path string `yaml:"path" json:"path"`
} }
type EmptyDirectory struct{} type EmptyDir struct{}
// Protocol defines network protocols supported for things like conatiner ports. // Protocol defines network protocols supported for things like conatiner ports.
type Protocol string type Protocol string

View File

@ -126,22 +126,22 @@ type Volume struct {
type VolumeSource struct { type VolumeSource struct {
// Only one of the following sources may be specified // Only one of the following sources may be specified
// HostDirectory represents a pre-existing directory on the host machine that is directly // HostDir represents a pre-existing directory on the host machine that is directly
// exposed to the container. This is generally used for system agents or other privileged // exposed to the container. This is generally used for system agents or other privileged
// things that are allowed to see the host machine. Most containers will NOT need this. // things that are allowed to see the host machine. Most containers will NOT need this.
// TODO(jonesdl) We need to restrict who can use host directory mounts and who can/can not // TODO(jonesdl) We need to restrict who can use host directory mounts and who can/can not
// mount host directories as read/write. // mount host directories as read/write.
HostDirectory *HostDirectory `json:"hostDir" yaml:"hostDir"` HostDir *HostDir `json:"hostDir" yaml:"hostDir"`
// EmptyDirectory represents a temporary directory that shares a pod's lifetime. // EmptyDir represents a temporary directory that shares a pod's lifetime.
EmptyDirectory *EmptyDirectory `json:"emptyDir" yaml:"emptyDir"` EmptyDir *EmptyDir `json:"emptyDir" yaml:"emptyDir"`
} }
// HostDirectory represents bare host directory volume. // HostDir represents bare host directory volume.
type HostDirectory struct { type HostDir struct {
Path string `json:"path" yaml:"path"` Path string `json:"path" yaml:"path"`
} }
type EmptyDirectory struct{} type EmptyDir struct{}
// Protocol defines network protocols supported for things like conatiner ports. // Protocol defines network protocols supported for things like conatiner ports.
type Protocol string type Protocol string

View File

@ -56,11 +56,11 @@ func validateVolumes(volumes []api.Volume) (util.StringSet, errs.ErrorList) {
func validateSource(source *api.VolumeSource) errs.ErrorList { func validateSource(source *api.VolumeSource) errs.ErrorList {
numVolumes := 0 numVolumes := 0
allErrs := errs.ErrorList{} allErrs := errs.ErrorList{}
if source.HostDirectory != nil { if source.HostDir != nil {
numVolumes++ numVolumes++
allErrs = append(allErrs, validateHostDir(source.HostDirectory).Prefix("hostDirectory")...) allErrs = append(allErrs, validateHostDir(source.HostDir).Prefix("hostDirectory")...)
} }
if source.EmptyDirectory != nil { if source.EmptyDir != nil {
numVolumes++ numVolumes++
//EmptyDirs have nothing to validate //EmptyDirs have nothing to validate
} }
@ -70,7 +70,7 @@ func validateSource(source *api.VolumeSource) errs.ErrorList {
return allErrs return allErrs
} }
func validateHostDir(hostDir *api.HostDirectory) errs.ErrorList { func validateHostDir(hostDir *api.HostDir) errs.ErrorList {
allErrs := errs.ErrorList{} allErrs := errs.ErrorList{}
if hostDir.Path == "" { if hostDir.Path == "" {
allErrs = append(allErrs, errs.NewNotFound("path", hostDir.Path)) allErrs = append(allErrs, errs.NewNotFound("path", hostDir.Path))

View File

@ -37,9 +37,9 @@ func expectPrefix(t *testing.T, prefix string, errs errors.ErrorList) {
func TestValidateVolumes(t *testing.T) { func TestValidateVolumes(t *testing.T) {
successCase := []api.Volume{ successCase := []api.Volume{
{Name: "abc"}, {Name: "abc"},
{Name: "123", Source: &api.VolumeSource{HostDirectory: &api.HostDirectory{"/mnt/path2"}}}, {Name: "123", Source: &api.VolumeSource{HostDir: &api.HostDir{"/mnt/path2"}}},
{Name: "abc-123", Source: &api.VolumeSource{HostDirectory: &api.HostDirectory{"/mnt/path3"}}}, {Name: "abc-123", Source: &api.VolumeSource{HostDir: &api.HostDir{"/mnt/path3"}}},
{Name: "empty", Source: &api.VolumeSource{EmptyDirectory: &api.EmptyDirectory{}}}, {Name: "empty", Source: &api.VolumeSource{EmptyDir: &api.EmptyDir{}}},
} }
names, errs := validateVolumes(successCase) names, errs := validateVolumes(successCase)
if len(errs) != 0 { if len(errs) != 0 {
@ -309,8 +309,8 @@ func TestValidateManifest(t *testing.T) {
{ {
Version: "v1beta1", Version: "v1beta1",
ID: "abc", ID: "abc",
Volumes: []api.Volume{{Name: "vol1", Source: &api.VolumeSource{HostDirectory: &api.HostDirectory{"/mnt/vol1"}}}, Volumes: []api.Volume{{Name: "vol1", Source: &api.VolumeSource{HostDir: &api.HostDir{"/mnt/vol1"}}},
{Name: "vol2", Source: &api.VolumeSource{HostDirectory: &api.HostDirectory{"/mnt/vol2"}}}}, {Name: "vol2", Source: &api.VolumeSource{HostDir: &api.HostDir{"/mnt/vol2"}}}},
Containers: []api.Container{ Containers: []api.Container{
{ {
Name: "abc", Name: "abc",

View File

@ -581,14 +581,14 @@ func TestMountExternalVolumes(t *testing.T) {
{ {
Name: "host-dir", Name: "host-dir",
Source: &api.VolumeSource{ Source: &api.VolumeSource{
HostDirectory: &api.HostDirectory{"/dir/path"}, HostDir: &api.HostDir{"/dir/path"},
}, },
}, },
}, },
} }
podVolumes, _ := kubelet.mountExternalVolumes(&manifest) podVolumes, _ := kubelet.mountExternalVolumes(&manifest)
expectedPodVolumes := make(volumeMap) expectedPodVolumes := make(volumeMap)
expectedPodVolumes["host-dir"] = &volume.HostDirectory{"/dir/path"} expectedPodVolumes["host-dir"] = &volume.HostDir{"/dir/path"}
if len(expectedPodVolumes) != len(podVolumes) { if len(expectedPodVolumes) != len(podVolumes) {
t.Errorf("Unexpected volumes. Expected %#v got %#v. Manifest was: %#v", expectedPodVolumes, podVolumes, manifest) t.Errorf("Unexpected volumes. Expected %#v got %#v. Manifest was: %#v", expectedPodVolumes, podVolumes, manifest)
} }
@ -631,9 +631,9 @@ func TestMakeVolumesAndBinds(t *testing.T) {
} }
podVolumes := volumeMap{ podVolumes := volumeMap{
"disk": &volume.HostDirectory{"/mnt/disk"}, "disk": &volume.HostDir{"/mnt/disk"},
"disk4": &volume.HostDirectory{"/mnt/host"}, "disk4": &volume.HostDir{"/mnt/host"},
"disk5": &volume.EmptyDirectory{"disk5", "podID", "/var/lib/kubelet"}, "disk5": &volume.EmptyDir{"disk5", "podID", "/var/lib/kubelet"},
} }
binds := makeBinds(&pod, &container, podVolumes) binds := makeBinds(&pod, &container, podVolumes)

View File

@ -49,32 +49,32 @@ type Cleaner interface {
TearDown() error TearDown() error
} }
// HostDirectory volumes represent a bare host directory mount. // HostDir volumes represent a bare host directory mount.
// The directory in Path will be directly exposed to the container. // The directory in Path will be directly exposed to the container.
type HostDirectory struct { type HostDir struct {
Path string Path string
} }
// SetUp implements interface definitions, even though host directory // SetUp implements interface definitions, even though host directory
// mounts don't require any setup or cleanup. // mounts don't require any setup or cleanup.
func (hostVol *HostDirectory) SetUp() error { func (hostVol *HostDir) SetUp() error {
return nil return nil
} }
func (hostVol *HostDirectory) GetPath() string { func (hostVol *HostDir) GetPath() string {
return hostVol.Path return hostVol.Path
} }
// EmptyDirectory volumes are temporary directories exposed to the pod. // EmptyDir volumes are temporary directories exposed to the pod.
// These do not persist beyond the lifetime of a pod. // These do not persist beyond the lifetime of a pod.
type EmptyDirectory struct { type EmptyDir struct {
Name string Name string
PodID string PodID string
RootDir string RootDir string
} }
// SetUp creates new directory. // SetUp creates new directory.
func (emptyDir *EmptyDirectory) SetUp() error { func (emptyDir *EmptyDir) SetUp() error {
path := emptyDir.GetPath() path := emptyDir.GetPath()
err := os.MkdirAll(path, 0750) err := os.MkdirAll(path, 0750)
if err != nil { if err != nil {
@ -83,11 +83,11 @@ func (emptyDir *EmptyDirectory) SetUp() error {
return nil return nil
} }
func (emptyDir *EmptyDirectory) GetPath() string { func (emptyDir *EmptyDir) GetPath() string {
return path.Join(emptyDir.RootDir, emptyDir.PodID, "volumes", "empty", emptyDir.Name) return path.Join(emptyDir.RootDir, emptyDir.PodID, "volumes", "empty", emptyDir.Name)
} }
func (emptyDir *EmptyDirectory) renameDirectory() (string, error) { func (emptyDir *EmptyDir) renameDirectory() (string, error) {
oldPath := emptyDir.GetPath() oldPath := emptyDir.GetPath()
newPath, err := ioutil.TempDir(path.Dir(oldPath), emptyDir.Name+".deleting~") newPath, err := ioutil.TempDir(path.Dir(oldPath), emptyDir.Name+".deleting~")
if err != nil { if err != nil {
@ -101,7 +101,7 @@ func (emptyDir *EmptyDirectory) renameDirectory() (string, error) {
} }
// TearDown simply deletes everything in the directory. // TearDown simply deletes everything in the directory.
func (emptyDir *EmptyDirectory) TearDown() error { func (emptyDir *EmptyDir) TearDown() error {
tmpDir, err := emptyDir.renameDirectory() tmpDir, err := emptyDir.renameDirectory()
if err != nil { if err != nil {
return err return err
@ -113,14 +113,14 @@ func (emptyDir *EmptyDirectory) TearDown() error {
return nil return nil
} }
// createHostDirectory interprets API volume as a HostDirectory. // createHostDir interprets API volume as a HostDir.
func createHostDirectory(volume *api.Volume) *HostDirectory { func createHostDir(volume *api.Volume) *HostDir {
return &HostDirectory{volume.Source.HostDirectory.Path} return &HostDir{volume.Source.HostDir.Path}
} }
// createEmptyDirectory interprets API volume as an EmptyDirectory. // createEmptyDir interprets API volume as an EmptyDir.
func createEmptyDirectory(volume *api.Volume, podID string, rootDir string) *EmptyDirectory { func createEmptyDir(volume *api.Volume, podID string, rootDir string) *EmptyDir {
return &EmptyDirectory{volume.Name, podID, rootDir} return &EmptyDir{volume.Name, podID, rootDir}
} }
// CreateVolumeBuilder returns a Builder capable of mounting a volume described by an // CreateVolumeBuilder returns a Builder capable of mounting a volume described by an
@ -135,10 +135,10 @@ func CreateVolumeBuilder(volume *api.Volume, podID string, rootDir string) (Buil
var vol Builder var vol Builder
// TODO(jonesdl) We should probably not check every pointer and directly // TODO(jonesdl) We should probably not check every pointer and directly
// resolve these types instead. // resolve these types instead.
if source.HostDirectory != nil { if source.HostDir != nil {
vol = createHostDirectory(volume) vol = createHostDir(volume)
} else if source.EmptyDirectory != nil { } else if source.EmptyDir != nil {
vol = createEmptyDirectory(volume, podID, rootDir) vol = createEmptyDir(volume, podID, rootDir)
} else { } else {
return nil, ErrUnsupportedVolumeType return nil, ErrUnsupportedVolumeType
} }
@ -149,7 +149,7 @@ func CreateVolumeBuilder(volume *api.Volume, podID string, rootDir string) (Buil
func CreateVolumeCleaner(kind string, name string, podID string, rootDir string) (Cleaner, error) { func CreateVolumeCleaner(kind string, name string, podID string, rootDir string) (Cleaner, error) {
switch kind { switch kind {
case "empty": case "empty":
return &EmptyDirectory{name, podID, rootDir}, nil return &EmptyDir{name, podID, rootDir}, nil
default: default:
return nil, ErrUnsupportedVolumeType return nil, ErrUnsupportedVolumeType
} }

View File

@ -41,7 +41,7 @@ func TestCreateVolumeBuilders(t *testing.T) {
api.Volume{ api.Volume{
Name: "host-dir", Name: "host-dir",
Source: &api.VolumeSource{ Source: &api.VolumeSource{
HostDirectory: &api.HostDirectory{"/dir/path"}, HostDir: &api.HostDir{"/dir/path"},
}, },
}, },
"/dir/path", "/dir/path",
@ -52,7 +52,7 @@ func TestCreateVolumeBuilders(t *testing.T) {
api.Volume{ api.Volume{
Name: "empty-dir", Name: "empty-dir",
Source: &api.VolumeSource{ Source: &api.VolumeSource{
EmptyDirectory: &api.EmptyDirectory{}, EmptyDir: &api.EmptyDir{},
}, },
}, },
path.Join(tempDir, "/my-id/volumes/empty/empty-dir"), path.Join(tempDir, "/my-id/volumes/empty/empty-dir"),
@ -79,7 +79,7 @@ func TestCreateVolumeBuilders(t *testing.T) {
} }
continue continue
} }
if tt.volume.Source.HostDirectory == nil && tt.volume.Source.EmptyDirectory == nil { if tt.volume.Source.HostDir == nil && tt.volume.Source.EmptyDir == nil {
if err != ErrUnsupportedVolumeType { if err != ErrUnsupportedVolumeType {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
} }