Merge pull request #5631 from dchen1107/podstatus

Remove PodIP from ContainerStatus
pull/6/head
Victor Marmol 2015-03-19 11:03:10 -07:00
commit 84ee72d4a7
8 changed files with 59 additions and 64 deletions

View File

@ -457,9 +457,6 @@ type ContainerStatus struct {
// Note that this is calculated from dead containers. But those containers are subject to // Note that this is calculated from dead containers. But those containers are subject to
// garbage collection. This value will get capped at 5 by GC. // garbage collection. This value will get capped at 5 by GC.
RestartCount int `json:"restartCount"` RestartCount int `json:"restartCount"`
// TODO(dchen1107): Deprecated this soon once we pull entire PodStatus from node,
// not just PodInfo. Now we need this to remove docker.Container from API
PodIP string `json:"podIP,omitempty"`
// TODO(dchen1107): Need to decide how to represent this in v1beta3 // TODO(dchen1107): Need to decide how to represent this in v1beta3
Image string `json:"image"` Image string `json:"image"`
ImageID string `json:"imageID" description:"ID of the container's image"` ImageID string `json:"imageID" description:"ID of the container's image"`

View File

@ -437,9 +437,6 @@ type ContainerStatus struct {
// Note that this is calculated from dead containers. But those containers are subject to // Note that this is calculated from dead containers. But those containers are subject to
// garbage collection. This value will get capped at 5 by GC. // garbage collection. This value will get capped at 5 by GC.
RestartCount int `json:"restartCount" description:"the number of times the container has been restarted, currently based on the number of dead containers that have not yet been removed"` RestartCount int `json:"restartCount" description:"the number of times the container has been restarted, currently based on the number of dead containers that have not yet been removed"`
// TODO(dchen1107): Deprecated this soon once we pull entire PodStatus from node,
// not just PodInfo. Now we need this to remove docker.Container from API
PodIP string `json:"podIP,omitempty" description:"pod's IP address"`
// TODO(dchen1107): Need to decide how to reprensent this in v1beta3 // TODO(dchen1107): Need to decide how to reprensent this in v1beta3
Image string `json:"image" description:"image of the container"` Image string `json:"image" description:"image of the container"`
ImageID string `json:"imageID" description:"ID of the container's image"` ImageID string `json:"imageID" description:"ID of the container's image"`

View File

@ -434,9 +434,6 @@ type ContainerStatus struct {
// Note that this is calculated from dead containers. But those containers are subject to // Note that this is calculated from dead containers. But those containers are subject to
// garbage collection. This value will get capped at 5 by GC. // garbage collection. This value will get capped at 5 by GC.
RestartCount int `json:"restartCount" description:"the number of times the container has been restarted, currently based on the number of dead containers that have not yet been removed"` RestartCount int `json:"restartCount" description:"the number of times the container has been restarted, currently based on the number of dead containers that have not yet been removed"`
// TODO(dchen1107): Deprecated this soon once we pull entire PodStatus from node,
// not just PodInfo. Now we need this to remove docker.Container from API
PodIP string `json:"podIP,omitempty" description:"pod's IP address"`
// TODO(dchen1107): Need to decide how to reprensent this in v1beta3 // TODO(dchen1107): Need to decide how to reprensent this in v1beta3
Image string `json:"image" description:"image of the container"` Image string `json:"image" description:"image of the container"`
ImageID string `json:"imageID" description:"ID of the container's image"` ImageID string `json:"imageID" description:"ID of the container's image"`

View File

@ -468,9 +468,6 @@ type ContainerStatus struct {
// Note that this is calculated from dead containers. But those containers are subject to // Note that this is calculated from dead containers. But those containers are subject to
// garbage collection. This value will get capped at 5 by GC. // garbage collection. This value will get capped at 5 by GC.
RestartCount int `json:"restartCount" description:"the number of times the container has been restarted, currently based on the number of dead containers that have not yet been removed"` RestartCount int `json:"restartCount" description:"the number of times the container has been restarted, currently based on the number of dead containers that have not yet been removed"`
// The IP of the Pod
// PodIP is deprecated and will be removed from v1beta3 once it becomes possible for the Kubelet to report PodStatus.
PodIP string `json:"podIP,omitempty" description:"pod's IP address"`
// TODO(dchen1107): Which image the container is running with? // TODO(dchen1107): Which image the container is running with?
// The image the container is running // The image the container is running
Image string `json:"image" description:"image of the container"` Image string `json:"image" description:"image of the container"`

View File

@ -528,19 +528,29 @@ var (
ErrContainerCannotRun = errors.New("Container cannot run") ErrContainerCannotRun = errors.New("Container cannot run")
) )
func inspectContainer(client DockerInterface, dockerID, containerName, tPath string) (*api.ContainerStatus, error) { // Internal information kept for containers from inspection
type containerStatusResult struct {
status api.ContainerStatus
ip string
err error
}
func inspectContainer(client DockerInterface, dockerID, containerName, tPath string) *containerStatusResult {
result := containerStatusResult{api.ContainerStatus{}, "", nil}
inspectResult, err := client.InspectContainer(dockerID) inspectResult, err := client.InspectContainer(dockerID)
if err != nil { if err != nil {
return nil, err result.err = err
return &result
} }
if inspectResult == nil { if inspectResult == nil {
// Why did we not get an error? // Why did we not get an error?
return &api.ContainerStatus{}, nil return &result
} }
glog.V(3).Infof("Container inspect result: %+v", *inspectResult) glog.V(3).Infof("Container inspect result: %+v", *inspectResult)
containerStatus := api.ContainerStatus{ result.status = api.ContainerStatus{
Image: inspectResult.Config.Image, Image: inspectResult.Config.Image,
ImageID: DockerPrefix + inspectResult.Image, ImageID: DockerPrefix + inspectResult.Image,
ContainerID: DockerPrefix + dockerID, ContainerID: DockerPrefix + dockerID,
@ -548,11 +558,11 @@ func inspectContainer(client DockerInterface, dockerID, containerName, tPath str
waiting := true waiting := true
if inspectResult.State.Running { if inspectResult.State.Running {
containerStatus.State.Running = &api.ContainerStateRunning{ result.status.State.Running = &api.ContainerStateRunning{
StartedAt: util.NewTime(inspectResult.State.StartedAt), StartedAt: util.NewTime(inspectResult.State.StartedAt),
} }
if containerName == PodInfraContainerName && inspectResult.NetworkSettings != nil { if containerName == PodInfraContainerName && inspectResult.NetworkSettings != nil {
containerStatus.PodIP = inspectResult.NetworkSettings.IPAddress result.ip = inspectResult.NetworkSettings.IPAddress
} }
waiting = false waiting = false
} else if !inspectResult.State.FinishedAt.IsZero() { } else if !inspectResult.State.FinishedAt.IsZero() {
@ -565,7 +575,7 @@ func inspectContainer(client DockerInterface, dockerID, containerName, tPath str
} else { } else {
reason = inspectResult.State.Error reason = inspectResult.State.Error
} }
containerStatus.State.Termination = &api.ContainerStateTerminated{ result.status.State.Termination = &api.ContainerStateTerminated{
ExitCode: inspectResult.State.ExitCode, ExitCode: inspectResult.State.ExitCode,
Reason: reason, Reason: reason,
StartedAt: util.NewTime(inspectResult.State.StartedAt), StartedAt: util.NewTime(inspectResult.State.StartedAt),
@ -578,7 +588,7 @@ func inspectContainer(client DockerInterface, dockerID, containerName, tPath str
if err != nil { if err != nil {
glog.Errorf("Error on reading termination-log %s: %v", path, err) glog.Errorf("Error on reading termination-log %s: %v", path, err)
} else { } else {
containerStatus.State.Termination.Message = string(data) result.status.State.Termination.Message = string(data)
} }
} }
} }
@ -589,18 +599,20 @@ func inspectContainer(client DockerInterface, dockerID, containerName, tPath str
// TODO(dchen1107): Separate issue docker/docker#8294 was filed // TODO(dchen1107): Separate issue docker/docker#8294 was filed
// TODO(dchen1107): Need to figure out why we are still waiting // TODO(dchen1107): Need to figure out why we are still waiting
// Check any issue to run container // Check any issue to run container
containerStatus.State.Waiting = &api.ContainerStateWaiting{ result.status.State.Waiting = &api.ContainerStateWaiting{
Reason: ErrContainerCannotRun.Error(), Reason: ErrContainerCannotRun.Error(),
} }
} }
return &containerStatus, nil return &result
} }
// GetDockerPodInfo returns docker info for all containers in the pod/manifest and // GetDockerPodStatus returns docker related status for all containers in the pod/manifest and
// infrastructure container // infrastructure container
func GetDockerPodInfo(client DockerInterface, manifest api.PodSpec, podFullName string, uid types.UID) (api.PodInfo, error) { func GetDockerPodStatus(client DockerInterface, manifest api.PodSpec, podFullName string, uid types.UID) (*api.PodStatus, error) {
info := api.PodInfo{} var podStatus api.PodStatus
podStatus.Info = api.PodInfo{}
expectedContainers := make(map[string]api.Container) expectedContainers := make(map[string]api.Container)
for _, container := range manifest.Containers { for _, container := range manifest.Containers {
expectedContainers[container.Name] = container expectedContainers[container.Name] = container
@ -635,34 +647,35 @@ func GetDockerPodInfo(client DockerInterface, manifest api.PodSpec, podFullName
terminationMessagePath = c.TerminationMessagePath terminationMessagePath = c.TerminationMessagePath
} }
// We assume docker return us a list of containers in time order // We assume docker return us a list of containers in time order
if containerStatus, found := info[dockerContainerName]; found { if containerStatus, found := podStatus.Info[dockerContainerName]; found {
containerStatus.RestartCount += 1 containerStatus.RestartCount += 1
info[dockerContainerName] = containerStatus podStatus.Info[dockerContainerName] = containerStatus
continue continue
} }
containerStatus, err := inspectContainer(client, value.ID, dockerContainerName, terminationMessagePath) result := inspectContainer(client, value.ID, dockerContainerName, terminationMessagePath)
if err != nil { if result.err != nil {
return nil, err return nil, err
} }
info[dockerContainerName] = *containerStatus // Add user container information
if dockerContainerName == PodInfraContainerName {
// Found network container
podStatus.PodIP = result.ip
} else {
podStatus.Info[dockerContainerName] = result.status
}
} }
if len(info) == 0 { if len(podStatus.Info) == 0 && podStatus.PodIP == "" {
return nil, ErrNoContainersInPod return nil, ErrNoContainersInPod
} }
// First make sure we are not missing pod infra container // Not all containers expected are created, check if there are
if _, found := info[PodInfraContainerName]; !found { // image related issues
return nil, ErrNoPodInfraContainerInPod if len(podStatus.Info) < len(manifest.Containers) {
}
if len(info) < (len(manifest.Containers) + 1) {
var containerStatus api.ContainerStatus var containerStatus api.ContainerStatus
// Not all containers expected are created, check if there are
// image related issues
for _, container := range manifest.Containers { for _, container := range manifest.Containers {
if _, found := info[container.Name]; found { if _, found := podStatus.Info[container.Name]; found {
continue continue
} }
@ -684,11 +697,11 @@ func GetDockerPodInfo(client DockerInterface, manifest api.PodSpec, podFullName
} }
} }
info[container.Name] = containerStatus podStatus.Info[container.Name] = containerStatus
} }
} }
return info, nil return &podStatus, nil
} }
const containerNamePrefix = "k8s" const containerNamePrefix = "k8s"

View File

@ -24,7 +24,6 @@ import (
"strconv" "strconv"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
"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/golang/glog" "github.com/golang/glog"
@ -77,11 +76,10 @@ func (h *httpActionHandler) Run(podFullName string, uid types.UID, container *ap
glog.Errorf("Unable to get pod info, event handlers may be invalid.") glog.Errorf("Unable to get pod info, event handlers may be invalid.")
return err return err
} }
netInfo, found := status.Info[dockertools.PodInfraContainerName] if status.PodIP == "" {
if !found {
return fmt.Errorf("failed to find networking container: %v", status) return fmt.Errorf("failed to find networking container: %v", status)
} }
host = netInfo.PodIP host = status.PodIP
} }
var port int var port int
if handler.HTTPGet.Port.Kind == util.IntstrString && len(handler.HTTPGet.Port.StrVal) == 0 { if handler.HTTPGet.Port.Kind == util.IntstrString && len(handler.HTTPGet.Port.StrVal) == 0 {

View File

@ -2015,44 +2015,40 @@ func (kl *Kubelet) GetPodStatus(podFullName string, uid types.UID) (api.PodStatu
func (kl *Kubelet) generatePodStatus(podFullName string, uid types.UID) (api.PodStatus, error) { func (kl *Kubelet) generatePodStatus(podFullName string, uid types.UID) (api.PodStatus, error) {
glog.V(3).Infof("Generating status for %s", podFullName) glog.V(3).Infof("Generating status for %s", podFullName)
var podStatus api.PodStatus
spec, found := kl.GetPodByFullName(podFullName) spec, found := kl.GetPodByFullName(podFullName)
if !found { if !found {
return podStatus, fmt.Errorf("Couldn't find spec for pod %s", podFullName) return api.PodStatus{}, fmt.Errorf("Couldn't find spec for pod %s", podFullName)
} }
info, err := dockertools.GetDockerPodInfo(kl.dockerClient, *spec, podFullName, uid) podStatus, err := dockertools.GetDockerPodStatus(kl.dockerClient, *spec, podFullName, uid)
if err != nil { if err != nil {
// Error handling // Error handling
glog.Infof("Query docker container info for pod %s failed with error (%v)", podFullName, err) glog.Infof("Query docker container info for pod %s failed with error (%v)", podFullName, err)
if strings.Contains(err.Error(), "resource temporarily unavailable") { if strings.Contains(err.Error(), "resource temporarily unavailable") {
// Leave upstream layer to decide what to do // Leave upstream layer to decide what to do
return podStatus, err return api.PodStatus{}, err
} else { } else {
podStatus.Phase = api.PodPending pendingStatus := api.PodStatus{
podStatus.Message = fmt.Sprintf("Query docker container info failed with error (%v)", err) Phase: api.PodPending,
return podStatus, nil Message: fmt.Sprintf("Query docker container info failed with error (%v)", err),
}
return pendingStatus, nil
} }
} }
// Assume info is ready to process // Assume info is ready to process
podStatus.Phase = getPhase(spec, info) podStatus.Phase = getPhase(spec, podStatus.Info)
podStatus.Info = api.PodInfo{}
for _, c := range spec.Containers { for _, c := range spec.Containers {
containerStatus := info[c.Name] containerStatus := podStatus.Info[c.Name]
containerStatus.Ready = kl.readiness.IsReady(containerStatus) containerStatus.Ready = kl.readiness.IsReady(containerStatus)
podStatus.Info[c.Name] = containerStatus podStatus.Info[c.Name] = containerStatus
} }
podStatus.Conditions = append(podStatus.Conditions, getPodReadyCondition(spec, podStatus.Info)...) podStatus.Conditions = append(podStatus.Conditions, getPodReadyCondition(spec, podStatus.Info)...)
netContainerInfo, found := info[dockertools.PodInfraContainerName]
if found {
podStatus.PodIP = netContainerInfo.PodIP
}
podStatus.Host = kl.hostname podStatus.Host = kl.hostname
return podStatus, nil return *podStatus, nil
} }
// Returns logs of current machine. // Returns logs of current machine.

View File

@ -636,7 +636,7 @@ func TestSyncPodsWithPodInfraCreatesContainer(t *testing.T) {
waitGroup.Wait() waitGroup.Wait()
verifyCalls(t, fakeDocker, []string{ verifyCalls(t, fakeDocker, []string{
"list", "list", "list", "inspect_container", "inspect_image", "list", "create", "start", "list", "inspect_container", "inspect_container"}) "list", "list", "list", "inspect_container", "list", "create", "start", "list", "inspect_container", "inspect_container"})
fakeDocker.Lock() fakeDocker.Lock()
if len(fakeDocker.Created) != 1 || if len(fakeDocker.Created) != 1 ||
@ -693,7 +693,7 @@ func TestSyncPodsWithPodInfraCreatesContainerCallsHandler(t *testing.T) {
waitGroup.Wait() waitGroup.Wait()
verifyCalls(t, fakeDocker, []string{ verifyCalls(t, fakeDocker, []string{
"list", "list", "list", "inspect_container", "inspect_image", "list", "create", "start", "list", "inspect_container", "inspect_container"}) "list", "list", "list", "inspect_container", "list", "create", "start", "list", "inspect_container", "inspect_container"})
fakeDocker.Lock() fakeDocker.Lock()
if len(fakeDocker.Created) != 1 || if len(fakeDocker.Created) != 1 ||