コード例 #1
0
ファイル: server.go プロジェクト: nail-lian/kubernetes
// encodePods creates an api.PodList object from pods and returns the encoded
// PodList.
func encodePods(pods []*api.Pod) (data []byte, err error) {
	podList := new(api.PodList)
	for _, pod := range pods {
		podList.Items = append(podList.Items, *pod)
	}
	return latest.Codec.Encode(podList)
}
コード例 #2
0
ファイル: pod_registry.go プロジェクト: jgeewax/kubernetes
func (storage *PodRegistryStorage) List(query labels.Query) (interface{}, error) {
	var result api.PodList
	pods, err := storage.registry.ListPods(query)
	if err == nil {
		result.Items = pods
	}
	result.Kind = "cluster#podList"
	return result, err
}
コード例 #3
0
ファイル: storage.go プロジェクト: kunallimaye/kubernetes
func (rs *RegistryStorage) List(selector labels.Selector) (interface{}, error) {
	var result api.PodList
	pods, err := rs.registry.ListPods(selector)
	if err == nil {
		result.Items = pods
		for i := range result.Items {
			rs.fillPodInfo(&result.Items[i])
		}
	}
	return result, err
}
コード例 #4
0
ファイル: listers.go プロジェクト: Ima8/kubernetes
// Please note that selector is filtering among the pods that have gotten into
// the store; there may have been some filtering that already happened before
// that.
func (s storePodsNamespacer) List(selector labels.Selector) (pods api.PodList, err error) {
	list := api.PodList{}
	for _, m := range s.store.List() {
		pod := m.(*api.Pod)
		if s.namespace == api.NamespaceAll || s.namespace == pod.Namespace {
			if selector.Matches(labels.Set(pod.Labels)) {
				list.Items = append(list.Items, *pod)
			}
		}
	}
	return list, nil
}
コード例 #5
0
ファイル: server.go プロジェクト: cjnygard/origin
// handlePods returns a list of pod bound to the Kubelet and their spec
func (s *Server) handlePods(w http.ResponseWriter, req *http.Request) {
	pods := s.host.GetPods()
	podList := new(api.PodList)
	for _, pod := range pods {
		podList.Items = append(podList.Items, *pod)
	}
	data, err := latest.Codec.Encode(podList)
	if err != nil {
		s.error(w, err)
		return
	}
	w.Header().Add("Content-type", "application/json")
	w.Write(data)
}
コード例 #6
0
ファイル: pod_registry.go プロジェクト: happywky/kubernetes
func (storage *PodRegistryStorage) List(url *url.URL) (interface{}, error) {
	var result api.PodList
	var query *map[string]string
	if url != nil {
		queryMap := client.DecodeLabelQuery(url.Query().Get("labels"))
		query = &queryMap
	}
	pods, err := storage.registry.ListPods(query)
	if err == nil {
		result = api.PodList{
			Items: pods,
		}
	}
	result.Kind = "cluster#podList"
	return result, err
}
コード例 #7
0
ファイル: etcd.go プロジェクト: hortonworks/kubernetes-yarn
// ListPodsPredicate obtains a list of pods that match filter.
func (r *Registry) ListPodsPredicate(ctx api.Context, filter func(*api.Pod) bool) (*api.PodList, error) {
	allPods := api.PodList{}
	key := makePodListKey(ctx)
	err := r.ExtractToList(key, &allPods)
	if err != nil {
		return nil, err
	}
	filtered := []api.Pod{}
	for _, pod := range allPods.Items {
		if filter(&pod) {
			filtered = append(filtered, pod)
		}
	}
	allPods.Items = filtered
	return &allPods, nil
}
コード例 #8
0
ファイル: etcd.go プロジェクト: nvdnkpr/kubernetes
// ListPods obtains a list of pods that match selector.
func (r *Registry) ListPods(selector labels.Selector) (*api.PodList, error) {
	allPods := api.PodList{}
	err := r.ExtractList("/registry/pods", &allPods.Items, &allPods.ResourceVersion)
	if err != nil {
		return nil, err
	}
	filtered := []api.Pod{}
	for _, pod := range allPods.Items {
		if selector.Matches(labels.Set(pod.Labels)) {
			// TODO: Currently nothing sets CurrentState.Host. We need a feedback loop that sets
			// the CurrentState.Host and Status fields. Here we pretend that reality perfectly
			// matches our desires.
			pod.CurrentState.Host = pod.DesiredState.Host
			filtered = append(filtered, pod)
		}
	}
	allPods.Items = filtered
	return &allPods, nil
}
コード例 #9
0
ファイル: etcd.go プロジェクト: ericcapricorn/kubernetes
// ListPodsPredicate obtains a list of pods that match filter.
func (r *Registry) ListPodsPredicate(ctx api.Context, filter func(*api.Pod) bool) (*api.PodList, error) {
	allPods := api.PodList{}
	key := makePodListKey(ctx)
	err := r.ExtractToList(key, &allPods)
	if err != nil {
		return nil, err
	}
	filtered := []api.Pod{}
	for _, pod := range allPods.Items {
		if filter(&pod) {
			// TODO: Currently nothing sets CurrentState.Host. We need a feedback loop that sets
			// the CurrentState.Host and Status fields. Here we pretend that reality perfectly
			// matches our desires.
			pod.CurrentState.Host = pod.DesiredState.Host
			filtered = append(filtered, pod)
		}
	}
	allPods.Items = filtered
	return &allPods, nil
}
コード例 #10
0
ファイル: pod_registry.go プロジェクト: jmoretti/kubernetes
func (storage *PodRegistryStorage) List(selector labels.Selector) (interface{}, error) {
	var result api.PodList
	pods, err := storage.registry.ListPods(selector)
	if err == nil {
		result.Items = pods
		// Get cached info for the list currently.
		// TODO: Optionally use fresh info
		if storage.podCache != nil {
			for ix, pod := range pods {
				info, err := storage.podCache.GetContainerInfo(pod.CurrentState.Host, pod.ID)
				if err != nil {
					glog.Errorf("Error getting container info: %#v", err)
					continue
				}
				result.Items[ix].CurrentState.Info = info
			}
		}
	}

	return result, err
}