// PortForward executes socat in the pod's network namespace and copies // data between stream (representing the user's local connection on their // computer) and the specified port in the container. // // TODO: // - match cgroups of container // - should we support nsenter + socat on the host? (current impl) // - should we support nsenter + socat in a container, running with elevated privs and --pid=host? func (dm *DockerManager) PortForward(pod *kubecontainer.Pod, port uint16, stream io.ReadWriteCloser) error { podInfraContainer := pod.FindContainerByName(PodInfraContainerName) if podInfraContainer == nil { return fmt.Errorf("cannot find pod infra container in pod %q", kubecontainer.BuildPodFullName(pod.Name, pod.Namespace)) } container, err := dm.client.InspectContainer(string(podInfraContainer.ID)) if err != nil { return err } if !container.State.Running { return fmt.Errorf("container not running (%s)", container) } containerPid := container.State.Pid // TODO what if the host doesn't have it??? _, lookupErr := exec.LookPath("socat") if lookupErr != nil { return fmt.Errorf("Unable to do port forwarding: socat not found.") } args := []string{"-t", fmt.Sprintf("%d", containerPid), "-n", "socat", "-", fmt.Sprintf("TCP4:localhost:%d", port)} // TODO use exec.LookPath command := exec.Command("nsenter", args...) command.Stdin = stream command.Stdout = stream return command.Run() }
// 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) { pods, err := r.GetPods(true) if err != nil { return nil, err } p := kubecontainer.Pods(pods).FindPodByID(pod.UID) if len(p.Containers) == 0 { return nil, fmt.Errorf("cannot find status for pod: %q", kubecontainer.BuildPodFullName(pod.Name, pod.Namespace)) } return &p.Status, nil }
// GetPodByName provides the (non-mirror) pod that matches namespace and name, // as well as whether the pod was found. func (pm *basicPodManager) GetPodByName(namespace, name string) (*api.Pod, bool) { podFullName := kubecontainer.BuildPodFullName(name, namespace) return pm.GetPodByFullName(podFullName) }