mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
kubelet/rkt: Add volumeGetter to rkt.
This enable rkt to fetch the volume mounts by the kubelet.
This commit is contained in:
parent
8715c54bd3
commit
a8f86da35b
@ -42,7 +42,6 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/securitycontext"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/securitycontext"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
|
|
||||||
appcschema "github.com/appc/spec/schema"
|
appcschema "github.com/appc/spec/schema"
|
||||||
appctypes "github.com/appc/spec/schema/types"
|
appctypes "github.com/appc/spec/schema/types"
|
||||||
"github.com/coreos/go-systemd/dbus"
|
"github.com/coreos/go-systemd/dbus"
|
||||||
@ -102,10 +101,16 @@ type runtime struct {
|
|||||||
recorder record.EventRecorder
|
recorder record.EventRecorder
|
||||||
prober prober.Prober
|
prober prober.Prober
|
||||||
readinessManager *kubecontainer.ReadinessManager
|
readinessManager *kubecontainer.ReadinessManager
|
||||||
|
volumeGetter volumeGetter
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ kubecontainer.Runtime = &runtime{}
|
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.
|
// 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
|
// 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.
|
// version of it. If so, creates the rkt container runtime, otherwise returns an error.
|
||||||
@ -113,7 +118,8 @@ func New(config *Config,
|
|||||||
generator kubecontainer.RunContainerOptionsGenerator,
|
generator kubecontainer.RunContainerOptionsGenerator,
|
||||||
recorder record.EventRecorder,
|
recorder record.EventRecorder,
|
||||||
containerRefManager *kubecontainer.RefManager,
|
containerRefManager *kubecontainer.RefManager,
|
||||||
readinessManager *kubecontainer.ReadinessManager) (kubecontainer.Runtime, error) {
|
readinessManager *kubecontainer.ReadinessManager,
|
||||||
|
volumeGetter volumeGetter) (kubecontainer.Runtime, error) {
|
||||||
|
|
||||||
systemdVersion, err := getSystemdVersion()
|
systemdVersion, err := getSystemdVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -353,7 +359,7 @@ func setApp(app *appctypes.App, c *api.Container) error {
|
|||||||
|
|
||||||
// makePodManifest transforms a kubelet pod spec to the rkt pod manifest.
|
// makePodManifest transforms a kubelet pod spec to the rkt pod manifest.
|
||||||
// TODO(yifan): Use the RunContainerOptions generated by GenerateRunContainerOptions().
|
// 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()
|
manifest := appcschema.BlankPodManifest()
|
||||||
|
|
||||||
// Get the image manifests, assume they are already in the cas,
|
// Get the image manifests, assume they are already in the cas,
|
||||||
@ -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.
|
// Set global volumes.
|
||||||
for name, volume := range volumeMap {
|
for name, volume := range volumeMap {
|
||||||
volName, err := appctypes.NewACName(name)
|
volName, err := appctypes.NewACName(name)
|
||||||
@ -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
|
// 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
|
// and a boolean that indicates if the unit file needs to be reloaded (whether
|
||||||
// the file is already existed).
|
// 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"}
|
cmds := []string{"prepare", "--quiet", "--pod-manifest"}
|
||||||
|
|
||||||
// Generate the pod manifest from the pod spec.
|
// Generate the pod manifest from the pod spec.
|
||||||
manifest, err := r.makePodManifest(pod, volumeMap)
|
manifest, err := r.makePodManifest(pod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", false, err
|
return "", false, err
|
||||||
}
|
}
|
||||||
@ -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
|
// RunPod first creates the unit file for a pod, and then calls
|
||||||
// StartUnit over d-bus.
|
// 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)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -812,7 +823,7 @@ func (r *runtime) SyncPod(pod *api.Pod, runningPod kubecontainer.Pod, podStatus
|
|||||||
if len(runningPod.Containers) == 0 {
|
if len(runningPod.Containers) == 0 {
|
||||||
glog.V(4).Infof("Pod %q is not running, will start it", podFullName)
|
glog.V(4).Infof("Pod %q is not running, will start it", podFullName)
|
||||||
// TODO(yifan): Use RunContainerOptionsGeneratior to get volumeMaps, etc.
|
// TODO(yifan): Use RunContainerOptionsGeneratior to get volumeMaps, etc.
|
||||||
return r.RunPod(pod, nil)
|
return r.RunPod(pod)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add references to all containers.
|
// Add references to all containers.
|
||||||
@ -869,7 +880,7 @@ func (r *runtime) SyncPod(pod *api.Pod, runningPod kubecontainer.Pod, podStatus
|
|||||||
if err := r.KillPod(runningPod); err != nil {
|
if err := r.KillPod(runningPod); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := r.RunPod(pod, nil); err != nil {
|
if err := r.RunPod(pod); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,8 @@ func New(config *Config,
|
|||||||
generator kubecontainer.RunContainerOptionsGenerator,
|
generator kubecontainer.RunContainerOptionsGenerator,
|
||||||
recorder record.EventRecorder,
|
recorder record.EventRecorder,
|
||||||
containerRefManager *kubecontainer.RefManager,
|
containerRefManager *kubecontainer.RefManager,
|
||||||
readinessManager *kubecontainer.ReadinessManager) (kubecontainer.Runtime, error) {
|
readinessManager *kubecontainer.ReadinessManager,
|
||||||
|
volumeGetter volumeGetter) (kubecontainer.Runtime, error) {
|
||||||
return nil, unsupportedError
|
return nil, unsupportedError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user