// GetRawResourceReplicas calculates the desired replica count based on a target resource utilization (as a raw milli-value)
// for pods matching the given selector in the given namespace, and the current replica count
14950
func (c *ReplicaCalculator) GetRawResourceReplicas(currentReplicas int32, targetUtilization int64, resource v1.ResourceName, namespace string, selector labels.Selector) (replicaCount int32, utilization int64, timestamp time.Time, err error) {
	metrics, timestamp, err := c.metricsClient.GetResourceMetric(resource, namespace, selector)
	if err != nil {
		return 0, 0, time.Time{}, fmt.Errorf("unable to get metrics for resource %s: %v", resource, err)
	}

	replicaCount, utilization, err = c.calcPlainMetricReplicas(metrics, currentReplicas, targetUtilization, namespace, selector, resource)
	return replicaCount, utilization, timestamp, err
}
548883
func getResourcesAndSelector(args []string) (resources []string, selector *metav1.LabelSelector, err error) {
	if len(args) == 0 {
		return []string{}, nil, nil
	}
	resources = args[:len(args)-1]
	selector, err = metav1.ParseToLabelSelector(args[len(args)-1])
	return resources, selector, err
}
67977
func (t *Template) GetAllAWSECSServiceResources() map[string]*resources.AWSECSService {
	results := map[string]*resources.AWSECSService{}
	for name, untyped := range t.Resources {
		switch resource := untyped.(type) {
		case *resources.AWSECSService:
			results[name] = resource
		}
	}
	return results
}
377146
func (p Protos) GetResources() (map[string]*resource.Resource, error) {

	resources := Resources{}
	resourcesReq, err := http.NewRequest("GET", p.createURL("resource/provider"), nil)
	if err != nil {
		return resources, err
	}

	payload, err := p.makeRequest(resourcesReq)
	if err != nil {
		return resources, err
	}

	err = json.Unmarshal(payload, &resources)
	if err != nil {
		return resources, err
	}

	return resources, nil
}
1357170
func (t *Template) GetAllAWSECRRepositoryResources() map[string]*resources.AWSECRRepository {
	results := map[string]*resources.AWSECRRepository{}
	for name, untyped := range t.Resources {
		switch resource := untyped.(type) {
		case *resources.AWSECRRepository:
			results[name] = resource
		}
	}
	return results
}
399694
func (t *Template) GetAllAWSCodeDeployApplicationResources() map[string]*resources.AWSCodeDeployApplication {
	results := map[string]*resources.AWSCodeDeployApplication{}
	for name, untyped := range t.Resources {
		switch resource := untyped.(type) {
		case *resources.AWSCodeDeployApplication:
			results[name] = resource
		}
	}
	return results
}
347955
func (t *Template) GetAllAWSAthenaNamedQueryResources() map[string]*resources.AWSAthenaNamedQuery {
	results := map[string]*resources.AWSAthenaNamedQuery{}
	for name, untyped := range t.Resources {
		switch resource := untyped.(type) {
		case *resources.AWSAthenaNamedQuery:
			results[name] = resource
		}
	}
	return results
}
962382
func (t *Template) GetAllAWSServiceDiscoveryInstanceResources() map[string]*resources.AWSServiceDiscoveryInstance {
	results := map[string]*resources.AWSServiceDiscoveryInstance{}
	for name, untyped := range t.Resources {
		switch resource := untyped.(type) {
		case *resources.AWSServiceDiscoveryInstance:
			results[name] = resource
		}
	}
	return results
}
493524
func GetResourceName(res Resource) string {
	switch v := res.(type) {
	case *v2.ClusterLoadAssignment:
		return v.GetClusterName()
	case *v2.Cluster:
		return v.GetName()
	case *v2.RouteConfiguration:
		return v.GetName()
	case *v2.Listener:
		return v.GetName()
	case *auth.Secret:
		return v.GetName()
	default:
		return ""
	}
}
1170376
func GetAvailablePodsForReplicaSets(c clientset.Interface, rss []*extensions.ReplicaSet, minReadySeconds int) (int, error) {
	allPods, err := GetPodsForReplicaSets(c, rss)
	if err != nil {
		return 0, err
	}
	return getReadyPodsCount(allPods, minReadySeconds), nil
}
333324
func (t *Template) GetAllAWSEMRStepResources() map[string]*resources.AWSEMRStep {
	results := map[string]*resources.AWSEMRStep{}
	for name, untyped := range t.Resources {
		switch resource := untyped.(type) {
		case *resources.AWSEMRStep:
			results[name] = resource
		}
	}
	return results
}
271352
func (az *Cloud) GetResourceGroups() (sets.String, error) {
	// Kubelet won't set az.nodeInformerSynced, always return configured resourceGroup.
	if az.nodeInformerSynced == nil {
		return sets.NewString(az.ResourceGroup), nil
	}

	az.nodeCachesLock.Lock()
	defer az.nodeCachesLock.Unlock()
	if !az.nodeInformerSynced() {
		return nil, fmt.Errorf("node informer is not synced when trying to GetResourceGroups")
	}

	resourceGroups := sets.NewString(az.ResourceGroup)
	for _, rg := range az.nodeResourceGroups {
		resourceGroups.Insert(rg)
	}

	return resourceGroups, nil
}
739610
func GetActualReplicaCountForReplicaSets(replicaSets []*apps.ReplicaSet) int32 {
	totalActualReplicas := int32(0)
	for _, rs := range replicaSets {
		if rs != nil {
			totalActualReplicas += rs.Status.Replicas
		}
	}
	return totalActualReplicas
}
662571
func GetAvailableReplicaCountForReplicationControllers(replicationControllers []*v1.ReplicationController) int32 {
	totalAvailableReplicas := int32(0)
	for _, rc := range replicationControllers {
		if rc != nil {
			totalAvailableReplicas += rc.Status.AvailableReplicas
		}
	}
	return totalAvailableReplicas
}
274984
func (rsc *ReplicaSetController) getPodReplicaSets(pod *v1.Pod) []*apps.ReplicaSet {
	rss, err := rsc.rsLister.GetPodReplicaSets(pod)
	if err != nil {
		return nil
	}
	if len(rss) > 1 {
		// ControllerRef will ensure we don't do anything crazy, but more than one
		// item in this list nevertheless constitutes user error.
		utilruntime.HandleError(fmt.Errorf("user error! more than one %v is selecting pods with labels: %+v", rsc.Kind, pod.Labels))
	}
	return rss
}
352674
func (c *ReplicaCalculator) GetExternalPerPodMetricReplicas(currentReplicas int32, targetUtilizationPerPod int64, metricName, namespace string, metricSelector *metav1.LabelSelector) (replicaCount int32, utilization int64, timestamp time.Time, err error) {
	metricLabelSelector, err := metav1.LabelSelectorAsSelector(metricSelector)
	if err != nil {
		return 0, 0, time.Time{}, err
	}
	metrics, timestamp, err := c.metricsClient.GetExternalMetric(metricName, namespace, metricLabelSelector)
	if err != nil {
		return 0, 0, time.Time{}, fmt.Errorf("unable to get external metric %s/%s/%+v: %s", namespace, metricName, metricSelector, err)
	}
	utilization = 0
	for _, val := range metrics {
		utilization = utilization + val
	}

	replicaCount = currentReplicas
	usageRatio := float64(utilization) / (float64(targetUtilizationPerPod) * float64(replicaCount))
	if math.Abs(1.0-usageRatio) > c.tolerance {
		// update number of replicas if the change is large enough
		replicaCount = int32(math.Ceil(float64(utilization) / float64(targetUtilizationPerPod)))
	}
	utilization = int64(math.Ceil(float64(utilization) / float64(currentReplicas)))
	return replicaCount, utilization, timestamp, nil
}
1269124
func (t *Template) GetAllAWSRDSDBClusterResources() map[string]*resources.AWSRDSDBCluster {
	results := map[string]*resources.AWSRDSDBCluster{}
	for name, untyped := range t.Resources {
		switch resource := untyped.(type) {
		case *resources.AWSRDSDBCluster:
			results[name] = resource
		}
	}
	return results
}