Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1785513: fix describe for HPA #227

Merged
merged 1 commit into from
Dec 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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