// getMyPodsFromCache returns a full list of pods that belong to this resource. // It is important that cachedPods include ALL pods from the namespace of this resource (but they can also include pods from other namespaces). func (self *ResourceSelector) getMyPodsFromCache(cachedPods []api.Pod) ([]api.Pod, error) { // make sure we have the full list of pods. you have to make sure the cache has pod list for all namespaces! if cachedPods == nil { return nil, fmt.Errorf(`GetMyPodsFromCache: pods were not available in cache. Required for resource type: "%s"`, self.ResourceType) } // now decide whether to match by ResourceSelector or by ResourceLabelSelector if self.LabelSelector != nil { return common.FilterNamespacedPodsByLabelSelector(cachedPods, self.Namespace, self.LabelSelector), nil } else if self.Selector != nil { return common.FilterNamespacedPodsBySelector(cachedPods, self.Namespace, self.Selector), nil } else { return nil, fmt.Errorf(`GetMyPodsFromCache: did not find any resource selector for resource type: "%s"`, self.ResourceType) } }
// Returns array of api pods targeting daemon set with given name. func getRawDaemonSetPods(client k8sClient.Interface, daemonSetName, namespace string) ( []api.Pod, error) { daemonSet, err := client.Extensions().DaemonSets(namespace).Get(daemonSetName) if err != nil { return nil, err } channels := &common.ResourceChannels{ PodList: common.GetPodListChannel(client, common.NewSameNamespaceQuery(namespace), 1), } podList := <-channels.PodList.List if err := <-channels.PodList.Error; err != nil { return nil, err } matchingPods := common.FilterNamespacedPodsByLabelSelector(podList.Items, daemonSet.ObjectMeta.Namespace, daemonSet.Spec.Selector) return matchingPods, nil }
// Returns array of api pods targeting pet set with given name. func getRawStatefulSetPods(client *k8sClient.Clientset, statefulSetName, namespace string) ( []api.Pod, error) { statefulSet, err := client.Apps().StatefulSets(namespace).Get(statefulSetName) if err != nil { return nil, err } channels := &common.ResourceChannels{ PodList: common.GetPodListChannel(client, common.NewSameNamespaceQuery(namespace), 1), } podList := <-channels.PodList.List if err := <-channels.PodList.Error; err != nil { return nil, err } matchingPods := common.FilterNamespacedPodsByLabelSelector(podList.Items, statefulSet.ObjectMeta.Namespace, statefulSet.Spec.Selector) return matchingPods, nil }
// CreateDaemonSetList returns a list of all Daemon Set model objects in the cluster, based on all // Kubernetes Daemon Set API objects. func CreateDaemonSetList(daemonSets []extensions.DaemonSet, pods []api.Pod, events []api.Event, dsQuery *dataselect.DataSelectQuery, heapsterClient *heapster.HeapsterClient) *DaemonSetList { daemonSetList := &DaemonSetList{ DaemonSets: make([]DaemonSet, 0), ListMeta: common.ListMeta{TotalItems: len(daemonSets)}, } cachedResources := &dataselect.CachedResources{ Pods: pods, } replicationControllerCells, metricPromises := dataselect.GenericDataSelectWithMetrics(daemonset.ToCells(daemonSets), dsQuery, cachedResources, heapsterClient) daemonSets = daemonset.FromCells(replicationControllerCells) for _, daemonSet := range daemonSets { matchingPods := common.FilterNamespacedPodsByLabelSelector(pods, daemonSet.Namespace, daemonSet.Spec.Selector) podInfo := common.GetPodInfo(daemonSet.Status.CurrentNumberScheduled, daemonSet.Status.DesiredNumberScheduled, matchingPods) podInfo.Warnings = event.GetPodsEventWarnings(events, matchingPods) daemonSetList.DaemonSets = append(daemonSetList.DaemonSets, DaemonSet{ ObjectMeta: common.NewObjectMeta(daemonSet.ObjectMeta), TypeMeta: common.NewTypeMeta(common.ResourceKindDaemonSet), Pods: podInfo, ContainerImages: common.GetContainerImages(&daemonSet.Spec.Template.Spec), }) } cumulativeMetrics, err := metricPromises.GetMetrics() daemonSetList.CumulativeMetrics = cumulativeMetrics if err != nil { daemonSetList.CumulativeMetrics = make([]metric.Metric, 0) } return daemonSetList }