Updated errors handling for updateHPAs method
Signed-off-by: Anatolii Dutchak <adutchak-x@tunein.com>
This commit is contained in:
1
go.mod
1
go.mod
@ -4,6 +4,7 @@ require (
|
||||
github.com/NYTimes/gziphandler v1.0.1 // indirect
|
||||
github.com/aws/aws-sdk-go v1.37.20
|
||||
github.com/go-openapi/spec v0.20.3
|
||||
github.com/hashicorp/go-multierror v1.0.0
|
||||
github.com/influxdata/influxdb-client-go v0.2.0
|
||||
github.com/influxdata/line-protocol v0.0.0-20201012155213-5f565037cbc9 // indirect
|
||||
github.com/kubernetes-sigs/custom-metrics-apiserver v0.0.0-20201216091021-1b9fa998bbaa
|
||||
|
2
go.sum
2
go.sum
@ -290,10 +290,12 @@ github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBt
|
||||
github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
|
||||
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
|
||||
github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
|
||||
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
|
||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
||||
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
||||
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
|
||||
github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o=
|
||||
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
|
||||
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
|
||||
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
kube_record "k8s.io/client-go/tools/record"
|
||||
"k8s.io/metrics/pkg/apis/custom_metrics"
|
||||
"k8s.io/metrics/pkg/apis/external_metrics"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -128,6 +129,9 @@ func (p *HPAProvider) updateHPAs() error {
|
||||
|
||||
newHPAs := 0
|
||||
|
||||
// Multi errors object used in loops where they have to continue but in the end an error should be reported
|
||||
var errs error
|
||||
|
||||
for _, hpa := range hpas.Items {
|
||||
hpa := *hpa.DeepCopy()
|
||||
resourceRef := resourceReference{
|
||||
@ -148,6 +152,7 @@ func (p *HPAProvider) updateHPAs() error {
|
||||
metricConfigs, err := collector.ParseHPAMetrics(&hpa)
|
||||
if err != nil {
|
||||
p.logger.Errorf("Failed to parse HPA metrics: %v", err)
|
||||
errs = multierror.Append(errs, err)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -164,6 +169,7 @@ func (p *HPAProvider) updateHPAs() error {
|
||||
// Only log when it's not a PluginNotFoundError AND flag disregardIncompatibleHPAs is true
|
||||
if !(errors.Is(err, &collector.PluginNotFoundError{}) && p.disregardIncompatibleHPAs) {
|
||||
p.recorder.Eventf(&hpa, apiv1.EventTypeWarning, "CreateNewMetricsCollector", "Failed to create new metrics collector: %v", err)
|
||||
errs = multierror.Append(errs, err)
|
||||
}
|
||||
|
||||
cache = false
|
||||
@ -196,7 +202,8 @@ func (p *HPAProvider) updateHPAs() error {
|
||||
|
||||
p.logger.Infof("Found %d new/updated HPA(s)", newHPAs)
|
||||
p.hpaCache = newHPACache
|
||||
return nil
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
// equalHPA returns true if two HPAs are identical (apart from their status).
|
||||
|
Reference in New Issue
Block a user