本文整理汇总了Golang中k8s/io/kubernetes/pkg/kubelet/api/v1alpha1/runtime.PodSandboxFilter.GetName方法的典型用法代码示例。如果您正苦于以下问题:Golang PodSandboxFilter.GetName方法的具体用法?Golang PodSandboxFilter.GetName怎么用?Golang PodSandboxFilter.GetName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类k8s/io/kubernetes/pkg/kubelet/api/v1alpha1/runtime.PodSandboxFilter
的用法示例。
在下文中一共展示了PodSandboxFilter.GetName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ListPodSandbox
func (r *FakeRuntimeService) ListPodSandbox(filter *runtimeApi.PodSandboxFilter) ([]*runtimeApi.PodSandbox, error) {
r.Lock()
defer r.Unlock()
r.Called = append(r.Called, "ListPodSandbox")
result := make([]*runtimeApi.PodSandbox, 0)
for id, s := range r.Sandboxes {
if filter != nil {
if filter.Id != nil && filter.GetId() != id {
continue
}
if filter.Name != nil && filter.GetName() != s.Metadata.GetName() {
continue
}
if filter.State != nil && filter.GetState() != s.GetState() {
continue
}
if filter.LabelSelector != nil && !filterInLabels(filter.LabelSelector, s.GetLabels()) {
continue
}
}
result = append(result, &runtimeApi.PodSandbox{
Id: s.Id,
Metadata: s.Metadata,
State: s.State,
CreatedAt: s.CreatedAt,
Labels: s.Labels,
})
}
return result, nil
}
示例2: ListPodSandbox
// ListPodSandbox returns a list of Sandbox.
func (ds *dockerService) ListPodSandbox(filter *runtimeApi.PodSandboxFilter) ([]*runtimeApi.PodSandbox, error) {
// By default, list all containers whether they are running or not.
opts := dockertypes.ContainerListOptions{All: true}
filterOutReadySandboxes := false
opts.Filter = dockerfilters.NewArgs()
f := newDockerFilter(&opts.Filter)
if filter != nil {
if filter.Id != nil {
f.Add("id", filter.GetId())
}
if filter.State != nil {
if filter.GetState() == runtimeApi.PodSandBoxState_READY {
// Only list running containers.
opts.All = false
} else {
// runtimeApi.PodSandBoxState_NOTREADY can mean the
// container is in any of the non-running state (e.g., created,
// exited). We can't tell docker to filter out running
// containers directly, so we'll need to filter them out
// ourselves after getting the results.
filterOutReadySandboxes = true
}
}
if filter.LabelSelector != nil {
for k, v := range filter.LabelSelector {
f.AddLabel(k, v)
}
}
// Filter out sandbox containers.
f.AddLabel(containerTypeLabelKey, containerTypeLabelSandbox)
}
containers, err := ds.client.ListContainers(opts)
if err != nil {
return nil, err
}
// Convert docker containers to runtime api sandboxes.
result := []*runtimeApi.PodSandbox{}
for _, c := range containers {
if len(filter.GetName()) > 0 {
sandboxName, _, _, _, err := parseSandboxName(c.Names[0])
if err != nil || sandboxName != filter.GetName() {
continue
}
}
s := toRuntimeAPISandbox(&c)
if filterOutReadySandboxes && s.GetState() == runtimeApi.PodSandBoxState_READY {
continue
}
result = append(result, s)
}
return result, nil
}