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
Cannot update HPA objects using object metrics with AverageValue #87733
Comments
/sig autoscaling |
An update: this doesn't only affect the |
k8s 1.17.2 also meet this error, is this a bug? |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Encountering the same error, are there any updates? |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Rotten issues close after 30d of inactivity. Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
@fejta-bot: Closing this issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/reopen |
@garimakemwal: You can't reopen an issue/PR unless you authored it or you are a collaborator. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Encountering the same issue, it breaks our CI pipeline. Can we reopen this? |
We have this issue as well. Would be cool to at least reopen it. |
Have the same issue :( |
@egoroof: You can't reopen an issue/PR unless you authored it or you are a collaborator. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Hitting this issue as well. There is a workaround tho kubectl edit hpa.v2beta2.autoscaling <your-hpa> Then spot every After that, you can freely edit w/e you want from the rest of the document. The bad news, the |
Btw hitting this on both K8s |
same problem here, and the workaround outlined above doesn't work either. |
My hypothesis is that when the control plane attempts to persist the object in k8s and convert the v2beta2 object to v1, it does so by storing the new interface in annotation. While doing so, it considers "value" as a required attribute and initialized it to 0. This later becomes an issue when we get back the yaml through the v2beta2 endpoint, which transforms the object back into a v2 object, now with both the "value" and "AverageValue" key. This is still appearing in 1.21 as well. What is the best way to get this re-opened? |
/reopen |
@szuecs: Reopened this issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/remove-lifecycle rotten |
@szuecs: Reopened this issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Also hit this problem on v1.22.10. |
I meet the same question in k8s 1.22 , and debug it when create v2beta2 hpa apiVersion: autoscaling/v2beta2 kind: HorizontalPodAutoscaler metadata: name: sample-app namespace: default spec: maxReplicas: 10 metrics: - object: describedObject: kind: Service name: sample-app metric: name: http_requests_count target: averageValue: "1" type: AverageValue type: Object minReplicas: 7 scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: sample-app and the object send to kube-apiserver , and v2beta2 hpa convert to internal hpa object. when read the internal hpa obj to v1 hpa obj, because metrics switch to annotation to the v1 hpa object, we can found the annotaion apiVersion: autoscaling/v1 kind: HorizontalPodAutoscaler metadata: annotations: autoscaling.alpha.kubernetes.io/conditions: '[{"type":"AbleToScale","status":"False","lastTransitionTime":"2022-09-29T12:31:03Z","reason":"FailedGetScale","message":"the HPA controller was unable to get the target''s current scale: deployments/scale.apps \"sample-app\" not found"}]' autoscaling.alpha.kubernetes.io/metrics: '[{"type":"Object","object":{"target":{"kind":"Service","name":"sample-app"},"metricName":"http_requests_count","targetValue":"0","averageValue":"1"}}]' creationTimestamp: "2022-09-29T12:30:48Z" name: sample-app namespace: default resourceVersion: "9314762" in annotion exist "targetValue":"0" In v1 hpa define in vendor/k8s.io/api/autoscaling/v1/types.go:227, the TargetValue is resource.Quantity type. type ObjectMetricSource struct { // target is the described Kubernetes object. Target CrossVersionObjectReference `json:"target" protobuf:"bytes,1,name=target"` // metricName is the name of the metric in question. MetricName string `json:"metricName" protobuf:"bytes,2,name=metricName"` // targetValue is the target value of the metric (as a quantity). TargetValue resource.Quantity `json:"targetValue" protobuf:"bytes,3,name=targetValue"`` --- } and in v2beta2 hpa define in vendor/k8s.io/api/autoscaling/v2beta2/types.go:320, the TargetValue is *resource.Quantity type. // MetricTarget defines the target value, average value, or average utilization of a specific metric type MetricTarget struct { // type represents whether the metric type is Utilization, Value, or AverageValue Type MetricTargetType `json:"type" protobuf:"bytes,1,name=type"` // value is the target value of the metric (as a quantity). // +optional Value *resource.Quantity `json:"value,omitempty" protobuf:"bytes,2,opt,name=value"` // averageValue is the target value of the average of the // metric across all relevant pods (as a quantity) // +optional AverageValue *resource.Quantity `json:"averageValue,omitempty" protobuf:"bytes,3,opt,name=averageValue"` // averageUtilization is the target value of the average of the // resource metric across all relevant pods, represented as a percentage of // the requested value of the resource for the pods. // Currently only valid for Resource metric source type // +optional AverageUtilization *int32 `json:"averageUtilization,omitempty" protobuf:"bytes,4,opt,name=averageUtilization"` } the TargetValue is not * v1, and in v2beta2 hpa TargetValue is *. then , the annotation of v1 hpa object will convert to internal hpa object, the "targetValue":"0" in anntation be convert to internal hpa object, the target value is set to 0 not the nil debug the problem in k8s 1.22.9 can fix the problem diff --git a/pkg/apis/autoscaling/v1/conversion.go b/pkg/apis/autoscaling/v1/conversion.go index bf94d48ae17..09fd8f9f337 100644 --- a/pkg/apis/autoscaling/v1/conversion.go +++ b/pkg/apis/autoscaling/v1/conversion.go @@ -90,9 +90,13 @@ func Convert_v1_ObjectMetricSource_To_autoscaling_ObjectMetricSource(in *autosca out.Target = autoscaling.MetricTarget{ Type: metricType, - Value: &in.TargetValue, AverageValue: in.AverageValue, } + + if in.TargetValue.Value() != 0 { + out.Target.Value = &in.TargetValue + } + out.DescribedObject = autoscaling.CrossVersionObjectReference{ Kind: in.Target.Kind, Name: in.Target.Name, |
Would be great to know if the problem also affects v2 API. |
/triage accepted |
Issue is replicated in both autoscaling/v2 and autoscaling/v2 versions. Server Version: v1.25.2 Error
|
/assign @abhisek00 |
Unfortunatelly, this workaround not very aplicable for our workflow with automated HPA updates. So I just set |
I'm trying to workaround this as well and I'm adding
And it seems issue is "fixed" with such spec.
Is it expected? However, there is no more error about
anymore on patching. @Zaporozhec7 can you share how you set |
I set spec.metrics[0].object.target.value to "1" on HPA creation/update (Helm chart). |
so you doing like this? |
Based on docs
So you need to modify custom metric value by dividing it to number of pods to have hpa working same way as with |
I using AverageValue target type, not Value - this is all about what this issue is. For AverageValue target type "averageValue" property used, "value" property is just ignored by AverageValue target type. My metric object look like this:
Your example above have different schema, it seems you are using different API version of HPA |
Thx @Zaporozhec7 . |
@pbetkier , you asked at some point if this affects v2 - I'm afraid it does (and @Zaporozhec7 already confirmed this too). What's worse, I just noticed that the objects gets mangled by using the 'averageValue' workaround.
What I get back by
But it looks like it's a different issue than the one originally raised, w/o setting averageValue I get:
|
Replying to my own comment - Value is simply not supported for Resource metrics. Sorry for the confusion. |
Note: the issue affects HPAs created under k8s prior to 1.27. I believe #114358 fixed this for 1.27. HPAs created before 1.27 need to be recreated (e.g. reapply |
Is there an update to this problem? We were using v2beta2 and switched to v2. We now get the same error we apply a helm deployment to the service that has an HPA with an Object resource. We've deleted all the HPA's manually and redeploying with helm works. Except its building the Object reference like this
If we try to do a helm upgrade install after this to the same service, it fails with the same error. The work around suggested by setting the value of |
What happened:
When attempting to label a HorizontalPodAutoscaler (autoscaling/v2beta2) object that has an object metric using
AverageValue
, received the following error:The HorizontalPodAutoscaler "<hpa-name>" is invalid: spec.metrics[0].object.target.value: Invalid value: resource.Quantity{i:resource.int64Amount{value:0, scale:0}, d:resource.infDecAmount{Dec:(*inf.Dec)(nil)}, s:"0", Format:"DecimalSI"}: must be positive
What you expected to happen:
The
label
command should properly label the HPA object with no errors, since the HPA was able to build and run without errors.How to reproduce it (as minimally and precisely as possible):
Make sure that you're using
AverageValue
and don't have aValue
set.Anything else we need to know?:
We were able to build and apply the HPA object without encountering any errors, and it appears to be scaling properly. This error only happens when calling
kubectl label
on the existing HPA object.Environment:
kubectl version
): tried in both 1.15.3 and 1.16.4cat /etc/os-release
): darwin/amd64uname -a
): Darwin Kernel Version 17.7.0: Fri Jul 6 19:54:51 PDT 2018; root:xnu-4570.71.3~2/RELEASE_X86_64 x86_64The text was updated successfully, but these errors were encountered: