本文整理匯總了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/api.ContainerStatus.Name方法的典型用法代碼示例。如果您正苦於以下問題:Golang ContainerStatus.Name方法的具體用法?Golang ContainerStatus.Name怎麽用?Golang ContainerStatus.Name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/GoogleCloudPlatform/kubernetes/pkg/api.ContainerStatus
的用法示例。
在下文中一共展示了ContainerStatus.Name方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getContainerStatus
// getContainerStatus creates the api.containerStatus of a container from the podInfo.
// TODO(yifan): Get more detailed info such as Image, ImageID, etc.
func (p *podInfo) getContainerStatus(container *kubecontainer.Container) api.ContainerStatus {
var status api.ContainerStatus
status.Name = container.Name
status.Image = container.Image
containerID, _ := parseContainerID(string(container.ID))
status.ImageID = containerID.imageID
switch p.state {
case Running:
// TODO(yifan): Get StartedAt.
status.State = api.ContainerState{
Running: &api.ContainerStateRunning{
StartedAt: util.Unix(container.Created, 0),
},
}
case Embryo, Preparing, Prepared:
status.State = api.ContainerState{Waiting: &api.ContainerStateWaiting{}}
case AbortedPrepare, Deleting, Exited, Garbage:
exitCode, ok := p.exitCodes[status.ImageID]
if !ok {
glog.Warningf("rkt: Cannot get exit code for container %v", container)
}
exitCode = -1
status.State = api.ContainerState{
Terminated: &api.ContainerStateTerminated{
ExitCode: exitCode,
StartedAt: util.Unix(container.Created, 0),
},
}
default:
glog.Warningf("rkt: Unknown pod state: %q", p.state)
}
return status
}
示例2: addConversionFuncs
func addConversionFuncs() {
// Our TypeMeta was split into two different structs.
api.Scheme.AddStructFieldConversion(TypeMeta{}, "TypeMeta", api.TypeMeta{}, "TypeMeta")
api.Scheme.AddStructFieldConversion(TypeMeta{}, "TypeMeta", api.ObjectMeta{}, "ObjectMeta")
api.Scheme.AddStructFieldConversion(TypeMeta{}, "TypeMeta", api.ListMeta{}, "ListMeta")
api.Scheme.AddStructFieldConversion(api.TypeMeta{}, "TypeMeta", TypeMeta{}, "TypeMeta")
api.Scheme.AddStructFieldConversion(api.ObjectMeta{}, "ObjectMeta", TypeMeta{}, "TypeMeta")
api.Scheme.AddStructFieldConversion(api.ListMeta{}, "ListMeta", TypeMeta{}, "TypeMeta")
api.Scheme.AddStructFieldConversion(api.Endpoints{}, "Endpoints", Endpoints{}, "Endpoints")
// TODO: scope this to a specific type once that becomes available and remove the Event conversion functions below
// api.Scheme.AddStructFieldConversion(string(""), "Status", string(""), "Condition")
// api.Scheme.AddStructFieldConversion(string(""), "Condition", string(""), "Status")
err := api.Scheme.AddConversionFuncs(
// TypeMeta must be split into two objects
func(in *api.TypeMeta, out *TypeMeta, s conversion.Scope) error {
out.Kind = in.Kind
out.APIVersion = in.APIVersion
return nil
},
func(in *TypeMeta, out *api.TypeMeta, s conversion.Scope) error {
out.Kind = in.Kind
out.APIVersion = in.APIVersion
return nil
},
// ListMeta must be converted to TypeMeta
func(in *api.ListMeta, out *TypeMeta, s conversion.Scope) error {
out.SelfLink = in.SelfLink
if len(in.ResourceVersion) > 0 {
v, err := strconv.ParseUint(in.ResourceVersion, 10, 64)
if err != nil {
return err
}
out.ResourceVersion = v
}
return nil
},
func(in *TypeMeta, out *api.ListMeta, s conversion.Scope) error {
out.SelfLink = in.SelfLink
if in.ResourceVersion != 0 {
out.ResourceVersion = strconv.FormatUint(in.ResourceVersion, 10)
} else {
out.ResourceVersion = ""
}
return nil
},
// ObjectMeta must be converted to TypeMeta
func(in *api.ObjectMeta, out *TypeMeta, s conversion.Scope) error {
out.Namespace = in.Namespace
out.ID = in.Name
out.GenerateName = in.GenerateName
out.UID = in.UID
out.CreationTimestamp = in.CreationTimestamp
out.DeletionTimestamp = in.DeletionTimestamp
out.SelfLink = in.SelfLink
if len(in.ResourceVersion) > 0 {
v, err := strconv.ParseUint(in.ResourceVersion, 10, 64)
if err != nil {
return err
}
out.ResourceVersion = v
}
return s.Convert(&in.Annotations, &out.Annotations, 0)
},
func(in *TypeMeta, out *api.ObjectMeta, s conversion.Scope) error {
out.Namespace = in.Namespace
out.Name = in.ID
out.GenerateName = in.GenerateName
out.UID = in.UID
out.CreationTimestamp = in.CreationTimestamp
out.DeletionTimestamp = in.DeletionTimestamp
out.SelfLink = in.SelfLink
if in.ResourceVersion != 0 {
out.ResourceVersion = strconv.FormatUint(in.ResourceVersion, 10)
} else {
out.ResourceVersion = ""
}
return s.Convert(&in.Annotations, &out.Annotations, 0)
},
// Convert all to the new PodPhase constants
func(in *api.PodPhase, out *PodStatus, s conversion.Scope) error {
switch *in {
case "":
*out = ""
case api.PodPending:
*out = PodWaiting
case api.PodRunning:
*out = PodRunning
case api.PodSucceeded:
*out = PodSucceeded
case api.PodFailed:
*out = PodTerminated
case api.PodUnknown:
*out = PodUnknown
default:
//.........這裏部分代碼省略.........
示例3: GetPodStatus
// GetPodStatus returns docker related status for all containers in the pod as
// well as the infrastructure container.
func (dm *DockerManager) GetPodStatus(pod *api.Pod) (*api.PodStatus, error) {
podFullName := kubecontainer.GetPodFullName(pod)
uid := pod.UID
manifest := pod.Spec
oldStatuses := make(map[string]api.ContainerStatus, len(pod.Spec.Containers))
lastObservedTime := make(map[string]util.Time, len(pod.Spec.Containers))
for _, status := range pod.Status.ContainerStatuses {
oldStatuses[status.Name] = status
if status.LastTerminationState.Termination != nil {
lastObservedTime[status.Name] = status.LastTerminationState.Termination.FinishedAt
}
}
var podStatus api.PodStatus
statuses := make(map[string]*api.ContainerStatus, len(pod.Spec.Containers))
expectedContainers := make(map[string]api.Container)
for _, container := range manifest.Containers {
expectedContainers[container.Name] = container
}
expectedContainers[PodInfraContainerName] = api.Container{}
containers, err := dm.client.ListContainers(docker.ListContainersOptions{All: true})
if err != nil {
return nil, err
}
containerDone := util.NewStringSet()
// Loop through list of running and exited docker containers to construct
// the statuses. We assume docker returns a list of containers sorted in
// reverse by time.
for _, value := range containers {
if len(value.Names) == 0 {
continue
}
dockerName, _, err := ParseDockerName(value.Names[0])
if err != nil {
continue
}
if dockerName.PodFullName != podFullName {
continue
}
if uid != "" && dockerName.PodUID != uid {
continue
}
dockerContainerName := dockerName.ContainerName
c, found := expectedContainers[dockerContainerName]
if !found {
continue
}
terminationMessagePath := c.TerminationMessagePath
if containerDone.Has(dockerContainerName) {
continue
}
var terminationState *api.ContainerState = nil
// Inspect the container.
result := dm.inspectContainer(value.ID, dockerContainerName, terminationMessagePath)
if result.err != nil {
return nil, result.err
} else if result.status.State.Termination != nil {
terminationState = &result.status.State
}
if containerStatus, found := statuses[dockerContainerName]; found {
if containerStatus.LastTerminationState.Termination == nil && terminationState != nil {
// Populate the last termination state.
containerStatus.LastTerminationState = *terminationState
}
count := true
// Only count dead containers terminated after last time we observed,
if lastObservedTime, ok := lastObservedTime[dockerContainerName]; ok {
if terminationState != nil && terminationState.Termination.FinishedAt.After(lastObservedTime.Time) {
count = false
} else {
// The container finished before the last observation. No
// need to examine/count the older containers. Mark the
// container name as done.
containerDone.Insert(dockerContainerName)
}
}
if count {
containerStatus.RestartCount += 1
}
continue
}
if dockerContainerName == PodInfraContainerName {
// Found network container
if result.status.State.Running != nil {
podStatus.PodIP = result.ip
}
} else {
// Add user container information.
if oldStatus, found := oldStatuses[dockerContainerName]; found {
// Use the last observed restart count if it's available.
result.status.RestartCount = oldStatus.RestartCount
//.........這裏部分代碼省略.........