// GetReplicationControllerDetail returns detailed information about the given replication
// controller in the given namespace.
func GetReplicationControllerDetail(client k8sClient.Interface, heapsterClient client.HeapsterClient,
	namespace, name string) (*ReplicationControllerDetail, error) {
	log.Printf("Getting details of %s replication controller in %s namespace", name, namespace)

	replicationController, err := client.Core().ReplicationControllers(namespace).Get(name)
	if err != nil {
		return nil, err
	}

	podInfo, err := getReplicationControllerPodInfo(client, replicationController, namespace)
	if err != nil {
		return nil, err
	}

	podList, err := GetReplicationControllerPods(client, heapsterClient, dataselect.DefaultDataSelectWithMetrics,
		name, namespace)
	if err != nil {
		return nil, err
	}

	eventList, err := GetReplicationControllerEvents(client, dataselect.DefaultDataSelect, namespace, name)
	if err != nil {
		return nil, err
	}

	serviceList, err := GetReplicationControllerServices(client, dataselect.DefaultDataSelect, namespace,
		name)
	if err != nil {
		return nil, err
	}

	hpas, err := horizontalpodautoscalerlist.GetHorizontalPodAutoscalerListForResource(client, namespace, "ReplicationController", name)
	if err != nil {
		return nil, err
	}

	replicationControllerDetail := ToReplicationControllerDetail(replicationController, *podInfo,
		*podList, *eventList, *serviceList, *hpas)
	return &replicationControllerDetail, nil
}
Exemplo n.º 2
0
// GetReplicaSetDetail gets replica set details.
func GetReplicaSetDetail(client k8sClient.Interface, heapsterClient client.HeapsterClient,
	namespace, name string) (*ReplicaSetDetail, error) {
	log.Printf("Getting details of %s service in %s namespace", name, namespace)

	// TODO(floreks): Use channels.
	replicaSetData, err := client.Extensions().ReplicaSets(namespace).Get(name)
	if err != nil {
		return nil, err
	}

	eventList, err := GetReplicaSetEvents(client, dataselect.DefaultDataSelect, replicaSetData.Namespace, replicaSetData.Name)
	if err != nil {
		return nil, err
	}

	podList, err := GetReplicaSetPods(client, heapsterClient, dataselect.DefaultDataSelectWithMetrics, name, namespace)
	if err != nil {
		return nil, err
	}

	podInfo, err := getReplicaSetPodInfo(client, replicaSetData)
	if err != nil {
		return nil, err
	}

	serviceList, err := GetReplicaSetServices(client, dataselect.DefaultDataSelect, namespace, name)
	if err != nil {
		return nil, err
	}

	hpas, err := horizontalpodautoscalerlist.GetHorizontalPodAutoscalerListForResource(client, namespace, "ReplicaSet", name)
	if err != nil {
		return nil, err
	}

	replicaSet := ToReplicaSetDetail(replicaSetData, *eventList, *podList, *podInfo, *serviceList, *hpas)
	return &replicaSet, nil
}
Exemplo n.º 3
0
// 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,
			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
	}
	// Horizontal Pod Autoscalers
	hpas, err := horizontalpodautoscalerlist.GetHorizontalPodAutoscalerListForResource(client, namespace, "Deployment", 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
	rawRepSets := make([]*extensions.ReplicaSet, 0)
	for i := range rawRs.Items {
		rawRepSets = append(rawRepSets, &rawRs.Items[i])
	}
	newRs, err := deploymentutil.FindNewReplicaSet(deployment, rawRepSets)
	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,
		HorizontalPodAutoscalerList: *hpas,
	}, nil

}