@@ -338,7 +338,7 @@ func (a *HorizontalController) computeReplicasForMetrics(ctx context.Context, hp
338
338
// return an error and set the condition of the hpa based on the first invalid metric.
339
339
// Otherwise set the condition as scaling active as we're going to scale
340
340
if invalidMetricsCount >= len (metricSpecs ) || (invalidMetricsCount > 0 && replicas < specReplicas ) {
341
- setCondition (hpa , invalidMetricCondition .Type , invalidMetricCondition .Status , invalidMetricCondition .Reason , invalidMetricCondition .Message )
341
+ setCondition (hpa , invalidMetricCondition .Type , invalidMetricCondition .Status , invalidMetricCondition .Reason , "%s" , invalidMetricCondition .Message )
342
342
return - 1 , "" , statuses , time.Time {}, invalidMetricError
343
343
}
344
344
setCondition (hpa , autoscalingv2 .ScalingActive , v1 .ConditionTrue , "ValidMetricFound" , "the HPA was able to successfully calculate a replica count from %s" , metric )
@@ -385,15 +385,15 @@ func (a *HorizontalController) validateAndParseSelector(hpa *autoscalingv2.Horiz
385
385
errMsg := "selector is required"
386
386
a .eventRecorder .Event (hpa , v1 .EventTypeWarning , "SelectorRequired" , errMsg )
387
387
setCondition (hpa , autoscalingv2 .ScalingActive , v1 .ConditionFalse , "InvalidSelector" , "the HPA target's scale is missing a selector" )
388
- return nil , fmt . Errorf (errMsg )
388
+ return nil , errors . New (errMsg )
389
389
}
390
390
391
391
parsedSelector , err := labels .Parse (selector )
392
392
if err != nil {
393
393
errMsg := fmt .Sprintf ("couldn't convert selector into a corresponding internal selector object: %v" , err )
394
394
a .eventRecorder .Event (hpa , v1 .EventTypeWarning , "InvalidSelector" , errMsg )
395
- setCondition (hpa , autoscalingv2 .ScalingActive , v1 .ConditionFalse , "InvalidSelector" , errMsg )
396
- return nil , fmt . Errorf (errMsg )
395
+ setCondition (hpa , autoscalingv2 .ScalingActive , v1 .ConditionFalse , "InvalidSelector" , "%s" , errMsg )
396
+ return nil , errors . New (errMsg )
397
397
}
398
398
399
399
hpaKey := selectors.Key {Name : hpa .Name , Namespace : hpa .Namespace }
@@ -413,8 +413,8 @@ func (a *HorizontalController) validateAndParseSelector(hpa *autoscalingv2.Horiz
413
413
if len (selectingHpas ) > 1 {
414
414
errMsg := fmt .Sprintf ("pods by selector %v are controlled by multiple HPAs: %v" , selector , selectingHpas )
415
415
a .eventRecorder .Event (hpa , v1 .EventTypeWarning , "AmbiguousSelector" , errMsg )
416
- setCondition (hpa , autoscalingv2 .ScalingActive , v1 .ConditionFalse , "AmbiguousSelector" , errMsg )
417
- return nil , fmt . Errorf (errMsg )
416
+ setCondition (hpa , autoscalingv2 .ScalingActive , v1 .ConditionFalse , "AmbiguousSelector" , "%s" , errMsg )
417
+ return nil , errors . New (errMsg )
418
418
}
419
419
420
420
return parsedSelector , nil
@@ -570,7 +570,7 @@ func (a *HorizontalController) computeStatusForObjectMetric(specReplicas, status
570
570
return replicaCountProposal , timestampProposal , fmt .Sprintf ("external metric %s(%+v)" , metricSpec .Object .Metric .Name , metricSpec .Object .Metric .Selector ), autoscalingv2.HorizontalPodAutoscalerCondition {}, nil
571
571
}
572
572
errMsg := "invalid object metric source: neither a value target nor an average value target was set"
573
- err = fmt . Errorf (errMsg )
573
+ err = errors . New (errMsg )
574
574
condition = a .getUnableComputeReplicaCountCondition (hpa , "FailedGetObjectMetric" , err )
575
575
return 0 , time.Time {}, "" , condition , err
576
576
}
@@ -617,7 +617,7 @@ func (a *HorizontalController) computeStatusForResourceMetricGeneric(ctx context
617
617
618
618
if target .AverageUtilization == nil {
619
619
errMsg := "invalid resource metric source: neither an average utilization target nor an average value (usage) target was set"
620
- return 0 , nil , time.Time {}, "" , condition , fmt . Errorf (errMsg )
620
+ return 0 , nil , time.Time {}, "" , condition , errors . New (errMsg )
621
621
}
622
622
623
623
targetUtilization := * target .AverageUtilization
@@ -719,9 +719,9 @@ func (a *HorizontalController) computeStatusForExternalMetric(specReplicas, stat
719
719
return replicaCountProposal , timestampProposal , fmt .Sprintf ("external metric %s(%+v)" , metricSpec .External .Metric .Name , metricSpec .External .Metric .Selector ), autoscalingv2.HorizontalPodAutoscalerCondition {}, nil
720
720
}
721
721
errMsg := "invalid external metric source: neither a value target nor an average value target was set"
722
- err = fmt . Errorf (errMsg )
722
+ err = errors . New (errMsg )
723
723
condition = a .getUnableComputeReplicaCountCondition (hpa , "FailedGetExternalMetric" , err )
724
- return 0 , time.Time {}, "" , condition , fmt . Errorf (errMsg )
724
+ return 0 , time.Time {}, "" , condition , errors . New (errMsg )
725
725
}
726
726
727
727
func (a * HorizontalController ) recordInitialRecommendation (currentReplicas int32 , key string ) {
@@ -950,12 +950,12 @@ func (a *HorizontalController) normalizeDesiredReplicas(hpa *autoscalingv2.Horiz
950
950
setCondition (hpa , autoscalingv2 .AbleToScale , v1 .ConditionTrue , "ReadyForNewScale" , "recommended size matches current size" )
951
951
}
952
952
953
- desiredReplicas , condition , reason := convertDesiredReplicasWithRules (currentReplicas , stabilizedRecommendation , minReplicas , hpa .Spec .MaxReplicas )
953
+ desiredReplicas , reason , message := convertDesiredReplicasWithRules (currentReplicas , stabilizedRecommendation , minReplicas , hpa .Spec .MaxReplicas )
954
954
955
955
if desiredReplicas == stabilizedRecommendation {
956
- setCondition (hpa , autoscalingv2 .ScalingLimited , v1 .ConditionFalse , condition , reason )
956
+ setCondition (hpa , autoscalingv2 .ScalingLimited , v1 .ConditionFalse , reason , "%s" , message )
957
957
} else {
958
- setCondition (hpa , autoscalingv2 .ScalingLimited , v1 .ConditionTrue , condition , reason )
958
+ setCondition (hpa , autoscalingv2 .ScalingLimited , v1 .ConditionTrue , reason , "%s" , message )
959
959
}
960
960
961
961
return desiredReplicas
@@ -991,15 +991,15 @@ func (a *HorizontalController) normalizeDesiredReplicasWithBehaviors(hpa *autosc
991
991
normalizationArg .DesiredReplicas = stabilizedRecommendation
992
992
if stabilizedRecommendation != prenormalizedDesiredReplicas {
993
993
// "ScaleUpStabilized" || "ScaleDownStabilized"
994
- setCondition (hpa , autoscalingv2 .AbleToScale , v1 .ConditionTrue , reason , message )
994
+ setCondition (hpa , autoscalingv2 .AbleToScale , v1 .ConditionTrue , reason , "%s" , message )
995
995
} else {
996
996
setCondition (hpa , autoscalingv2 .AbleToScale , v1 .ConditionTrue , "ReadyForNewScale" , "recommended size matches current size" )
997
997
}
998
998
desiredReplicas , reason , message := a .convertDesiredReplicasWithBehaviorRate (normalizationArg )
999
999
if desiredReplicas == stabilizedRecommendation {
1000
- setCondition (hpa , autoscalingv2 .ScalingLimited , v1 .ConditionFalse , reason , message )
1000
+ setCondition (hpa , autoscalingv2 .ScalingLimited , v1 .ConditionFalse , reason , "%s" , message )
1001
1001
} else {
1002
- setCondition (hpa , autoscalingv2 .ScalingLimited , v1 .ConditionTrue , reason , message )
1002
+ setCondition (hpa , autoscalingv2 .ScalingLimited , v1 .ConditionTrue , reason , "%s" , message )
1003
1003
}
1004
1004
1005
1005
return desiredReplicas
0 commit comments