// Returns a list of all Daemon Set model objects in the cluster, based on all Kubernetes
// Daemon Set and Service API objects.
// The function processes all Daemon Set API objects and finds matching Services for them.
func getDaemonSetList(daemonSets []extensions.DaemonSet, pods []api.Pod,
	events []api.Event) *DaemonSetList {

	daemonSetList := &DaemonSetList{DaemonSets: make([]DaemonSet, 0)}

	for _, daemonSet := range daemonSets {

		matchingPods := make([]api.Pod, 0)
		for _, pod := range pods {
			if pod.ObjectMeta.Namespace == daemonSet.ObjectMeta.Namespace &&
				common.IsLabelSelectorMatching(pod.ObjectMeta.Labels, daemonSet.Spec.Selector) {
				matchingPods = append(matchingPods, pod)
			}
		}
		podInfo := getDaemonSetPodInfo(&daemonSet, matchingPods)
		podErrors := event.GetPodsEventWarnings(events, matchingPods)

		podInfo.Warnings = podErrors

		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),
			})
	}

	return daemonSetList
}
func getDeploymentList(deployments []extensions.Deployment, pods []api.Pod,
	events []api.Event) *DeploymentList {

	deploymentList := &DeploymentList{
		Deployments: make([]Deployment, 0),
	}

	for _, deployment := range deployments {

		matchingPods := common.FilterNamespacedPodsBySelector(pods, deployment.ObjectMeta.Namespace,
			deployment.Spec.Selector.MatchLabels)
		podInfo := getPodInfo(&deployment, matchingPods)
		podInfo.Warnings = event.GetPodsEventWarnings(events, matchingPods)

		deploymentList.Deployments = append(deploymentList.Deployments,
			Deployment{
				ObjectMeta:      common.NewObjectMeta(deployment.ObjectMeta),
				TypeMeta:        common.NewTypeMeta(common.ResourceKindDeployment),
				ContainerImages: common.GetContainerImages(&deployment.Spec.Template.Spec),
				Pods:            podInfo,
			})
	}

	return deploymentList
}
// Returns a list of all Replication Controller model objects in the cluster, based on all Kubernetes
// Replication Controller and Service API objects.
func getReplicationControllerList(replicationControllers []api.ReplicationController,
	pods []api.Pod, events []api.Event) *ReplicationControllerList {

	replicationControllerList := &ReplicationControllerList{
		ReplicationControllers: make([]ReplicationController, 0),
	}

	for _, replicationController := range replicationControllers {
		matchingPods := make([]api.Pod, 0)
		for _, pod := range pods {
			if pod.ObjectMeta.Namespace == replicationController.ObjectMeta.Namespace &&
				common.IsSelectorMatching(replicationController.Spec.Selector, pod.ObjectMeta.Labels) {
				matchingPods = append(matchingPods, pod)
			}
		}
		podInfo := getReplicationPodInfo(&replicationController, matchingPods)
		podErrors := event.GetPodsEventWarnings(events, matchingPods)

		podInfo.Warnings = podErrors

		replicationControllerList.ReplicationControllers = append(replicationControllerList.ReplicationControllers,
			ReplicationController{
				ObjectMeta:      common.NewObjectMeta(replicationController.ObjectMeta),
				TypeMeta:        common.NewTypeMeta(common.ResourceKindReplicationController),
				Pods:            podInfo,
				ContainerImages: common.GetContainerImages(&replicationController.Spec.Template.Spec),
			})
	}

	return replicationControllerList
}
func ToJob(job *batch.Job, podInfo *common.PodInfo) Job {
	return Job{
		ObjectMeta:      common.NewObjectMeta(job.ObjectMeta),
		TypeMeta:        common.NewTypeMeta(common.ResourceKindJob),
		ContainerImages: common.GetContainerImages(&job.Spec.Template.Spec),
		Pods:            *podInfo,
	}
}
func ToPetSet(petSet *apps.PetSet, podInfo *common.PodInfo) PetSet {
	return PetSet{
		ObjectMeta:      common.NewObjectMeta(petSet.ObjectMeta),
		TypeMeta:        common.NewTypeMeta(common.ResourceKindPetSet),
		ContainerImages: common.GetContainerImages(&petSet.Spec.Template.Spec),
		Pods:            *podInfo,
	}
}
func ToReplicaSet(replicaSet *extensions.ReplicaSet, podInfo *common.PodInfo) ReplicaSet {
	return ReplicaSet{
		ObjectMeta:      common.NewObjectMeta(replicaSet.ObjectMeta),
		TypeMeta:        common.NewTypeMeta(common.ResourceKindReplicaSet),
		ContainerImages: common.GetContainerImages(&replicaSet.Spec.Template.Spec),
		Pods:            *podInfo,
	}
}
func getReplicaSetDetail(replicaSet *extensions.ReplicaSet, heapsterClient client.HeapsterClient,
	events *common.EventList, pods []api.Pod) ReplicaSetDetail {

	matchingPods := common.FilterNamespacedPodsByLabelSelector(pods, replicaSet.ObjectMeta.Namespace,
		replicaSet.Spec.Selector)

	podInfo := getPodInfo(replicaSet, matchingPods)

	return ReplicaSetDetail{
		ObjectMeta:      common.NewObjectMeta(replicaSet.ObjectMeta),
		TypeMeta:        common.NewTypeMeta(common.ResourceKindReplicaSet),
		ContainerImages: common.GetContainerImages(&replicaSet.Spec.Template.Spec),
		PodInfo:         podInfo,
		PodList:         pod.CreatePodList(matchingPods, heapsterClient),
		EventList:       *events,
	}
}
func getPetSetDetail(petSet *apps.PetSet, heapsterClient client.HeapsterClient,
	events *common.EventList, pods []api.Pod) PetSetDetail {

	matchingPods := common.FilterNamespacedPodsByLabelSelector(pods, petSet.ObjectMeta.Namespace,
		petSet.Spec.Selector)

	podInfo := common.GetPodInfo(int32(petSet.Status.Replicas), int32(petSet.Spec.Replicas),
		matchingPods)

	return PetSetDetail{
		ObjectMeta:      common.NewObjectMeta(petSet.ObjectMeta),
		TypeMeta:        common.NewTypeMeta(common.ResourceKindPetSet),
		ContainerImages: common.GetContainerImages(&petSet.Spec.Template.Spec),
		PodInfo:         podInfo,
		PodList:         pod.CreatePodList(matchingPods, heapsterClient),
		EventList:       *events,
	}
}
func getJobDetail(job *batch.Job, heapsterClient client.HeapsterClient,
	events *common.EventList, pods []api.Pod) JobDetail {

	matchingPods := common.FilterNamespacedPodsBySelector(pods, job.ObjectMeta.Namespace,
		job.Spec.Selector.MatchLabels)

	podInfo := getPodInfo(job, matchingPods)

	return JobDetail{
		ObjectMeta:      common.NewObjectMeta(job.ObjectMeta),
		TypeMeta:        common.NewTypeMeta(common.ResourceKindJob),
		ContainerImages: common.GetContainerImages(&job.Spec.Template.Spec),
		PodInfo:         podInfo,
		PodList:         pod.CreatePodList(matchingPods, heapsterClient),
		EventList:       *events,
		Parallelism:     job.Spec.Parallelism,
		Completions:     job.Spec.Completions,
	}
}