// CreateReplicaSetList creates paginated list of Replica Set model // objects based on Kubernetes Replica Set objects array and related resources arrays. func CreateReplicaSetList(replicaSets []extensions.ReplicaSet, pods []api.Pod, events []api.Event, dsQuery *dataselect.DataSelectQuery, heapsterClient *heapster.HeapsterClient) *ReplicaSetList { replicaSetList := &ReplicaSetList{ ReplicaSets: make([]replicaset.ReplicaSet, 0), ListMeta: common.ListMeta{TotalItems: len(replicaSets)}, } cachedResources := &dataselect.CachedResources{ Pods: pods, } replicationControllerCells, metricPromises := dataselect.GenericDataSelectWithMetrics(replicaset.ToCells(replicaSets), dsQuery, cachedResources, heapsterClient) replicaSets = replicaset.FromCells(replicationControllerCells) for _, replicaSet := range replicaSets { matchingPods := common.FilterNamespacedPodsBySelector(pods, replicaSet.ObjectMeta.Namespace, replicaSet.Spec.Selector.MatchLabels) podInfo := common.GetPodInfo(replicaSet.Status.Replicas, replicaSet.Spec.Replicas, matchingPods) podInfo.Warnings = event.GetPodsEventWarnings(events, matchingPods) replicaSetList.ReplicaSets = append(replicaSetList.ReplicaSets, replicaset.ToReplicaSet(&replicaSet, &podInfo)) } cumulativeMetrics, err := metricPromises.GetMetrics() replicaSetList.CumulativeMetrics = cumulativeMetrics if err != nil { replicaSetList.CumulativeMetrics = make([]metric.Metric, 0) } return replicaSetList }
// GetDeploymentDetail returns model object of deployment and error, if any. func GetDeploymentDetail(client client.Interface, heapsterClient heapster.HeapsterClient, namespace string, deploymentName string) (*DeploymentDetail, error) { log.Printf("Getting details of %s deployment in %s namespace", deploymentName, namespace) deployment, err := client.Extensions().Deployments(namespace).Get(deploymentName) if err != nil { return nil, err } selector, err := unversioned.LabelSelectorAsSelector(deployment.Spec.Selector) if err != nil { return nil, err } options := api.ListOptions{LabelSelector: selector} channels := &common.ResourceChannels{ ReplicaSetList: common.GetReplicaSetListChannelWithOptions(client.Extensions(), common.NewSameNamespaceQuery(namespace), options, 1), PodList: common.GetPodListChannelWithOptions(client, common.NewSameNamespaceQuery(namespace), options, 1), } rawRs := <-channels.ReplicaSetList.List if err := <-channels.ReplicaSetList.Error; err != nil { return nil, err } rawPods := <-channels.PodList.List if err := <-channels.PodList.Error; err != nil { return nil, err } // Pods podList, err := GetDeploymentPods(client, heapsterClient, dataselect.DefaultDataSelectWithMetrics, namespace, deploymentName) if err != nil { return nil, err } // Events eventList, err := GetDeploymentEvents(client, dataselect.DefaultDataSelect, namespace, deploymentName) if err != nil { return nil, err } // Old Replica Sets oldReplicaSetList, err := GetDeploymentOldReplicaSets(client, dataselect.DefaultDataSelect, namespace, deploymentName) if err != nil { return nil, err } // New Replica Set newRs, err := deploymentutil.FindNewReplicaSet(deployment, rawRs.Items) if err != nil { return nil, err } var newReplicaSet replicaset.ReplicaSet if newRs != nil { newRsPodInfo := common.GetPodInfo(newRs.Status.Replicas, newRs.Spec.Replicas, rawPods.Items) newReplicaSet = replicaset.ToReplicaSet(newRs, &newRsPodInfo) } // Extra Info var rollingUpdateStrategy *RollingUpdateStrategy if deployment.Spec.Strategy.RollingUpdate != nil { rollingUpdateStrategy = &RollingUpdateStrategy{ MaxSurge: deployment.Spec.Strategy.RollingUpdate.MaxSurge.IntValue(), MaxUnavailable: deployment.Spec.Strategy.RollingUpdate.MaxUnavailable.IntValue(), } } return &DeploymentDetail{ ObjectMeta: common.NewObjectMeta(deployment.ObjectMeta), TypeMeta: common.NewTypeMeta(common.ResourceKindDeployment), PodList: *podList, Selector: deployment.Spec.Selector.MatchLabels, StatusInfo: GetStatusInfo(&deployment.Status), Strategy: deployment.Spec.Strategy.Type, MinReadySeconds: deployment.Spec.MinReadySeconds, RollingUpdateStrategy: rollingUpdateStrategy, OldReplicaSetList: *oldReplicaSetList, NewReplicaSet: newReplicaSet, RevisionHistoryLimit: deployment.Spec.RevisionHistoryLimit, EventList: *eventList, }, nil }