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


Golang runtime.ContainerFilter類代碼示例

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


在下文中一共展示了ContainerFilter類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ListContainers

// ListContainers lists all containers matching the filter.
func (ds *dockerService) ListContainers(filter *runtimeApi.ContainerFilter) ([]*runtimeApi.Container, error) {
	opts := dockertypes.ContainerListOptions{All: true}

	opts.Filter = dockerfilters.NewArgs()
	f := newDockerFilter(&opts.Filter)
	// Add filter to get *only* (non-sandbox) containers.
	f.AddLabel(containerTypeLabelKey, containerTypeLabelContainer)

	if filter != nil {
		if filter.Id != nil {
			f.Add("id", filter.GetId())
		}
		if filter.State != nil {
			f.Add("status", toDockerContainerStatus(filter.GetState()))
		}
		if filter.PodSandboxId != nil {
			f.AddLabel(sandboxIDLabelKey, *filter.PodSandboxId)
		}

		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 to runtime api containers.
	result := []*runtimeApi.Container{}
	for i := range containers {
		c := containers[i]

		converted, err := toRuntimeAPIContainer(&c)
		if err != nil {
			glog.V(5).Infof("Unable to convert docker to runtime API container: %v", err)
			continue
		}

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

示例2: ListContainers

// ListContainers lists all containers matching the filter.
func (ds *dockerService) ListContainers(filter *runtimeApi.ContainerFilter) ([]*runtimeApi.Container, error) {
	opts := dockertypes.ContainerListOptions{All: true}

	opts.Filter = dockerfilters.NewArgs()
	if filter != nil {
		if filter.Name != nil {
			opts.Filter.Add("name", filter.GetName())
		}
		if filter.Id != nil {
			opts.Filter.Add("id", filter.GetId())
		}
		if filter.State != nil {
			opts.Filter.Add("status", toDockerContainerStatus(filter.GetState()))
		}
		if filter.PodSandboxId != nil {
			// TODO: implement this after sandbox functions are implemented.
		}

		if filter.LabelSelector != nil {
			for k, v := range filter.LabelSelector {
				opts.Filter.Add("label", fmt.Sprintf("%s=%s", k, v))
			}
		}
	}
	containers, err := ds.client.ListContainers(opts)
	if err != nil {
		return nil, err
	}
	// Convert docker to runtime api containers.
	result := []*runtimeApi.Container{}
	for _, c := range containers {
		result = append(result, toRuntimeAPIContainer(&c))
	}
	return result, nil
}
開發者ID:rlugojr,項目名稱:kubernetes,代碼行數:36,代碼來源:docker_container.go

示例3: ListContainers

func (r *FakeRuntimeService) ListContainers(filter *runtimeApi.ContainerFilter) ([]*runtimeApi.Container, error) {
	r.Lock()
	defer r.Unlock()

	r.Called = append(r.Called, "ListContainers")

	result := make([]*runtimeApi.Container, 0)
	for _, s := range r.Containers {
		if filter != nil {
			if filter.Id != nil && filter.GetId() != s.GetId() {
				continue
			}
			if filter.PodSandboxId != nil && filter.GetPodSandboxId() != s.SandboxID {
				continue
			}
			if filter.State != nil && filter.GetState() != s.GetState() {
				continue
			}
			if filter.LabelSelector != nil && !filterInLabels(filter.LabelSelector, s.GetLabels()) {
				continue
			}
		}

		result = append(result, &runtimeApi.Container{
			Id:       s.Id,
			Metadata: s.Metadata,
			State:    s.State,
			Image:    s.Image,
			ImageRef: s.ImageRef,
			Labels:   s.Labels,
		})
	}

	return result, nil
}
開發者ID:huang195,項目名稱:kubernetes,代碼行數:35,代碼來源:fake_runtime_service.go

示例4: ListContainers

// ListContainers lists all containers matching the filter.
func (ds *dockerService) ListContainers(filter *runtimeApi.ContainerFilter) ([]*runtimeApi.Container, error) {
	opts := dockertypes.ContainerListOptions{All: true}

	opts.Filter = dockerfilters.NewArgs()
	f := newDockerFilter(&opts.Filter)

	if filter != nil {
		if filter.Id != nil {
			f.Add("id", filter.GetId())
		}
		if filter.State != nil {
			f.Add("status", toDockerContainerStatus(filter.GetState()))
		}
		if filter.PodSandboxId != nil {
			// TODO: implement this after sandbox functions are implemented.
		}

		if filter.LabelSelector != nil {
			for k, v := range filter.LabelSelector {
				f.AddLabel(k, v)
			}
		}
		// Filter out sandbox containers.
		f.AddLabel(containerTypeLabelKey, containerTypeLabelContainer)
	}
	containers, err := ds.client.ListContainers(opts)
	if err != nil {
		return nil, err
	}
	// Convert docker to runtime api containers.
	result := []*runtimeApi.Container{}
	for _, c := range containers {
		if len(filter.GetName()) > 0 {
			_, _, _, containerName, _, err := parseContainerName(c.Names[0])
			if err != nil || containerName != filter.GetName() {
				continue
			}
		}

		result = append(result, toRuntimeAPIContainer(&c))
	}
	return result, nil
}
開發者ID:juanluisvaladas,項目名稱:origin,代碼行數:44,代碼來源:docker_container.go


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