Update printers to include changes from autoscaling/v2beta2

This commit is contained in:
Mike Dame 2018-06-28 14:33:31 -04:00
parent e31eff092f
commit 17740a2857
4 changed files with 316 additions and 170 deletions

View File

@ -2972,50 +2972,50 @@ func describeHorizontalPodAutoscaler(hpa *autoscaling.HorizontalPodAutoscaler, e
for i, metric := range hpa.Spec.Metrics {
switch metric.Type {
case autoscaling.ExternalMetricSourceType:
if metric.External.TargetAverageValue != nil {
if metric.External.Target.AverageValue != nil {
current := "<unknown>"
if len(hpa.Status.CurrentMetrics) > i && hpa.Status.CurrentMetrics[i].External != nil &&
hpa.Status.CurrentMetrics[i].External.CurrentAverageValue != nil {
current = hpa.Status.CurrentMetrics[i].External.CurrentAverageValue.String()
&hpa.Status.CurrentMetrics[i].External.Current.AverageValue != nil {
current = hpa.Status.CurrentMetrics[i].External.Current.AverageValue.String()
}
w.Write(LEVEL_1, "%q (target average value):\t%s / %s\n", metric.External.MetricName, current, metric.External.TargetAverageValue.String())
w.Write(LEVEL_1, "%q (target average value):\t%s / %s\n", metric.External.Metric.Name, current, metric.External.Target.AverageValue.String())
} else {
current := "<unknown>"
if len(hpa.Status.CurrentMetrics) > i && hpa.Status.CurrentMetrics[i].External != nil {
current = hpa.Status.CurrentMetrics[i].External.CurrentValue.String()
current = hpa.Status.CurrentMetrics[i].External.Current.Value.String()
}
w.Write(LEVEL_1, "%q (target value):\t%s / %s\n", metric.External.MetricName, current, metric.External.TargetValue.String())
w.Write(LEVEL_1, "%q (target value):\t%s / %s\n", metric.External.Metric.Name, current, metric.External.Target.Value.String())
}
case autoscaling.PodsMetricSourceType:
current := "<unknown>"
if len(hpa.Status.CurrentMetrics) > i && hpa.Status.CurrentMetrics[i].Pods != nil {
current = hpa.Status.CurrentMetrics[i].Pods.CurrentAverageValue.String()
current = hpa.Status.CurrentMetrics[i].Pods.Current.AverageValue.String()
}
w.Write(LEVEL_1, "%q on pods:\t%s / %s\n", metric.Pods.MetricName, current, metric.Pods.TargetAverageValue.String())
w.Write(LEVEL_1, "%q on pods:\t%s / %s\n", metric.Pods.Metric.Name, current, metric.Pods.Target.AverageValue.String())
case autoscaling.ObjectMetricSourceType:
current := "<unknown>"
if len(hpa.Status.CurrentMetrics) > i && hpa.Status.CurrentMetrics[i].Object != nil {
current = hpa.Status.CurrentMetrics[i].Object.CurrentValue.String()
current = hpa.Status.CurrentMetrics[i].Object.Current.Value.String()
}
w.Write(LEVEL_1, "%q on %s/%s:\t%s / %s\n", metric.Object.MetricName, metric.Object.Target.Kind, metric.Object.Target.Name, current, metric.Object.TargetValue.String())
w.Write(LEVEL_1, "%q on %s/%s:\t%s / %s\n", metric.Object.Metric.Name, metric.Object.DescribedObject.Kind, metric.Object.DescribedObject.Name, current, metric.Object.Target.Value.String())
case autoscaling.ResourceMetricSourceType:
w.Write(LEVEL_1, "resource %s on pods", string(metric.Resource.Name))
if metric.Resource.TargetAverageValue != nil {
if metric.Resource.Target.AverageValue != nil {
current := "<unknown>"
if len(hpa.Status.CurrentMetrics) > i && hpa.Status.CurrentMetrics[i].Resource != nil {
current = hpa.Status.CurrentMetrics[i].Resource.CurrentAverageValue.String()
current = hpa.Status.CurrentMetrics[i].Resource.Current.AverageValue.String()
}
w.Write(LEVEL_0, ":\t%s / %s\n", current, metric.Resource.TargetAverageValue.String())
w.Write(LEVEL_0, ":\t%s / %s\n", current, metric.Resource.Target.AverageValue.String())
} else {
current := "<unknown>"
if len(hpa.Status.CurrentMetrics) > i && hpa.Status.CurrentMetrics[i].Resource != nil && hpa.Status.CurrentMetrics[i].Resource.CurrentAverageUtilization != nil {
current = fmt.Sprintf("%d%% (%s)", *hpa.Status.CurrentMetrics[i].Resource.CurrentAverageUtilization, hpa.Status.CurrentMetrics[i].Resource.CurrentAverageValue.String())
if len(hpa.Status.CurrentMetrics) > i && hpa.Status.CurrentMetrics[i].Resource != nil && hpa.Status.CurrentMetrics[i].Resource.Current.AverageUtilization != nil {
current = fmt.Sprintf("%d%% (%s)", *hpa.Status.CurrentMetrics[i].Resource.Current.AverageUtilization, hpa.Status.CurrentMetrics[i].Resource.Current.AverageValue.String())
}
target := "<auto>"
if metric.Resource.TargetAverageUtilization != nil {
target = fmt.Sprintf("%d%%", *metric.Resource.TargetAverageUtilization)
if metric.Resource.Target.AverageUtilization != nil {
target = fmt.Sprintf("%d%%", *metric.Resource.Target.AverageUtilization)
}
w.Write(LEVEL_1, "(as a percentage of request):\t%s / %s\n", current, target)
}

View File

@ -1483,6 +1483,10 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
minReplicasVal := int32(2)
targetUtilizationVal := int32(80)
currentUtilizationVal := int32(50)
metricLabelSelector, err := metav1.ParseToLabelSelector("label=value")
if err != nil {
t.Errorf("unable to parse label selector: %v", err)
}
tests := []struct {
name string
hpa autoscaling.HorizontalPodAutoscaler
@ -1517,13 +1521,14 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
{
Type: autoscaling.ExternalMetricSourceType,
External: &autoscaling.ExternalMetricSource{
MetricSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"label": "value",
},
Metric: autoscaling.MetricIdentifier{
Name: "some-external-metric",
Selector: metricLabelSelector,
},
Target: autoscaling.MetricTarget{
Type: autoscaling.AverageValueMetricType,
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
MetricName: "some-external-metric",
TargetAverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
@ -1548,13 +1553,14 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
{
Type: autoscaling.ExternalMetricSourceType,
External: &autoscaling.ExternalMetricSource{
MetricSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"label": "value",
},
Metric: autoscaling.MetricIdentifier{
Name: "some-external-metric",
Selector: metricLabelSelector,
},
Target: autoscaling.MetricTarget{
Type: autoscaling.AverageValueMetricType,
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
MetricName: "some-external-metric",
TargetAverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
@ -1566,13 +1572,13 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
{
Type: autoscaling.ExternalMetricSourceType,
External: &autoscaling.ExternalMetricStatus{
MetricSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"label": "value",
},
Metric: autoscaling.MetricIdentifier{
Name: "some-external-metric",
Selector: metricLabelSelector,
},
Current: autoscaling.MetricValueStatus{
AverageValue: resource.NewMilliQuantity(50, resource.DecimalSI),
},
MetricName: "some-external-metric",
CurrentAverageValue: resource.NewMilliQuantity(50, resource.DecimalSI),
},
},
},
@ -1593,13 +1599,14 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
{
Type: autoscaling.ExternalMetricSourceType,
External: &autoscaling.ExternalMetricSource{
MetricSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"label": "value",
},
Metric: autoscaling.MetricIdentifier{
Name: "some-external-metric",
Selector: metricLabelSelector,
},
Target: autoscaling.MetricTarget{
Type: autoscaling.ValueMetricType,
Value: resource.NewMilliQuantity(100, resource.DecimalSI),
},
MetricName: "some-external-metric",
TargetValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
@ -1624,13 +1631,14 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
{
Type: autoscaling.ExternalMetricSourceType,
External: &autoscaling.ExternalMetricSource{
MetricSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"label": "value",
},
Metric: autoscaling.MetricIdentifier{
Name: "some-external-metric",
Selector: metricLabelSelector,
},
Target: autoscaling.MetricTarget{
Type: autoscaling.ValueMetricType,
Value: resource.NewMilliQuantity(100, resource.DecimalSI),
},
MetricName: "some-external-metric",
TargetValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
@ -1642,13 +1650,13 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
{
Type: autoscaling.ExternalMetricSourceType,
External: &autoscaling.ExternalMetricStatus{
MetricSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"label": "value",
},
Metric: autoscaling.MetricIdentifier{
Name: "some-external-metric",
Selector: metricLabelSelector,
},
Current: autoscaling.MetricValueStatus{
Value: resource.NewMilliQuantity(50, resource.DecimalSI),
},
MetricName: "some-external-metric",
CurrentValue: *resource.NewMilliQuantity(50, resource.DecimalSI),
},
},
},
@ -1669,8 +1677,13 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
{
Type: autoscaling.PodsMetricSourceType,
Pods: &autoscaling.PodsMetricSource{
MetricName: "some-pods-metric",
TargetAverageValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
Metric: autoscaling.MetricIdentifier{
Name: "some-pods-metric",
},
Target: autoscaling.MetricTarget{
Type: autoscaling.AverageValueMetricType,
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
},
@ -1695,8 +1708,13 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
{
Type: autoscaling.PodsMetricSourceType,
Pods: &autoscaling.PodsMetricSource{
MetricName: "some-pods-metric",
TargetAverageValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
Metric: autoscaling.MetricIdentifier{
Name: "some-pods-metric",
},
Target: autoscaling.MetricTarget{
Type: autoscaling.AverageValueMetricType,
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
},
@ -1708,8 +1726,12 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
{
Type: autoscaling.PodsMetricSourceType,
Pods: &autoscaling.PodsMetricStatus{
MetricName: "some-pods-metric",
CurrentAverageValue: *resource.NewMilliQuantity(50, resource.DecimalSI),
Metric: autoscaling.MetricIdentifier{
Name: "some-pods-metric",
},
Current: autoscaling.MetricValueStatus{
AverageValue: resource.NewMilliQuantity(50, resource.DecimalSI),
},
},
},
},
@ -1730,12 +1752,17 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
{
Type: autoscaling.ObjectMetricSourceType,
Object: &autoscaling.ObjectMetricSource{
Target: autoscaling.CrossVersionObjectReference{
DescribedObject: autoscaling.CrossVersionObjectReference{
Name: "some-service",
Kind: "Service",
},
MetricName: "some-service-metric",
TargetValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
Metric: autoscaling.MetricIdentifier{
Name: "some-service-metric",
},
Target: autoscaling.MetricTarget{
Type: autoscaling.ValueMetricType,
Value: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
},
@ -1760,12 +1787,17 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
{
Type: autoscaling.ObjectMetricSourceType,
Object: &autoscaling.ObjectMetricSource{
Target: autoscaling.CrossVersionObjectReference{
DescribedObject: autoscaling.CrossVersionObjectReference{
Name: "some-service",
Kind: "Service",
},
MetricName: "some-service-metric",
TargetValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
Metric: autoscaling.MetricIdentifier{
Name: "some-service-metric",
},
Target: autoscaling.MetricTarget{
Type: autoscaling.ValueMetricType,
Value: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
},
@ -1777,12 +1809,16 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
{
Type: autoscaling.ObjectMetricSourceType,
Object: &autoscaling.ObjectMetricStatus{
Target: autoscaling.CrossVersionObjectReference{
DescribedObject: autoscaling.CrossVersionObjectReference{
Name: "some-service",
Kind: "Service",
},
MetricName: "some-service-metric",
CurrentValue: *resource.NewMilliQuantity(50, resource.DecimalSI),
Metric: autoscaling.MetricIdentifier{
Name: "some-service-metric",
},
Current: autoscaling.MetricValueStatus{
Value: resource.NewMilliQuantity(50, resource.DecimalSI),
},
},
},
},
@ -1803,8 +1839,11 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
{
Type: autoscaling.ResourceMetricSourceType,
Resource: &autoscaling.ResourceMetricSource{
Name: api.ResourceCPU,
TargetAverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
Name: api.ResourceCPU,
Target: autoscaling.MetricTarget{
Type: autoscaling.AverageValueMetricType,
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
},
@ -1829,8 +1868,11 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
{
Type: autoscaling.ResourceMetricSourceType,
Resource: &autoscaling.ResourceMetricSource{
Name: api.ResourceCPU,
TargetAverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
Name: api.ResourceCPU,
Target: autoscaling.MetricTarget{
Type: autoscaling.AverageValueMetricType,
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
},
@ -1842,8 +1884,10 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
{
Type: autoscaling.ResourceMetricSourceType,
Resource: &autoscaling.ResourceMetricStatus{
Name: api.ResourceCPU,
CurrentAverageValue: *resource.NewMilliQuantity(50, resource.DecimalSI),
Name: api.ResourceCPU,
Current: autoscaling.MetricValueStatus{
AverageValue: resource.NewMilliQuantity(50, resource.DecimalSI),
},
},
},
},
@ -1865,7 +1909,10 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
Type: autoscaling.ResourceMetricSourceType,
Resource: &autoscaling.ResourceMetricSource{
Name: api.ResourceCPU,
TargetAverageUtilization: &targetUtilizationVal,
Target: autoscaling.MetricTarget{
Type: autoscaling.UtilizationMetricType,
AverageUtilization: &targetUtilizationVal,
},
},
},
},
@ -1891,7 +1938,10 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
Type: autoscaling.ResourceMetricSourceType,
Resource: &autoscaling.ResourceMetricSource{
Name: api.ResourceCPU,
TargetAverageUtilization: &targetUtilizationVal,
Target: autoscaling.MetricTarget{
Type: autoscaling.UtilizationMetricType,
AverageUtilization: &targetUtilizationVal,
},
},
},
},
@ -1904,8 +1954,10 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
Type: autoscaling.ResourceMetricSourceType,
Resource: &autoscaling.ResourceMetricStatus{
Name: api.ResourceCPU,
CurrentAverageUtilization: &currentUtilizationVal,
CurrentAverageValue: *resource.NewMilliQuantity(40, resource.DecimalSI),
Current: autoscaling.MetricValueStatus{
AverageUtilization: &currentUtilizationVal,
AverageValue: resource.NewMilliQuantity(40, resource.DecimalSI),
},
},
},
},
@ -1926,22 +1978,35 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
{
Type: autoscaling.PodsMetricSourceType,
Pods: &autoscaling.PodsMetricSource{
MetricName: "some-pods-metric",
TargetAverageValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
Metric: autoscaling.MetricIdentifier{
Name: "some-pods-metric",
},
Target: autoscaling.MetricTarget{
Type: autoscaling.AverageValueMetricType,
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
{
Type: autoscaling.ResourceMetricSourceType,
Resource: &autoscaling.ResourceMetricSource{
Name: api.ResourceCPU,
TargetAverageUtilization: &targetUtilizationVal,
Target: autoscaling.MetricTarget{
Type: autoscaling.UtilizationMetricType,
AverageUtilization: &targetUtilizationVal,
},
},
},
{
Type: autoscaling.PodsMetricSourceType,
Pods: &autoscaling.PodsMetricSource{
MetricName: "other-pods-metric",
TargetAverageValue: *resource.NewMilliQuantity(400, resource.DecimalSI),
Metric: autoscaling.MetricIdentifier{
Name: "other-pods-metric",
},
Target: autoscaling.MetricTarget{
Type: autoscaling.AverageValueMetricType,
AverageValue: resource.NewMilliQuantity(400, resource.DecimalSI),
},
},
},
},
@ -1953,16 +2018,22 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
{
Type: autoscaling.PodsMetricSourceType,
Pods: &autoscaling.PodsMetricStatus{
MetricName: "some-pods-metric",
CurrentAverageValue: *resource.NewMilliQuantity(50, resource.DecimalSI),
Metric: autoscaling.MetricIdentifier{
Name: "some-pods-metric",
},
Current: autoscaling.MetricValueStatus{
AverageValue: resource.NewMilliQuantity(50, resource.DecimalSI),
},
},
},
{
Type: autoscaling.ResourceMetricSourceType,
Resource: &autoscaling.ResourceMetricStatus{
Name: api.ResourceCPU,
CurrentAverageUtilization: &currentUtilizationVal,
CurrentAverageValue: *resource.NewMilliQuantity(40, resource.DecimalSI),
Current: autoscaling.MetricValueStatus{
AverageUtilization: &currentUtilizationVal,
AverageValue: resource.NewMilliQuantity(40, resource.DecimalSI),
},
},
},
},

View File

@ -1580,47 +1580,47 @@ func formatHPAMetrics(specs []autoscaling.MetricSpec, statuses []autoscaling.Met
for i, spec := range specs {
switch spec.Type {
case autoscaling.ExternalMetricSourceType:
if spec.External.TargetAverageValue != nil {
if spec.External.Target.AverageValue != nil {
current := "<unknown>"
if len(statuses) > i && statuses[i].External != nil && statuses[i].External.CurrentAverageValue != nil {
current = statuses[i].External.CurrentAverageValue.String()
if len(statuses) > i && statuses[i].External != nil && &statuses[i].External.Current.AverageValue != nil {
current = statuses[i].External.Current.AverageValue.String()
}
list = append(list, fmt.Sprintf("%s/%s (avg)", current, spec.External.TargetAverageValue.String()))
list = append(list, fmt.Sprintf("%s/%s (avg)", current, spec.External.Target.AverageValue.String()))
} else {
current := "<unknown>"
if len(statuses) > i && statuses[i].External != nil {
current = statuses[i].External.CurrentValue.String()
current = statuses[i].External.Current.Value.String()
}
list = append(list, fmt.Sprintf("%s/%s", current, spec.External.TargetValue.String()))
list = append(list, fmt.Sprintf("%s/%s", current, spec.External.Target.Value.String()))
}
case autoscaling.PodsMetricSourceType:
current := "<unknown>"
if len(statuses) > i && statuses[i].Pods != nil {
current = statuses[i].Pods.CurrentAverageValue.String()
current = statuses[i].Pods.Current.AverageValue.String()
}
list = append(list, fmt.Sprintf("%s/%s", current, spec.Pods.TargetAverageValue.String()))
list = append(list, fmt.Sprintf("%s/%s", current, spec.Pods.Target.AverageValue.String()))
case autoscaling.ObjectMetricSourceType:
current := "<unknown>"
if len(statuses) > i && statuses[i].Object != nil {
current = statuses[i].Object.CurrentValue.String()
current = statuses[i].Object.Current.Value.String()
}
list = append(list, fmt.Sprintf("%s/%s", current, spec.Object.TargetValue.String()))
list = append(list, fmt.Sprintf("%s/%s", current, spec.Object.Target.Value.String()))
case autoscaling.ResourceMetricSourceType:
if spec.Resource.TargetAverageValue != nil {
if spec.Resource.Target.AverageValue != nil {
current := "<unknown>"
if len(statuses) > i && statuses[i].Resource != nil {
current = statuses[i].Resource.CurrentAverageValue.String()
current = statuses[i].Resource.Current.AverageValue.String()
}
list = append(list, fmt.Sprintf("%s/%s", current, spec.Resource.TargetAverageValue.String()))
list = append(list, fmt.Sprintf("%s/%s", current, spec.Resource.Target.AverageValue.String()))
} else {
current := "<unknown>"
if len(statuses) > i && statuses[i].Resource != nil && statuses[i].Resource.CurrentAverageUtilization != nil {
current = fmt.Sprintf("%d%%", *statuses[i].Resource.CurrentAverageUtilization)
if len(statuses) > i && statuses[i].Resource != nil && statuses[i].Resource.Current.AverageUtilization != nil {
current = fmt.Sprintf("%d%%", *statuses[i].Resource.Current.AverageUtilization)
}
target := "<auto>"
if spec.Resource.TargetAverageUtilization != nil {
target = fmt.Sprintf("%d%%", *spec.Resource.TargetAverageUtilization)
if spec.Resource.Target.AverageUtilization != nil {
target = fmt.Sprintf("%d%%", *spec.Resource.Target.AverageUtilization)
}
list = append(list, fmt.Sprintf("%s/%s", current, target))
}

View File

@ -2172,6 +2172,10 @@ func TestPrintHPA(t *testing.T) {
minReplicasVal := int32(2)
targetUtilizationVal := int32(80)
currentUtilizationVal := int32(50)
metricLabelSelector, err := metav1.ParseToLabelSelector("label=value")
if err != nil {
t.Errorf("unable to parse label selector: %v", err)
}
tests := []struct {
hpa autoscaling.HorizontalPodAutoscaler
expected string
@ -2209,13 +2213,14 @@ func TestPrintHPA(t *testing.T) {
{
Type: autoscaling.ExternalMetricSourceType,
External: &autoscaling.ExternalMetricSource{
MetricSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"label": "value",
},
Metric: autoscaling.MetricIdentifier{
Name: "some-external-metric",
Selector: metricLabelSelector,
},
Target: autoscaling.MetricTarget{
Type: autoscaling.AverageValueMetricType,
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
MetricName: "some-external-metric",
TargetAverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
@ -2242,13 +2247,14 @@ func TestPrintHPA(t *testing.T) {
{
Type: autoscaling.ExternalMetricSourceType,
External: &autoscaling.ExternalMetricSource{
MetricSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"label": "value",
},
Metric: autoscaling.MetricIdentifier{
Name: "some-external-metric",
Selector: metricLabelSelector,
},
Target: autoscaling.MetricTarget{
Type: autoscaling.AverageValueMetricType,
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
MetricName: "some-external-metric",
TargetAverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
@ -2260,13 +2266,13 @@ func TestPrintHPA(t *testing.T) {
{
Type: autoscaling.ExternalMetricSourceType,
External: &autoscaling.ExternalMetricStatus{
MetricSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"label": "value",
},
Metric: autoscaling.MetricIdentifier{
Name: "some-external-metric",
Selector: metricLabelSelector,
},
Current: autoscaling.MetricValueStatus{
AverageValue: resource.NewMilliQuantity(50, resource.DecimalSI),
},
MetricName: "some-external-metric",
CurrentAverageValue: resource.NewMilliQuantity(50, resource.DecimalSI),
},
},
},
@ -2289,13 +2295,14 @@ func TestPrintHPA(t *testing.T) {
{
Type: autoscaling.ExternalMetricSourceType,
External: &autoscaling.ExternalMetricSource{
MetricSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"label": "value",
},
Metric: autoscaling.MetricIdentifier{
Name: "some-service-metric",
Selector: metricLabelSelector,
},
Target: autoscaling.MetricTarget{
Type: autoscaling.ValueMetricType,
Value: resource.NewMilliQuantity(100, resource.DecimalSI),
},
MetricName: "some-service-metric",
TargetValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
@ -2322,13 +2329,14 @@ func TestPrintHPA(t *testing.T) {
{
Type: autoscaling.ExternalMetricSourceType,
External: &autoscaling.ExternalMetricSource{
MetricSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"label": "value",
},
Metric: autoscaling.MetricIdentifier{
Name: "some-external-metric",
Selector: metricLabelSelector,
},
Target: autoscaling.MetricTarget{
Type: autoscaling.ValueMetricType,
Value: resource.NewMilliQuantity(100, resource.DecimalSI),
},
MetricName: "some-external-metric",
TargetValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
@ -2340,8 +2348,12 @@ func TestPrintHPA(t *testing.T) {
{
Type: autoscaling.ExternalMetricSourceType,
External: &autoscaling.ExternalMetricStatus{
MetricName: "some-external-metric",
CurrentValue: *resource.NewMilliQuantity(50, resource.DecimalSI),
Metric: autoscaling.MetricIdentifier{
Name: "some-external-metric",
},
Current: autoscaling.MetricValueStatus{
Value: resource.NewMilliQuantity(50, resource.DecimalSI),
},
},
},
},
@ -2364,8 +2376,13 @@ func TestPrintHPA(t *testing.T) {
{
Type: autoscaling.PodsMetricSourceType,
Pods: &autoscaling.PodsMetricSource{
MetricName: "some-pods-metric",
TargetAverageValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
Metric: autoscaling.MetricIdentifier{
Name: "some-pods-metric",
},
Target: autoscaling.MetricTarget{
Type: autoscaling.AverageValueMetricType,
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
},
@ -2392,8 +2409,13 @@ func TestPrintHPA(t *testing.T) {
{
Type: autoscaling.PodsMetricSourceType,
Pods: &autoscaling.PodsMetricSource{
MetricName: "some-pods-metric",
TargetAverageValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
Metric: autoscaling.MetricIdentifier{
Name: "some-pods-metric",
},
Target: autoscaling.MetricTarget{
Type: autoscaling.AverageValueMetricType,
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
},
@ -2405,8 +2427,12 @@ func TestPrintHPA(t *testing.T) {
{
Type: autoscaling.PodsMetricSourceType,
Pods: &autoscaling.PodsMetricStatus{
MetricName: "some-pods-metric",
CurrentAverageValue: *resource.NewMilliQuantity(50, resource.DecimalSI),
Metric: autoscaling.MetricIdentifier{
Name: "some-pods-metric",
},
Current: autoscaling.MetricValueStatus{
AverageValue: resource.NewMilliQuantity(50, resource.DecimalSI),
},
},
},
},
@ -2429,12 +2455,17 @@ func TestPrintHPA(t *testing.T) {
{
Type: autoscaling.ObjectMetricSourceType,
Object: &autoscaling.ObjectMetricSource{
Target: autoscaling.CrossVersionObjectReference{
DescribedObject: autoscaling.CrossVersionObjectReference{
Name: "some-service",
Kind: "Service",
},
MetricName: "some-service-metric",
TargetValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
Metric: autoscaling.MetricIdentifier{
Name: "some-service-metric",
},
Target: autoscaling.MetricTarget{
Type: autoscaling.ValueMetricType,
Value: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
},
@ -2461,12 +2492,17 @@ func TestPrintHPA(t *testing.T) {
{
Type: autoscaling.ObjectMetricSourceType,
Object: &autoscaling.ObjectMetricSource{
Target: autoscaling.CrossVersionObjectReference{
DescribedObject: autoscaling.CrossVersionObjectReference{
Name: "some-service",
Kind: "Service",
},
MetricName: "some-service-metric",
TargetValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
Metric: autoscaling.MetricIdentifier{
Name: "some-service-metric",
},
Target: autoscaling.MetricTarget{
Type: autoscaling.ValueMetricType,
Value: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
},
@ -2478,12 +2514,16 @@ func TestPrintHPA(t *testing.T) {
{
Type: autoscaling.ObjectMetricSourceType,
Object: &autoscaling.ObjectMetricStatus{
Target: autoscaling.CrossVersionObjectReference{
DescribedObject: autoscaling.CrossVersionObjectReference{
Name: "some-service",
Kind: "Service",
},
MetricName: "some-service-metric",
CurrentValue: *resource.NewMilliQuantity(50, resource.DecimalSI),
Metric: autoscaling.MetricIdentifier{
Name: "some-service-metric",
},
Current: autoscaling.MetricValueStatus{
Value: resource.NewMilliQuantity(50, resource.DecimalSI),
},
},
},
},
@ -2506,8 +2546,11 @@ func TestPrintHPA(t *testing.T) {
{
Type: autoscaling.ResourceMetricSourceType,
Resource: &autoscaling.ResourceMetricSource{
Name: api.ResourceCPU,
TargetAverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
Name: api.ResourceCPU,
Target: autoscaling.MetricTarget{
Type: autoscaling.AverageValueMetricType,
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
},
@ -2534,8 +2577,11 @@ func TestPrintHPA(t *testing.T) {
{
Type: autoscaling.ResourceMetricSourceType,
Resource: &autoscaling.ResourceMetricSource{
Name: api.ResourceCPU,
TargetAverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
Name: api.ResourceCPU,
Target: autoscaling.MetricTarget{
Type: autoscaling.AverageValueMetricType,
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
},
@ -2547,8 +2593,10 @@ func TestPrintHPA(t *testing.T) {
{
Type: autoscaling.ResourceMetricSourceType,
Resource: &autoscaling.ResourceMetricStatus{
Name: api.ResourceCPU,
CurrentAverageValue: *resource.NewMilliQuantity(50, resource.DecimalSI),
Name: api.ResourceCPU,
Current: autoscaling.MetricValueStatus{
AverageValue: resource.NewMilliQuantity(50, resource.DecimalSI),
},
},
},
},
@ -2572,7 +2620,10 @@ func TestPrintHPA(t *testing.T) {
Type: autoscaling.ResourceMetricSourceType,
Resource: &autoscaling.ResourceMetricSource{
Name: api.ResourceCPU,
TargetAverageUtilization: &targetUtilizationVal,
Target: autoscaling.MetricTarget{
Type: autoscaling.UtilizationMetricType,
AverageUtilization: &targetUtilizationVal,
},
},
},
},
@ -2600,7 +2651,10 @@ func TestPrintHPA(t *testing.T) {
Type: autoscaling.ResourceMetricSourceType,
Resource: &autoscaling.ResourceMetricSource{
Name: api.ResourceCPU,
TargetAverageUtilization: &targetUtilizationVal,
Target: autoscaling.MetricTarget{
Type: autoscaling.UtilizationMetricType,
AverageUtilization: &targetUtilizationVal,
},
},
},
},
@ -2613,8 +2667,10 @@ func TestPrintHPA(t *testing.T) {
Type: autoscaling.ResourceMetricSourceType,
Resource: &autoscaling.ResourceMetricStatus{
Name: api.ResourceCPU,
CurrentAverageUtilization: &currentUtilizationVal,
CurrentAverageValue: *resource.NewMilliQuantity(40, resource.DecimalSI),
Current: autoscaling.MetricValueStatus{
AverageUtilization: &currentUtilizationVal,
AverageValue: resource.NewMilliQuantity(40, resource.DecimalSI),
},
},
},
},
@ -2637,22 +2693,35 @@ func TestPrintHPA(t *testing.T) {
{
Type: autoscaling.PodsMetricSourceType,
Pods: &autoscaling.PodsMetricSource{
MetricName: "some-pods-metric",
TargetAverageValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
Metric: autoscaling.MetricIdentifier{
Name: "some-pods-metric",
},
Target: autoscaling.MetricTarget{
Type: autoscaling.AverageValueMetricType,
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
},
},
},
{
Type: autoscaling.ResourceMetricSourceType,
Resource: &autoscaling.ResourceMetricSource{
Name: api.ResourceCPU,
TargetAverageUtilization: &targetUtilizationVal,
Target: autoscaling.MetricTarget{
Type: autoscaling.UtilizationMetricType,
AverageUtilization: &targetUtilizationVal,
},
},
},
{
Type: autoscaling.PodsMetricSourceType,
Pods: &autoscaling.PodsMetricSource{
MetricName: "other-pods-metric",
TargetAverageValue: *resource.NewMilliQuantity(400, resource.DecimalSI),
Metric: autoscaling.MetricIdentifier{
Name: "other-pods-metric",
},
Target: autoscaling.MetricTarget{
Type: autoscaling.AverageValueMetricType,
AverageValue: resource.NewMilliQuantity(400, resource.DecimalSI),
},
},
},
},
@ -2664,16 +2733,22 @@ func TestPrintHPA(t *testing.T) {
{
Type: autoscaling.PodsMetricSourceType,
Pods: &autoscaling.PodsMetricStatus{
MetricName: "some-pods-metric",
CurrentAverageValue: *resource.NewMilliQuantity(50, resource.DecimalSI),
Metric: autoscaling.MetricIdentifier{
Name: "some-pods-metric",
},
Current: autoscaling.MetricValueStatus{
AverageValue: resource.NewMilliQuantity(50, resource.DecimalSI),
},
},
},
{
Type: autoscaling.ResourceMetricSourceType,
Resource: &autoscaling.ResourceMetricStatus{
Name: api.ResourceCPU,
CurrentAverageUtilization: &currentUtilizationVal,
CurrentAverageValue: *resource.NewMilliQuantity(40, resource.DecimalSI),
Current: autoscaling.MetricValueStatus{
AverageUtilization: &currentUtilizationVal,
AverageValue: resource.NewMilliQuantity(40, resource.DecimalSI),
},
},
},
},