mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +00:00
Fix unmarshaling into internal version of CustomMetricTargetList in validation
This commit is contained in:
parent
3654d63766
commit
6676bab9c3
@ -22,7 +22,7 @@ import (
|
|||||||
apivalidation "k8s.io/kubernetes/pkg/api/validation"
|
apivalidation "k8s.io/kubernetes/pkg/api/validation"
|
||||||
pathvalidation "k8s.io/kubernetes/pkg/api/validation/path"
|
pathvalidation "k8s.io/kubernetes/pkg/api/validation/path"
|
||||||
"k8s.io/kubernetes/pkg/apis/autoscaling"
|
"k8s.io/kubernetes/pkg/apis/autoscaling"
|
||||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
"k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
|
||||||
"k8s.io/kubernetes/pkg/controller/podautoscaler"
|
"k8s.io/kubernetes/pkg/controller/podautoscaler"
|
||||||
"k8s.io/kubernetes/pkg/util/validation/field"
|
"k8s.io/kubernetes/pkg/util/validation/field"
|
||||||
)
|
)
|
||||||
@ -87,7 +87,7 @@ func validateHorizontalPodAutoscalerAnnotations(annotations map[string]string, f
|
|||||||
allErrs := field.ErrorList{}
|
allErrs := field.ErrorList{}
|
||||||
if annotationValue, found := annotations[podautoscaler.HpaCustomMetricsTargetAnnotationName]; found {
|
if annotationValue, found := annotations[podautoscaler.HpaCustomMetricsTargetAnnotationName]; found {
|
||||||
// Try to parse the annotation
|
// Try to parse the annotation
|
||||||
var targetList extensions.CustomMetricTargetList
|
var targetList v1beta1.CustomMetricTargetList
|
||||||
if err := json.Unmarshal([]byte(annotationValue), &targetList); err != nil {
|
if err := json.Unmarshal([]byte(annotationValue), &targetList); err != nil {
|
||||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("annotations"), annotations, "failed to parse custom metrics target annotation"))
|
allErrs = append(allErrs, field.Invalid(fldPath.Child("annotations"), annotations, "failed to parse custom metrics target annotation"))
|
||||||
} else {
|
} else {
|
||||||
|
@ -26,7 +26,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api/resource"
|
"k8s.io/kubernetes/pkg/api/resource"
|
||||||
"k8s.io/kubernetes/pkg/api/v1"
|
"k8s.io/kubernetes/pkg/api/v1"
|
||||||
autoscaling "k8s.io/kubernetes/pkg/apis/autoscaling/v1"
|
autoscaling "k8s.io/kubernetes/pkg/apis/autoscaling/v1"
|
||||||
extensions "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
|
extensionsv1beta1 "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
|
||||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||||
"k8s.io/kubernetes/pkg/client/cache"
|
"k8s.io/kubernetes/pkg/client/cache"
|
||||||
unversionedautoscaling "k8s.io/kubernetes/pkg/client/clientset_generated/release_1_5/typed/autoscaling/v1"
|
unversionedautoscaling "k8s.io/kubernetes/pkg/client/clientset_generated/release_1_5/typed/autoscaling/v1"
|
||||||
@ -144,7 +144,7 @@ func getLastScaleTime(hpa *autoscaling.HorizontalPodAutoscaler) time.Time {
|
|||||||
return lastScaleTime.Time
|
return lastScaleTime.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *HorizontalController) computeReplicasForCPUUtilization(hpa *autoscaling.HorizontalPodAutoscaler, scale *extensions.Scale) (int32, *int32, time.Time, error) {
|
func (a *HorizontalController) computeReplicasForCPUUtilization(hpa *autoscaling.HorizontalPodAutoscaler, scale *extensionsv1beta1.Scale) (int32, *int32, time.Time, error) {
|
||||||
targetUtilization := int32(defaultTargetCPUUtilizationPercentage)
|
targetUtilization := int32(defaultTargetCPUUtilizationPercentage)
|
||||||
if hpa.Spec.TargetCPUUtilizationPercentage != nil {
|
if hpa.Spec.TargetCPUUtilizationPercentage != nil {
|
||||||
targetUtilization = *hpa.Spec.TargetCPUUtilizationPercentage
|
targetUtilization = *hpa.Spec.TargetCPUUtilizationPercentage
|
||||||
@ -190,7 +190,7 @@ func (a *HorizontalController) computeReplicasForCPUUtilization(hpa *autoscaling
|
|||||||
// Returns number of replicas, metric which required highest number of replicas,
|
// Returns number of replicas, metric which required highest number of replicas,
|
||||||
// status string (also json-serialized extensions.CustomMetricsCurrentStatusList),
|
// status string (also json-serialized extensions.CustomMetricsCurrentStatusList),
|
||||||
// last timestamp of the metrics involved in computations or error, if occurred.
|
// last timestamp of the metrics involved in computations or error, if occurred.
|
||||||
func (a *HorizontalController) computeReplicasForCustomMetrics(hpa *autoscaling.HorizontalPodAutoscaler, scale *extensions.Scale,
|
func (a *HorizontalController) computeReplicasForCustomMetrics(hpa *autoscaling.HorizontalPodAutoscaler, scale *extensionsv1beta1.Scale,
|
||||||
cmAnnotation string) (replicas int32, metric string, status string, timestamp time.Time, err error) {
|
cmAnnotation string) (replicas int32, metric string, status string, timestamp time.Time, err error) {
|
||||||
|
|
||||||
if cmAnnotation == "" {
|
if cmAnnotation == "" {
|
||||||
@ -199,7 +199,7 @@ func (a *HorizontalController) computeReplicasForCustomMetrics(hpa *autoscaling.
|
|||||||
|
|
||||||
currentReplicas := scale.Status.Replicas
|
currentReplicas := scale.Status.Replicas
|
||||||
|
|
||||||
var targetList extensions.CustomMetricTargetList
|
var targetList extensionsv1beta1.CustomMetricTargetList
|
||||||
if err := json.Unmarshal([]byte(cmAnnotation), &targetList); err != nil {
|
if err := json.Unmarshal([]byte(cmAnnotation), &targetList); err != nil {
|
||||||
a.eventRecorder.Event(hpa, v1.EventTypeWarning, "FailedParseCustomMetricsAnnotation", err.Error())
|
a.eventRecorder.Event(hpa, v1.EventTypeWarning, "FailedParseCustomMetricsAnnotation", err.Error())
|
||||||
return 0, "", "", time.Time{}, fmt.Errorf("failed to parse custom metrics annotation: %v", err)
|
return 0, "", "", time.Time{}, fmt.Errorf("failed to parse custom metrics annotation: %v", err)
|
||||||
@ -209,8 +209,8 @@ func (a *HorizontalController) computeReplicasForCustomMetrics(hpa *autoscaling.
|
|||||||
return 0, "", "", time.Time{}, fmt.Errorf("no custom metrics in annotation")
|
return 0, "", "", time.Time{}, fmt.Errorf("no custom metrics in annotation")
|
||||||
}
|
}
|
||||||
|
|
||||||
statusList := extensions.CustomMetricCurrentStatusList{
|
statusList := extensionsv1beta1.CustomMetricCurrentStatusList{
|
||||||
Items: make([]extensions.CustomMetricCurrentStatus, 0),
|
Items: make([]extensionsv1beta1.CustomMetricCurrentStatus, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, customMetricTarget := range targetList.Items {
|
for _, customMetricTarget := range targetList.Items {
|
||||||
@ -249,7 +249,7 @@ func (a *HorizontalController) computeReplicasForCustomMetrics(hpa *autoscaling.
|
|||||||
a.eventRecorder.Event(hpa, v1.EventTypeWarning, "FailedSetCustomMetrics", err.Error())
|
a.eventRecorder.Event(hpa, v1.EventTypeWarning, "FailedSetCustomMetrics", err.Error())
|
||||||
return 0, "", "", time.Time{}, fmt.Errorf("failed to set custom metric value: %v", err)
|
return 0, "", "", time.Time{}, fmt.Errorf("failed to set custom metric value: %v", err)
|
||||||
}
|
}
|
||||||
statusList.Items = append(statusList.Items, extensions.CustomMetricCurrentStatus{
|
statusList.Items = append(statusList.Items, extensionsv1beta1.CustomMetricCurrentStatus{
|
||||||
Name: customMetricTarget.Name,
|
Name: customMetricTarget.Name,
|
||||||
CurrentValue: quantity,
|
CurrentValue: quantity,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user