當前位置: 首頁>>代碼示例>>Golang>>正文


Golang PodSandboxFilter.GetId方法代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/pkg/kubelet/api/v1alpha1/runtime.PodSandboxFilter.GetId方法的典型用法代碼示例。如果您正苦於以下問題:Golang PodSandboxFilter.GetId方法的具體用法?Golang PodSandboxFilter.GetId怎麽用?Golang PodSandboxFilter.GetId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在k8s/io/kubernetes/pkg/kubelet/api/v1alpha1/runtime.PodSandboxFilter的用法示例。


在下文中一共展示了PodSandboxFilter.GetId方法的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
}
開發者ID:cheld,項目名稱:kubernetes,代碼行數:34,代碼來源:fake_runtime_service.go

示例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)
	// Add filter to select only sandbox containers.
	f.AddLabel(containerTypeLabelKey, containerTypeLabelSandbox)

	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)
			}
		}
	}
	containers, err := ds.client.ListContainers(opts)
	if err != nil {
		return nil, err
	}

	// Convert docker containers to runtime api sandboxes.
	result := []*runtimeApi.PodSandbox{}
	for i := range containers {
		c := containers[i]
		converted, err := toRuntimeAPISandbox(&c)
		if err != nil {
			glog.V(5).Infof("Unable to convert docker to runtime API sandbox: %v", err)
			continue
		}
		if filterOutReadySandboxes && converted.GetState() == runtimeApi.PodSandBoxState_READY {
			continue
		}

		result = append(result, converted)
	}
	return result, nil
}
開發者ID:simonswine,項目名稱:kubernetes,代碼行數:57,代碼來源:docker_sandbox.go


注:本文中的k8s/io/kubernetes/pkg/kubelet/api/v1alpha1/runtime.PodSandboxFilter.GetId方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。