Skip to content

Commit

Permalink
kubelet/rkt: Add volumeGetter to rkt.
Browse files Browse the repository at this point in the history
This enable rkt to fetch the volume mounts by the kubelet.
  • Loading branch information
yifan-gu authored and Yifan Gu committed May 7, 2015
1 parent 8715c54 commit a8f86da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
29 changes: 20 additions & 9 deletions pkg/kubelet/rkt/rkt_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/securitycontext"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
appcschema "github.com/appc/spec/schema"
appctypes "github.com/appc/spec/schema/types"
"github.com/coreos/go-systemd/dbus"
Expand Down Expand Up @@ -102,18 +101,25 @@ type runtime struct {
recorder record.EventRecorder
prober prober.Prober
readinessManager *kubecontainer.ReadinessManager
volumeGetter volumeGetter
}

var _ kubecontainer.Runtime = &runtime{}

// TODO(yifan): Remove this when volumeManager is moved to separate package.
type volumeGetter interface {
GetVolumes(podUID types.UID) (kubecontainer.VolumeMap, bool)
}

// New creates the rkt container runtime which implements the container runtime interface.
// It will test if the rkt binary is in the $PATH, and whether we can get the
// version of it. If so, creates the rkt container runtime, otherwise returns an error.
func New(config *Config,
generator kubecontainer.RunContainerOptionsGenerator,
recorder record.EventRecorder,
containerRefManager *kubecontainer.RefManager,
readinessManager *kubecontainer.ReadinessManager) (kubecontainer.Runtime, error) {
readinessManager *kubecontainer.ReadinessManager,
volumeGetter volumeGetter) (kubecontainer.Runtime, error) {

systemdVersion, err := getSystemdVersion()
if err != nil {
Expand Down Expand Up @@ -353,7 +359,7 @@ func setApp(app *appctypes.App, c *api.Container) error {

// makePodManifest transforms a kubelet pod spec to the rkt pod manifest.
// TODO(yifan): Use the RunContainerOptions generated by GenerateRunContainerOptions().
func (r *runtime) makePodManifest(pod *api.Pod, volumeMap map[string]volume.Volume) (*appcschema.PodManifest, error) {
func (r *runtime) makePodManifest(pod *api.Pod) (*appcschema.PodManifest, error) {
manifest := appcschema.BlankPodManifest()

// Get the image manifests, assume they are already in the cas,
Expand Down Expand Up @@ -396,6 +402,11 @@ func (r *runtime) makePodManifest(pod *api.Pod, volumeMap map[string]volume.Volu
})
}

volumeMap, ok := r.volumeGetter.GetVolumes(pod.UID)
if !ok {
return nil, fmt.Errorf("cannot get the volumes for pod %q", kubecontainer.GetPodFullName(pod))
}

// Set global volumes.
for name, volume := range volumeMap {
volName, err := appctypes.NewACName(name)
Expand Down Expand Up @@ -486,11 +497,11 @@ func (r *runtime) apiPodToruntimePod(uuid string, pod *api.Pod) *kubecontainer.P
// On success, it will return a string that represents name of the unit file
// and a boolean that indicates if the unit file needs to be reloaded (whether
// the file is already existed).
func (r *runtime) preparePod(pod *api.Pod, volumeMap map[string]volume.Volume) (string, bool, error) {
func (r *runtime) preparePod(pod *api.Pod) (string, bool, error) {
cmds := []string{"prepare", "--quiet", "--pod-manifest"}

// Generate the pod manifest from the pod spec.
manifest, err := r.makePodManifest(pod, volumeMap)
manifest, err := r.makePodManifest(pod)
if err != nil {
return "", false, err
}
Expand Down Expand Up @@ -561,10 +572,10 @@ func (r *runtime) preparePod(pod *api.Pod, volumeMap map[string]volume.Volume) (

// RunPod first creates the unit file for a pod, and then calls
// StartUnit over d-bus.
func (r *runtime) RunPod(pod *api.Pod, volumeMap map[string]volume.Volume) error {
func (r *runtime) RunPod(pod *api.Pod) error {
glog.V(4).Infof("Rkt starts to run pod: name %q.", pod.Name)

name, needReload, err := r.preparePod(pod, volumeMap)
name, needReload, err := r.preparePod(pod)
if err != nil {
return err
}
Expand Down Expand Up @@ -812,7 +823,7 @@ func (r *runtime) SyncPod(pod *api.Pod, runningPod kubecontainer.Pod, podStatus
if len(runningPod.Containers) == 0 {
glog.V(4).Infof("Pod %q is not running, will start it", podFullName)
// TODO(yifan): Use RunContainerOptionsGeneratior to get volumeMaps, etc.
return r.RunPod(pod, nil)
return r.RunPod(pod)
}

// Add references to all containers.
Expand Down Expand Up @@ -869,7 +880,7 @@ func (r *runtime) SyncPod(pod *api.Pod, runningPod kubecontainer.Pod, podStatus
if err := r.KillPod(runningPod); err != nil {
return err
}
if err := r.RunPod(pod, nil); err != nil {
if err := r.RunPod(pod); err != nil {
return err
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/kubelet/rkt/rkt_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func New(config *Config,
generator kubecontainer.RunContainerOptionsGenerator,
recorder record.EventRecorder,
containerRefManager *kubecontainer.RefManager,
readinessManager *kubecontainer.ReadinessManager) (kubecontainer.Runtime, error) {
readinessManager *kubecontainer.ReadinessManager,
volumeGetter volumeGetter) (kubecontainer.Runtime, error) {
return nil, unsupportedError
}

Expand Down

0 comments on commit a8f86da

Please sign in to comment.