mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-08 20:50:24 +00:00
Read BoundPods from etcd instead of ContainerManifestList
There are three values that uniquely identify a pod on a host - the configuration source (etcd, file, http), the pod name, and the pod namespace. This change ensures that configuration properly makes those names unique by changing podFullName to contain both name (currently ID in v1beta1, Name in v1beta3) and namespace. The Kubelet does not properly handle information requests for pods not in the default namespace at this time.
This commit is contained in:
committed by
Eric Paris
parent
332a03b085
commit
892942af8f
@@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
@@ -32,7 +33,7 @@ const (
|
||||
)
|
||||
|
||||
type RunPodResult struct {
|
||||
Pod *Pod
|
||||
Pod *api.BoundPod
|
||||
Err error
|
||||
}
|
||||
|
||||
@@ -50,7 +51,7 @@ func (kl *Kubelet) RunOnce(updates <-chan PodUpdate) ([]RunPodResult, error) {
|
||||
}
|
||||
|
||||
// runOnce runs a given set of pods and returns their status.
|
||||
func (kl *Kubelet) runOnce(pods []Pod) (results []RunPodResult, err error) {
|
||||
func (kl *Kubelet) runOnce(pods []api.BoundPod) (results []RunPodResult, err error) {
|
||||
if kl.dockerPuller == nil {
|
||||
kl.dockerPuller = dockertools.NewDockerPuller(kl.dockerClient, kl.pullQPS, kl.pullBurst)
|
||||
}
|
||||
@@ -72,10 +73,10 @@ func (kl *Kubelet) runOnce(pods []Pod) (results []RunPodResult, err error) {
|
||||
results = append(results, res)
|
||||
if res.Err != nil {
|
||||
// TODO(proppy): report which containers failed the pod.
|
||||
glog.Infof("failed to start pod %q: %v", res.Pod.Name, res.Err)
|
||||
failedPods = append(failedPods, res.Pod.Name)
|
||||
glog.Infof("failed to start pod %q: %v", res.Pod.ID, res.Err)
|
||||
failedPods = append(failedPods, res.Pod.ID)
|
||||
} else {
|
||||
glog.Infof("started pod %q", res.Pod.Name)
|
||||
glog.Infof("started pod %q", res.Pod.ID)
|
||||
}
|
||||
}
|
||||
if len(failedPods) > 0 {
|
||||
@@ -86,7 +87,7 @@ func (kl *Kubelet) runOnce(pods []Pod) (results []RunPodResult, err error) {
|
||||
}
|
||||
|
||||
// runPod runs a single pod and wait until all containers are running.
|
||||
func (kl *Kubelet) runPod(pod Pod) error {
|
||||
func (kl *Kubelet) runPod(pod api.BoundPod) error {
|
||||
delay := RunOnceRetryDelay
|
||||
retry := 0
|
||||
for {
|
||||
@@ -95,18 +96,18 @@ func (kl *Kubelet) runPod(pod Pod) error {
|
||||
return fmt.Errorf("failed to get kubelet docker containers: %v", err)
|
||||
}
|
||||
if running := kl.isPodRunning(pod, dockerContainers); running {
|
||||
glog.Infof("pod %q containers running", pod.Name)
|
||||
glog.Infof("pod %q containers running", pod.ID)
|
||||
return nil
|
||||
}
|
||||
glog.Infof("pod %q containers not running: syncing", pod.Name)
|
||||
glog.Infof("pod %q containers not running: syncing", pod.ID)
|
||||
if err = kl.syncPod(&pod, dockerContainers); err != nil {
|
||||
return fmt.Errorf("error syncing pod: %v", err)
|
||||
}
|
||||
if retry >= RunOnceMaxRetries {
|
||||
return fmt.Errorf("timeout error: pod %q containers not running after %d retries", pod.Name, RunOnceMaxRetries)
|
||||
return fmt.Errorf("timeout error: pod %q containers not running after %d retries", pod.ID, RunOnceMaxRetries)
|
||||
}
|
||||
// TODO(proppy): health checking would be better than waiting + checking the state at the next iteration.
|
||||
glog.Infof("pod %q containers synced, waiting for %v", pod.Name, delay)
|
||||
glog.Infof("pod %q containers synced, waiting for %v", pod.ID, delay)
|
||||
<-time.After(delay)
|
||||
retry++
|
||||
delay *= RunOnceRetryDelayBackoff
|
||||
@@ -114,9 +115,9 @@ func (kl *Kubelet) runPod(pod Pod) error {
|
||||
}
|
||||
|
||||
// isPodRunning returns true if all containers of a manifest are running.
|
||||
func (kl *Kubelet) isPodRunning(pod Pod, dockerContainers dockertools.DockerContainers) bool {
|
||||
for _, container := range pod.Manifest.Containers {
|
||||
if dockerContainer, found, _ := dockerContainers.FindPodContainer(GetPodFullName(&pod), pod.Manifest.UUID, container.Name); !found || dockerContainer.Status != "running" {
|
||||
func (kl *Kubelet) isPodRunning(pod api.BoundPod, dockerContainers dockertools.DockerContainers) bool {
|
||||
for _, container := range pod.Spec.Containers {
|
||||
if dockerContainer, found, _ := dockerContainers.FindPodContainer(GetPodFullName(&pod), pod.UID, container.Name); !found || dockerContainer.Status != "running" {
|
||||
glog.Infof("container %q not found (%v) or not running: %#v", container.Name, found, dockerContainer)
|
||||
return false
|
||||
}
|
||||
|
Reference in New Issue
Block a user