mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 15:58:37 +00:00
Adds EmptyDirectory volume struct
Adds EmptyDirectory to volumes. This represents a directory on the host, given to a pod that should not persist beyond. The current draft does not cleanup after itself.
This commit is contained in:
parent
f84ff740f0
commit
f1a7850454
@ -14,10 +14,12 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package volumes
|
package volume
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -32,33 +34,64 @@ type Interface interface {
|
|||||||
TearDown()
|
TearDown()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Host Directory Volumes represent a bare host directory mount.
|
// Host Directory volumes represent a bare host directory mount.
|
||||||
type HostDirectoryVolume struct {
|
// The directory in Path will be directly exposed to the container.
|
||||||
|
type HostDirectory struct {
|
||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simple 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 *HostDirectoryVolume) SetUp() {}
|
func (hostVol *HostDirectory) SetUp() {}
|
||||||
|
|
||||||
func (hostVol *HostDirectoryVolume) TearDown() {}
|
func (hostVol *HostDirectory) TearDown() {}
|
||||||
|
|
||||||
func (hostVol *HostDirectoryVolume) GetPath() string {
|
func (hostVol *HostDirectory) GetPath() string {
|
||||||
return hostVol.Path
|
return hostVol.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interprets API volume as a HostDirectory
|
// EmptyDirectory volumes are temporary directories exposed to the pod.
|
||||||
func createHostDirectoryVolume(volume *api.Volume) *HostDirectoryVolume {
|
// These do not persist beyond the lifetime of a pod.
|
||||||
return &HostDirectoryVolume{volume.HostDirectory.Path}
|
|
||||||
|
type EmptyDirectory struct {
|
||||||
|
Name string
|
||||||
|
PodID string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interprets parameters passed in the API as an internal structure
|
// SetUp creates the new directory.
|
||||||
// with utility procedures for mounting.
|
func (emptyDir *EmptyDirectory) SetUp() {
|
||||||
func CreateVolume(volume *api.Volume) (Interface, error) {
|
os.MkdirAll(emptyDir.GetPath(), 0750)
|
||||||
// TODO(jonesdl) We should probably not check every
|
}
|
||||||
// pointer and directly resolve these types instead.
|
|
||||||
if volume.HostDirectory != nil {
|
// TODO(jonesdl) when we can properly invoke TearDown(), we should delete
|
||||||
return createHostDirectoryVolume(volume), nil
|
// the directory created by SetUp.
|
||||||
|
func (emptyDir *EmptyDirectory) TearDown() {}
|
||||||
|
|
||||||
|
func (emptyDir *EmptyDirectory) GetPath() string {
|
||||||
|
// TODO(jonesdl) We will want to add a flag to designate a root
|
||||||
|
// directory for kubelet to write to. For now this will just be /exports
|
||||||
|
return fmt.Sprintf("/exports/%v/%v", emptyDir.PodID, emptyDir.Name)
|
||||||
|
}
|
||||||
|
// Interprets API volume as a HostDirectory
|
||||||
|
func createHostDirectory(volume *api.Volume) *HostDirectory {
|
||||||
|
return &HostDirectory{volume.Source.HostDirectory.Path}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interprets API volume as an EmptyDirectory
|
||||||
|
func createEmptyDirectory(volume *api.Volume, podID string) *EmptyDirectory {
|
||||||
|
return &EmptyDirectory{volume.Name, podID}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateVolume returns an Interface capable of mounting a volume described by an
|
||||||
|
// *api.Volume, or an error.
|
||||||
|
func CreateVolume(volume *api.Volume, podID string) (Interface, error) {
|
||||||
|
// TODO(jonesdl) We should probably not check every pointer and directly
|
||||||
|
// resolve these types instead.
|
||||||
|
source := volume.Source
|
||||||
|
if source.HostDirectory != nil {
|
||||||
|
return createHostDirectory(volume), nil
|
||||||
|
} else if source.EmptyDirectory != nil {
|
||||||
|
return createEmptyDirectory(volume, podID), nil
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New("Unsupported volume type.")
|
return nil, errors.New("Unsupported volume type.")
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
opyright 2014 Google Inc. All rights reserved.
|
/*
|
||||||
|
Copyright 2014 Google Inc. All rights reserved.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@ -13,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package volumes
|
package volume
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
Loading…
Reference in New Issue
Block a user