From d84aac649891755ea5408c4aacb73ecd4f9f593e Mon Sep 17 00:00:00 2001 From: Victor Marmol Date: Mon, 4 May 2015 17:28:02 -0700 Subject: [PATCH] rkt: Unexport runtime, use Runtime interface --- pkg/kubelet/rkt/gc.go | 4 +-- pkg/kubelet/rkt/rkt_linux.go | 66 ++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/pkg/kubelet/rkt/gc.go b/pkg/kubelet/rkt/gc.go index 758c9b3db03..ff3bfda959a 100644 --- a/pkg/kubelet/rkt/gc.go +++ b/pkg/kubelet/rkt/gc.go @@ -18,10 +18,10 @@ package rkt // ImageManager manages and garbage collects the container images for rkt. type ImageManager struct { - runtime *Runtime + runtime *runtime } -func NewImageManager(r *Runtime) *ImageManager { +func NewImageManager(r *runtime) *ImageManager { return &ImageManager{runtime: r} } diff --git a/pkg/kubelet/rkt/rkt_linux.go b/pkg/kubelet/rkt/rkt_linux.go index cca2e2a6bfb..1bd919f65ac 100644 --- a/pkg/kubelet/rkt/rkt_linux.go +++ b/pkg/kubelet/rkt/rkt_linux.go @@ -84,10 +84,10 @@ const ( defaultExpirePrepared = "1m" ) -// Runtime implements the ContainerRuntime for rkt. The implementation +// runtime implements the Containerruntime for rkt. The implementation // uses systemd, so in order to run this runtime, systemd must be installed // on the machine. -type Runtime struct { +type runtime struct { generator kubecontainer.RunContainerOptionsGenerator readinessManager *kubecontainer.ReadinessManager prober prober.Prober @@ -99,12 +99,12 @@ type Runtime struct { dockerKeyring credentialprovider.DockerKeyring } -var _ kubecontainer.Runtime = &Runtime{} +var _ kubecontainer.Runtime = &runtime{} // 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) (*Runtime, error) { +func New(config *Config) (kubecontainer.Runtime, error) { systemdVersion, err := getSystemdVersion() if err != nil { return nil, err @@ -128,7 +128,7 @@ func New(config *Config) (*Runtime, error) { return nil, fmt.Errorf("cannot find rkt binary: %v", err) } - rkt := &Runtime{ + rkt := &runtime{ systemd: systemd, rktBinAbsPath: rktBinAbsPath, config: config, @@ -150,7 +150,7 @@ func New(config *Config) (*Runtime, error) { return rkt, nil } -func (r *Runtime) buildCommand(args ...string) *exec.Cmd { +func (r *runtime) buildCommand(args ...string) *exec.Cmd { cmd := exec.Command(rktBinName) cmd.Args = append(cmd.Args, r.config.buildGlobalOptions()...) cmd.Args = append(cmd.Args, args...) @@ -159,7 +159,7 @@ func (r *Runtime) buildCommand(args ...string) *exec.Cmd { // runCommand invokes rkt binary with arguments and returns the result // from stdout in a list of strings. -func (r *Runtime) runCommand(args ...string) ([]string, error) { +func (r *runtime) runCommand(args ...string) ([]string, error) { glog.V(4).Info("rkt: Run command:", args) output, err := r.buildCommand(args...).Output() @@ -329,7 +329,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, volumeMap map[string]volume.Volume) (*appcschema.PodManifest, error) { manifest := appcschema.BlankPodManifest() // Get the image manifests, assume they are already in the cas, @@ -403,7 +403,7 @@ func (r *Runtime) makePodManifest(pod *api.Pod, volumeMap map[string]volume.Volu } // TODO(yifan): Replace with 'rkt images'. -func (r *Runtime) getImageID(imageName string) (string, error) { +func (r *runtime) getImageID(imageName string) (string, error) { output, err := r.runCommand("fetch", imageName) if err != nil { return "", err @@ -431,7 +431,7 @@ func hashContainer(container *api.Container) uint64 { } // TODO(yifan): Remove the receiver once we can solve the appName->imageID problem. -func (r *Runtime) apiPodToRuntimePod(uuid string, pod *api.Pod) *kubecontainer.Pod { +func (r *runtime) apiPodToruntimePod(uuid string, pod *api.Pod) *kubecontainer.Pod { p := &kubecontainer.Pod{ ID: pod.UID, Name: pod.Name, @@ -462,7 +462,7 @@ 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, volumeMap map[string]volume.Volume) (string, bool, error) { cmds := []string{"prepare", "--quiet", "--pod-manifest"} // Generate the pod manifest from the pod spec. @@ -502,7 +502,7 @@ func (r *Runtime) preparePod(pod *api.Pod, volumeMap map[string]volume.Volume) ( uuid := output[0] glog.V(4).Infof("'rkt prepare' returns %q.", uuid) - p := r.apiPodToRuntimePod(uuid, pod) + p := r.apiPodToruntimePod(uuid, pod) b, err := json.Marshal(p) if err != nil { return "", false, err @@ -537,7 +537,7 @@ 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, volumeMap map[string]volume.Volume) error { glog.V(4).Infof("Rkt starts to run pod: name %q.", pod.Name) name, needReload, err := r.preparePod(pod, volumeMap) @@ -561,10 +561,10 @@ func (r *Runtime) RunPod(pod *api.Pod, volumeMap map[string]volume.Volume) error return nil } -// makeRuntimePod constructs the container runtime pod. It will: +// makeruntimePod constructs the container runtime pod. It will: // 1, Construct the pod by the information stored in the unit file. // 2, Construct the pod status from pod info. -func (r *Runtime) makeRuntimePod(unitName string, podInfos map[string]*podInfo) (*kubecontainer.Pod, error) { +func (r *runtime) makeruntimePod(unitName string, podInfos map[string]*podInfo) (*kubecontainer.Pod, error) { f, err := os.Open(path.Join(systemdServiceDir, unitName)) if err != nil { return nil, err @@ -610,7 +610,7 @@ func (r *Runtime) makeRuntimePod(unitName string, podInfos map[string]*podInfo) // Then it will use the result to contruct a list of container runtime pods. // If all is false, then only running pods will be returned, otherwise all pods will be // returned. -func (r *Runtime) GetPods(all bool) ([]*kubecontainer.Pod, error) { +func (r *runtime) GetPods(all bool) ([]*kubecontainer.Pod, error) { glog.V(4).Infof("Rkt getting pods") units, err := r.systemd.ListUnits() @@ -631,7 +631,7 @@ func (r *Runtime) GetPods(all bool) ([]*kubecontainer.Pod, error) { if !all && u.SubState != "running" { continue } - pod, err := r.makeRuntimePod(u.Name, podInfos) + pod, err := r.makeruntimePod(u.Name, podInfos) if err != nil { glog.Warningf("rkt: Cannot construct pod from unit file: %v.", err) continue @@ -643,7 +643,7 @@ func (r *Runtime) GetPods(all bool) ([]*kubecontainer.Pod, error) { } // KillPod invokes 'systemctl kill' to kill the unit that runs the pod. -func (r *Runtime) KillPod(pod kubecontainer.Pod) error { +func (r *runtime) KillPod(pod kubecontainer.Pod) error { glog.V(4).Infof("Rkt is killing pod: name %q.", pod.Name) // TODO(yifan): More graceful stop. Replace with StopUnit and wait for a timeout. @@ -653,7 +653,7 @@ func (r *Runtime) KillPod(pod kubecontainer.Pod) error { // GetPodStatus currently invokes GetPods() to return the status. // TODO(yifan): Split the get status logic from GetPods(). -func (r *Runtime) GetPodStatus(pod *api.Pod) (*api.PodStatus, error) { +func (r *runtime) GetPodStatus(pod *api.Pod) (*api.PodStatus, error) { pods, err := r.GetPods(true) if err != nil { return nil, err @@ -672,7 +672,7 @@ func (r *Runtime) GetPodStatus(pod *api.Pod) (*api.PodStatus, error) { // Example: // rkt:0.3.2+git --> []int{0, 3, 2}. // -func (r *Runtime) Version() (kubecontainer.Version, error) { +func (r *runtime) Version() (kubecontainer.Version, error) { output, err := r.runCommand("version") if err != nil { return nil, err @@ -696,7 +696,7 @@ func (r *Runtime) Version() (kubecontainer.Version, error) { // writeDockerAuthConfig writes the docker credentials to rkt auth config files. // This enables rkt to pull docker images from docker registry with credentials. -func (r *Runtime) writeDockerAuthConfig(image string, creds docker.AuthConfiguration) error { +func (r *runtime) writeDockerAuthConfig(image string, creds docker.AuthConfiguration) error { registry := "index.docker.io" // Image spec: [/]/[: