Skip to content

Commit

Permalink
Merge pull request #227 from soltysh/bug1785513
Browse files Browse the repository at this point in the history
Bug 1785513: fix describe for HPA
  • Loading branch information
openshift-merge-robot committed Dec 21, 2019
2 parents c3b30a1 + 5a9378a commit e3fe0dd
Showing 1 changed file with 3 additions and 46 deletions.
49 changes: 3 additions & 46 deletions pkg/helpers/describe/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"k8s.io/kubectl/pkg/describe"
"k8s.io/kubectl/pkg/describe/versioned"
"k8s.io/kubectl/pkg/scheme"
"k8s.io/kubernetes/pkg/apis/autoscaling"

"github.com/openshift/api/apps"
appsv1 "github.com/openshift/api/apps/v1"
Expand Down Expand Up @@ -340,59 +339,17 @@ func printAutoscalingInfo(res []schema.GroupResource, namespace, name string, kc

for _, hpa := range scaledBy {
fmt.Fprintf(w, "Autoscaling:\tbetween %d and %d replicas", *hpa.Spec.MinReplicas, hpa.Spec.MaxReplicas)
// TODO: Replace this with external HPA
legacyHpa := &autoscaling.HorizontalPodAutoscaler{}
if err := scheme.Scheme.Convert(&hpa, legacyHpa, nil); err != nil {
panic(err)
}
targetDescriptions := formatHPATargets(legacyHpa)
if len(targetDescriptions) == 1 {
fmt.Fprintf(w, " targeting %s\n", targetDescriptions[0])
if hpa.Spec.TargetCPUUtilizationPercentage != nil {
fmt.Fprintf(w, " targeting %d%% CPU over all the pods\n", *hpa.Spec.TargetCPUUtilizationPercentage)
} else {
fmt.Fprintf(w, "\n")
for _, description := range targetDescriptions {
// NB(directxman12): we should *not* use the wording "triggered at" here.
// The HPA is *not* threshold-based. Rather, it "aims" for a particular load,
// quasi-constantly scaling the replica count by the ratio of current to target.
fmt.Fprintf(w, "\t targeting %s\n", description)
}
fmt.Fprint(w, " (default autoscaling policy)\n")
}
// TODO: Print a warning in case of multiple hpas.
// Related oc status PR: https://github.com/openshift/origin/pull/7799
break
}
}

// formatHPATargets formats a list of HPA targets in human readable form. It functions similarly to the
// upstream describer and printer, except that it doesn't include status information, so it's more compact.
func formatHPATargets(hpa *autoscaling.HorizontalPodAutoscaler) []string {
descriptions := make([]string, len(hpa.Spec.Metrics))
for i, metricSpec := range hpa.Spec.Metrics {
switch metricSpec.Type {
case autoscaling.PodsMetricSourceType:
descriptions[i] = fmt.Sprintf("%s %s average per pod", metricSpec.Pods.Target.AverageValue.String(), metricSpec.Pods.Metric.Name)
case autoscaling.ObjectMetricSourceType:
// TODO: it'd probably be more accurate if we put the group in here too,
// but it might be a bit to verbose to read at a glance
// TODO: we might want to use the resource name here instead of the kind?
targetObjDesc := fmt.Sprintf("%s %s", metricSpec.Object.Target.Type, metricSpec.Object.Metric.Name)
descriptions[i] = fmt.Sprintf("%s %s on %s", metricSpec.Object.Target.Value.String(), metricSpec.Object.Metric.Name, targetObjDesc)
case autoscaling.ResourceMetricSourceType:
if metricSpec.Resource.Target.AverageValue != nil {
descriptions[i] = fmt.Sprintf("%s %s average per pod", metricSpec.Resource.Target.AverageValue.String(), metricSpec.Resource.Name)
} else if metricSpec.Resource.Target.AverageUtilization != nil {
descriptions[i] = fmt.Sprintf("%d%% %s average per pod", *metricSpec.Resource.Target.AverageUtilization, metricSpec.Resource.Name)
} else {
descriptions[i] = "<unset resource metric>"
}
default:
descriptions[i] = "<unknown metric type>"
}
}

return descriptions
}

func printDeploymentRc(deployment *corev1.ReplicationController, kubeClient kubernetes.Interface, w io.Writer, header string, verbose bool) error {
if len(header) > 0 {
fmt.Fprintf(w, "%v:\n", header)
Expand Down

0 comments on commit e3fe0dd

Please sign in to comment.