From ad413c99f175bf49a3841f181166d8821158920e Mon Sep 17 00:00:00 2001 From: "shaowei.wayne" Date: Tue, 11 Apr 2023 16:45:30 +0800 Subject: [PATCH] fix(*): fix lint errors for katalyst --- cmd/base/context.go | 5 ++-- cmd/base/options/generic.go | 2 +- .../app/options/lifecycle.go | 3 +- cmd/katalyst-controller/app/options/spd.go | 3 +- cmd/katalyst-controller/main.go | 5 +++- cmd/katalyst-metric/app/options/collector.go | 3 +- cmd/katalyst-metric/app/options/options.go | 5 ++++ cmd/katalyst-metric/app/options/store.go | 1 + cmd/katalyst-metric/main.go | 5 +++- cmd/katalyst-scheduler/app/options/options.go | 2 +- cmd/katalyst-scheduler/main.go | 1 + cmd/katalyst-webhook/app/options/pod.go | 3 +- cmd/katalyst-webhook/app/options/vpa.go | 3 +- cmd/katalyst-webhook/main.go | 5 +++- go.mod | 10 +++---- go.sum | 21 ++++++++++---- .../evictionmanager/endpoint/endpoint.go | 2 +- pkg/agent/evictionmanager/manager.go | 7 +++-- .../calculator/cpu_assignment.go | 2 +- .../cpu/dynamicpolicy/cpuadvisor/cpu.pb.go | 11 +++---- .../cpuadvisor/qos_aware_client_stub_test.go | 6 ++-- .../cpueviction/cpu_eviciton_test.go | 5 ++-- .../qrm-plugins/cpu/dynamicpolicy/policy.go | 5 +++- .../cpu/dynamicpolicy/policy_test.go | 3 +- .../cpu/dynamicpolicy/state/checkpoint.go | 2 +- .../cpu/dynamicpolicy/state/state_test.go | 11 ++++--- .../cpu/dynamicpolicy/state/util_test.go | 3 +- .../dynamicpolicy/allocation_handlers.go | 6 ++-- .../memory/dynamicpolicy/policy.go | 2 -- .../memory/dynamicpolicy/policy_test.go | 3 +- .../memory/dynamicpolicy/state/checkpoint.go | 2 +- pkg/agent/qrm-plugins/util/util.go | 18 +++++++----- pkg/agent/qrm-plugins/util/util_test.go | 3 +- .../fetcher/kubelet/kubeletplugin.go | 1 + .../kubelet/topology/podresourcesserver.go | 3 +- .../fetcher/kubelet/topology/util.go | 1 + .../resourcemanager/fetcher/manager_test.go | 8 ++--- pkg/agent/sysadvisor/metacache/checkpoint.go | 2 +- .../plugin/qosaware/reporter/reporter_test.go | 6 ++-- .../plugin/qosaware/server/cpu/cpu_server.go | 1 + .../plugin/qosaware/server/cpu/helper.go | 3 +- pkg/client/control/cnc.go | 1 + .../reclaimed_resources_eviction_plugin.go | 2 +- pkg/config/metric/collector.go | 3 +- pkg/controller/kcc/kcct.go | 3 +- pkg/controller/kcc/kcct_test.go | 7 +++-- pkg/controller/kcc/util/kcct_test.go | 2 +- pkg/controller/spd/spd_test.go | 6 ++-- .../recommenders/avg_load_to_cpu_test.go | 2 +- pkg/controller/vpa/algorithm/register.go | 3 +- pkg/controller/vpa/recommend_test.go | 2 +- pkg/controller/vpa/util/api_test.go | 2 +- pkg/controller/vpa/vpa_test.go | 6 ++-- .../prometheus/collector_promethes.go | 9 ++---- .../collector_sharding_promethes.go | 1 + .../collector/prometheus/scrape.go | 2 +- pkg/custom-metric/provider/provider.go | 1 - pkg/custom-metric/provider/provider_test.go | 29 ++++++++++--------- pkg/custom-metric/store/data/cache_test.go | 2 +- pkg/custom-metric/store/local/local_store.go | 3 +- .../store/remote/remote_store.go | 3 +- pkg/metaserver/agent/metric/malachite/cri.go | 5 ++-- pkg/metaserver/agent/pod/pod.go | 6 ++-- pkg/metaserver/config/checkpoint.go | 3 +- pkg/metaserver/config/config_test.go | 3 +- pkg/metaserver/config/manager_test.go | 3 +- pkg/metaserver/external/manager_linux_test.go | 4 ++- pkg/metaserver/spd/checkpoint/checkpoint.go | 7 +++-- pkg/metaserver/spd/manager.go | 7 +++-- pkg/metaserver/spd/manager_test.go | 3 +- .../metrics-pool/custom_metrics_pool_test.go | 1 + .../plugins/qosawarenoderesources/fit.go | 7 +++-- .../qosawarenoderesources/least_allocated.go | 2 +- .../resource_allocation.go | 3 +- pkg/util/cgroup/manager/cgroup_test.go | 4 +-- pkg/util/cgroup/manager/v2/fs_linux.go | 3 +- pkg/util/external/rdt/manager_test.go | 8 ----- pkg/util/native/pod_sorter.go | 3 +- pkg/util/native/resources.go | 4 +-- pkg/util/spd_test.go | 8 ++--- pkg/util/syntax/reflect.go | 8 +++-- pkg/util/vpa_test.go | 8 ++--- 82 files changed, 220 insertions(+), 162 deletions(-) diff --git a/cmd/base/context.go b/cmd/base/context.go index 02251f73e0..bd45d81d62 100644 --- a/cmd/base/context.go +++ b/cmd/base/context.go @@ -22,6 +22,7 @@ import ( "net/http/pprof" "time" + "github.com/prometheus/client_golang/prometheus/promhttp" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/client-go/dynamic/dynamicinformer" @@ -40,7 +41,6 @@ import ( "github.com/kubewharf/katalyst-core/pkg/util/general" "github.com/kubewharf/katalyst-core/pkg/util/native" "github.com/kubewharf/katalyst-core/pkg/util/process" - "github.com/prometheus/client_golang/prometheus/promhttp" ) const ( @@ -55,7 +55,8 @@ type GenericContext struct { httpHandler *process.HTTPHandler healthChecker *HealthzChecker - // those following components are shared by all generic components + // those following components are shared by all generic components. + //nolint BroadcastAdapter events.EventBroadcasterAdapter Client *client.GenericClientSet EmitterPool metricspool.MetricsEmitterPool diff --git a/cmd/base/options/generic.go b/cmd/base/options/generic.go index 486f9a41c3..ad2f120550 100644 --- a/cmd/base/options/generic.go +++ b/cmd/base/options/generic.go @@ -22,11 +22,11 @@ import ( "k8s.io/apimachinery/pkg/util/errors" cliflag "k8s.io/component-base/cli/flag" + componentbaseconfig "k8s.io/component-base/config" "k8s.io/klog/v2" "github.com/kubewharf/katalyst-core/pkg/config/generic" "github.com/kubewharf/katalyst-core/pkg/util/process" - componentbaseconfig "k8s.io/component-base/config" ) // GenericOptions holds the configurations for multi components. diff --git a/cmd/katalyst-controller/app/options/lifecycle.go b/cmd/katalyst-controller/app/options/lifecycle.go index 4c15b8f590..c317b4820d 100644 --- a/cmd/katalyst-controller/app/options/lifecycle.go +++ b/cmd/katalyst-controller/app/options/lifecycle.go @@ -19,8 +19,9 @@ package options import ( "time" - "github.com/kubewharf/katalyst-core/pkg/config/controller" cliflag "k8s.io/component-base/cli/flag" + + "github.com/kubewharf/katalyst-core/pkg/config/controller" ) // LifeCycleOptions holds the configurations for life cycle. diff --git a/cmd/katalyst-controller/app/options/spd.go b/cmd/katalyst-controller/app/options/spd.go index d992bb3f5d..8708c7a169 100644 --- a/cmd/katalyst-controller/app/options/spd.go +++ b/cmd/katalyst-controller/app/options/spd.go @@ -20,8 +20,9 @@ import ( "fmt" "time" - "github.com/kubewharf/katalyst-core/pkg/config/controller" cliflag "k8s.io/component-base/cli/flag" + + "github.com/kubewharf/katalyst-core/pkg/config/controller" ) // SPDOptions holds the configurations for service profile data. diff --git a/cmd/katalyst-controller/main.go b/cmd/katalyst-controller/main.go index 95656b7643..70ad577b46 100644 --- a/cmd/katalyst-controller/main.go +++ b/cmd/katalyst-controller/main.go @@ -38,7 +38,10 @@ func main() { for _, f := range fss.FlagSets { commandLine.AddFlagSet(f) } - commandLine.Parse(os.Args[1:]) + if err := commandLine.Parse(os.Args[1:]); err != nil { + fmt.Printf("parse command error: %v\n", err) + os.Exit(1) + } rand.Seed(time.Now().UnixNano()) if err := app.Run(opt); err != nil { diff --git a/cmd/katalyst-metric/app/options/collector.go b/cmd/katalyst-metric/app/options/collector.go index fd5e559414..54b4d9b71e 100644 --- a/cmd/katalyst-metric/app/options/collector.go +++ b/cmd/katalyst-metric/app/options/collector.go @@ -18,9 +18,10 @@ package options import ( "fmt" - "k8s.io/apimachinery/pkg/labels" "time" + "k8s.io/apimachinery/pkg/labels" + cliflag "k8s.io/component-base/cli/flag" "github.com/kubewharf/katalyst-core/pkg/config/metric" diff --git a/cmd/katalyst-metric/app/options/options.go b/cmd/katalyst-metric/app/options/options.go index a0e55f03e6..ea893532ff 100644 --- a/cmd/katalyst-metric/app/options/options.go +++ b/cmd/katalyst-metric/app/options/options.go @@ -21,6 +21,7 @@ import ( "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/errors" cliflag "k8s.io/component-base/cli/flag" election "k8s.io/component-base/config" @@ -129,6 +130,10 @@ func (o *Options) ApplyTo(c *config.Configuration) error { errList = append(errList, o.StoreOptions.ApplyTo(c.StoreConfiguration)) errList = append(errList, o.ProviderOptions.ApplyTo(c.ProviderConfiguration)) errList = append(errList, o.CollectorOptions.ApplyTo(c.CollectorConfiguration)) + + if len(errList) > 0 { + return errors.NewAggregate(errList) + } return nil } diff --git a/cmd/katalyst-metric/app/options/store.go b/cmd/katalyst-metric/app/options/store.go index b207482063..4bc09fdab4 100644 --- a/cmd/katalyst-metric/app/options/store.go +++ b/cmd/katalyst-metric/app/options/store.go @@ -18,6 +18,7 @@ package options import ( "fmt" + "k8s.io/apimachinery/pkg/labels" cliflag "k8s.io/component-base/cli/flag" diff --git a/cmd/katalyst-metric/main.go b/cmd/katalyst-metric/main.go index 14d9ae661b..2d6f10d15d 100644 --- a/cmd/katalyst-metric/main.go +++ b/cmd/katalyst-metric/main.go @@ -38,7 +38,10 @@ func main() { for _, f := range fss.FlagSets { commandLine.AddFlagSet(f) } - commandLine.Parse(os.Args[1:]) + if err := commandLine.Parse(os.Args[1:]); err != nil { + fmt.Printf("parse command error: %v\n", err) + os.Exit(1) + } rand.Seed(time.Now().UnixNano()) if err := app.Run(opt); err != nil { diff --git a/cmd/katalyst-scheduler/app/options/options.go b/cmd/katalyst-scheduler/app/options/options.go index ff44fac63c..6a23e33573 100644 --- a/cmd/katalyst-scheduler/app/options/options.go +++ b/cmd/katalyst-scheduler/app/options/options.go @@ -51,7 +51,7 @@ func (o *Options) Config() (*schedulerappconfig.Config, *generic.QoSConfiguratio } qosConfig := generic.NewQoSConfiguration() - if o.QoSOptions.ApplyTo(qosConfig); err != nil { + if err = o.QoSOptions.ApplyTo(qosConfig); err != nil { return nil, nil, err } diff --git a/cmd/katalyst-scheduler/main.go b/cmd/katalyst-scheduler/main.go index b84ebfbb61..bcb2d6e86e 100644 --- a/cmd/katalyst-scheduler/main.go +++ b/cmd/katalyst-scheduler/main.go @@ -26,6 +26,7 @@ import ( "github.com/kubewharf/katalyst-core/cmd/katalyst-scheduler/app" "github.com/kubewharf/katalyst-core/pkg/scheduler/plugins/qosawarenoderesources" + // Ensure scheme package is initialized. _ "github.com/kubewharf/katalyst-api/pkg/apis/scheduling/config/scheme" ) diff --git a/cmd/katalyst-webhook/app/options/pod.go b/cmd/katalyst-webhook/app/options/pod.go index b75720d36b..ac227dc33d 100644 --- a/cmd/katalyst-webhook/app/options/pod.go +++ b/cmd/katalyst-webhook/app/options/pod.go @@ -19,8 +19,9 @@ package options import ( "fmt" - "github.com/kubewharf/katalyst-core/pkg/config/webhook" cliflag "k8s.io/component-base/cli/flag" + + "github.com/kubewharf/katalyst-core/pkg/config/webhook" ) // PodOptions holds the configurations for Pod webhook. diff --git a/cmd/katalyst-webhook/app/options/vpa.go b/cmd/katalyst-webhook/app/options/vpa.go index 06eaf0faf4..20c5adb798 100644 --- a/cmd/katalyst-webhook/app/options/vpa.go +++ b/cmd/katalyst-webhook/app/options/vpa.go @@ -17,8 +17,9 @@ limitations under the License. package options import ( - "github.com/kubewharf/katalyst-core/pkg/config/webhook" cliflag "k8s.io/component-base/cli/flag" + + "github.com/kubewharf/katalyst-core/pkg/config/webhook" ) // VPAOptions holds the configurations for VPA webhook. diff --git a/cmd/katalyst-webhook/main.go b/cmd/katalyst-webhook/main.go index e9f52ff1ee..6a125e9469 100644 --- a/cmd/katalyst-webhook/main.go +++ b/cmd/katalyst-webhook/main.go @@ -38,7 +38,10 @@ func main() { for _, f := range fss.FlagSets { commandLine.AddFlagSet(f) } - commandLine.Parse(os.Args[1:]) + if err := commandLine.Parse(os.Args[1:]); err != nil { + fmt.Printf("parse command error: %v\n", err) + os.Exit(1) + } rand.Seed(time.Now().UnixNano()) if err := app.Run(opt); err != nil { diff --git a/go.mod b/go.mod index d79dd2a2b6..4f5d3cec9c 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( go.opentelemetry.io/otel/sdk/export/metric v0.20.0 go.opentelemetry.io/otel/sdk/metric v0.20.0 go.uber.org/atomic v1.7.0 - golang.org/x/sys v0.3.0 + golang.org/x/sys v0.7.0 golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 google.golang.org/grpc v1.51.0 k8s.io/api v0.24.6 @@ -113,11 +113,11 @@ require ( go.uber.org/multierr v1.6.0 // indirect go.uber.org/zap v1.19.1 // indirect golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect - golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10 // indirect + golang.org/x/net v0.9.0 // indirect golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect - golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect - golang.org/x/term v0.3.0 // indirect - golang.org/x/text v0.5.0 // indirect + golang.org/x/sync v0.1.0 // indirect + golang.org/x/term v0.7.0 // indirect + golang.org/x/text v0.9.0 // indirect gomodules.xyz/jsonpatch/v3 v3.0.1 // indirect gomodules.xyz/orderedmap v0.1.0 // indirect google.golang.org/appengine v1.6.7 // indirect diff --git a/go.sum b/go.sum index 8b57ed9d7e..3205bb7b42 100644 --- a/go.sum +++ b/go.sum @@ -1033,6 +1033,7 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1093,8 +1094,10 @@ golang.org/x/net v0.0.0-20211209124913-491a49abca63/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10 h1:Frnccbp+ok2GkUS2tC84yAq/U9Vg+0sIO7aRL3T4Xnc= golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= +golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1123,8 +1126,9 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1218,13 +1222,17 @@ golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= +golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI= golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ= +golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1235,8 +1243,10 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM= golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -1331,6 +1341,7 @@ golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.10-0.20220218145154-897bd77cd717/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/pkg/agent/evictionmanager/endpoint/endpoint.go b/pkg/agent/evictionmanager/endpoint/endpoint.go index 35929abf04..c76a8d3b89 100644 --- a/pkg/agent/evictionmanager/endpoint/endpoint.go +++ b/pkg/agent/evictionmanager/endpoint/endpoint.go @@ -22,12 +22,12 @@ import ( "sync" "time" + "google.golang.org/grpc" "k8s.io/klog/v2" pluginapi "github.com/kubewharf/katalyst-api/pkg/protocol/evictionplugin/v1alpha1" "github.com/kubewharf/katalyst-core/pkg/consts" "github.com/kubewharf/katalyst-core/pkg/util/process" - "google.golang.org/grpc" ) const ( diff --git a/pkg/agent/evictionmanager/manager.go b/pkg/agent/evictionmanager/manager.go index 9e4faba766..48b7da89e6 100644 --- a/pkg/agent/evictionmanager/manager.go +++ b/pkg/agent/evictionmanager/manager.go @@ -24,13 +24,14 @@ import ( "sync" "time" + //nolint "github.com/golang/protobuf/proto" v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/util/clock" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/tools/events" "k8s.io/klog/v2" + clocks "k8s.io/utils/clock" "github.com/kubewharf/katalyst-api/pkg/apis/node/v1alpha1" "github.com/kubewharf/katalyst-api/pkg/plugins/registration" @@ -71,7 +72,7 @@ type EvictionManger struct { // clock is an interface that provides time related functionality in a way that makes it // easy to test the code. - clock clock.Clock + clock clocks.WithTickerAndDelayedExecution podKiller podkiller.PodKiller @@ -132,7 +133,7 @@ func NewEvictionManager(genericClient *client.GenericClientSet, recorder events. conditions: make(map[string]*pluginapi.Condition), conditionsLastObservedAt: make(map[string]conditionObservedAt), thresholdsFirstObservedAt: make(map[string]thresholdObservedAt), - clock: clock.RealClock{}, + clock: clocks.RealClock{}, genericClient: genericClient, } diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/calculator/cpu_assignment.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/calculator/cpu_assignment.go index 7fcf1d7979..3fbf64d415 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/calculator/cpu_assignment.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/calculator/cpu_assignment.go @@ -101,7 +101,7 @@ func (a *cpuAccumulator) freeCores() []int { return free } -// freeCPUs eturns free CPU IDs as a slice sorted by sortAvailableCPUs(). +// freeCPUs returns free CPU IDs as a slice sorted by sortAvailableCPUs(). func (a *cpuAccumulator) freeCPUs() []int { return a.sortAvailableCPUs() } diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor/cpu.pb.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor/cpu.pb.go index 138bb0aaac..7440859ea5 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor/cpu.pb.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor/cpu.pb.go @@ -20,18 +20,19 @@ package cpuadvisor import ( context "context" fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + reflect "reflect" + strings "strings" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" github_com_gogo_protobuf_sortkeys "github.com/gogo/protobuf/sortkeys" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" - io "io" v1alpha1 "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" - math "math" - math_bits "math/bits" - reflect "reflect" - strings "strings" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor/qos_aware_client_stub_test.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor/qos_aware_client_stub_test.go index db02786500..b49177e041 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor/qos_aware_client_stub_test.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor/qos_aware_client_stub_test.go @@ -23,15 +23,15 @@ import ( func TestClientAddContainer(t *testing.T) { client := NewCPUAdvisorClientStub() - client.AddContainer(context.Background(), &AddContainerRequest{}) + _, _ = client.AddContainer(context.Background(), &AddContainerRequest{}) } func TestClientRemovePod(t *testing.T) { client := NewCPUAdvisorClientStub() - client.RemovePod(context.Background(), &RemovePodRequest{}) + _, _ = client.RemovePod(context.Background(), &RemovePodRequest{}) } func TestClientListAndWatch(t *testing.T) { client := NewCPUAdvisorClientStub() - client.ListAndWatch(context.Background(), &Empty{}) + _, _ = client.ListAndWatch(context.Background(), &Empty{}) } diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/cpu_eviciton_test.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/cpu_eviciton_test.go index 29cebda667..75dd23991a 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/cpu_eviciton_test.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/cpu_eviciton_test.go @@ -30,6 +30,9 @@ import ( pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" maputil "k8s.io/kubernetes/pkg/util/maps" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + apiconsts "github.com/kubewharf/katalyst-api/pkg/consts" evictionpluginapi "github.com/kubewharf/katalyst-api/pkg/protocol/evictionplugin/v1alpha1" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" @@ -41,8 +44,6 @@ import ( "github.com/kubewharf/katalyst-core/pkg/metaserver/agent/metric" "github.com/kubewharf/katalyst-core/pkg/metrics" "github.com/kubewharf/katalyst-core/pkg/util/machine" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) var ( diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy.go index 291b99da1b..a7462740f7 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy.go @@ -364,6 +364,9 @@ func (p *DynamicPolicy) GetResourcesAllocation(ctx context.Context, // pooledCPUs is the total available cpu cores minus those that are reserved pooledCPUs := machineState.GetAvailableCPUSetExcludeDedicatedCoresPods(p.reservedCPUs) pooledCPUsTopologyAwareAssignments, err := machine.GetNumaAwareAssignments(p.machineInfo.CPUTopology, pooledCPUs) + if err != nil { + return nil, fmt.Errorf("GetNumaAwareAssignments err: %v", err) + } podResources := make(map[string]*pluginapi.ContainerResources) allocationInfosJustFinishRampUp := []*state.AllocationInfo{} @@ -1011,7 +1014,7 @@ func (p *DynamicPolicy) initReclaimPool() error { // for residual pools, we must make them exist even if cause overlap allAvailableCPUs := p.machineInfo.CPUDetails.CPUs().Difference(p.reservedCPUs) if reclaimedCPUSet.IsEmpty() { - reclaimedCPUSet, allAvailableCPUs, err = calculator.TakeByNUMABalance(p.machineInfo, allAvailableCPUs, reservedReclaimedCPUsSize) + reclaimedCPUSet, _, err = calculator.TakeByNUMABalance(p.machineInfo, allAvailableCPUs, reservedReclaimedCPUsSize) if err != nil { return fmt.Errorf("fallback takeByNUMABalance faild in initReclaimPool for %s with error: %v", state.PoolNameReclaim, err) diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_test.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_test.go index 9667e0db2e..c70fc5e5dc 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_test.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_test.go @@ -34,6 +34,8 @@ import ( pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" utilfs "k8s.io/kubernetes/pkg/util/filesystem" + "github.com/stretchr/testify/require" + "github.com/kubewharf/katalyst-api/pkg/consts" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/calculator" advisorapi "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor" @@ -45,7 +47,6 @@ import ( cgroupcm "github.com/kubewharf/katalyst-core/pkg/util/cgroup/common" cgroupcmutils "github.com/kubewharf/katalyst-core/pkg/util/cgroup/manager" "github.com/kubewharf/katalyst-core/pkg/util/machine" - "github.com/stretchr/testify/require" ) func getTestDynamicPolicyWithInitialization(topology *machine.CPUTopology, stateFileDirectory string) (*DynamicPolicy, error) { diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/checkpoint.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/checkpoint.go index 43a3112745..872fddb2a5 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/checkpoint.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/checkpoint.go @@ -39,7 +39,7 @@ func NewCPUPluginCheckpoint() *CPUPluginCheckpoint { } } -// MarshalCheckpoint returns marshalled checkpoint +// MarshalCheckpoint returns marshaled checkpoint func (cp *CPUPluginCheckpoint) MarshalCheckpoint() ([]byte, error) { // make sure checksum wasn't set before so it doesn't affect output checksum cp.Checksum = 0 diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/state_test.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/state_test.go index 2c5a46e244..fedff7810b 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/state_test.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/state_test.go @@ -26,10 +26,11 @@ import ( "k8s.io/kubernetes/pkg/kubelet/checkpointmanager" testutil "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager/state/testing" - "github.com/kubewharf/katalyst-api/pkg/consts" - "github.com/kubewharf/katalyst-core/pkg/util/machine" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/kubewharf/katalyst-api/pkg/consts" + "github.com/kubewharf/katalyst-core/pkg/util/machine" ) const ( @@ -1451,9 +1452,7 @@ func TestNewCheckpointState(t *testing.T) { // test skip corruption if strings.Contains(err.Error(), "checkpoint is corrupted") { - restoredState, err = - NewCheckpointState(testingDir, cpuPluginStateFileName, policyName, cpuTopology, true) - + _, err = NewCheckpointState(testingDir, cpuPluginStateFileName, policyName, cpuTopology, true) require.Nil(t, err) } } else { @@ -1947,7 +1946,7 @@ func TestClearState(t *testing.T) { state1.SetPodEntries(tc.podEntries) state2, err := NewCheckpointState(testingDir, cpuPluginStateFileName, policyName, tc.cpuTopology, false) - + as.Nil(err) assertStateEqual(t, state2, state1) }) } diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/util_test.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/util_test.go index 51543904fb..b395834a87 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/util_test.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/util_test.go @@ -26,9 +26,10 @@ import ( pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" + "github.com/stretchr/testify/require" + "github.com/kubewharf/katalyst-api/pkg/consts" "github.com/kubewharf/katalyst-core/pkg/util/machine" - "github.com/stretchr/testify/require" ) func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/allocation_handlers.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/allocation_handlers.go index 6403d21e03..2f1b3e2fe8 100644 --- a/pkg/agent/qrm-plugins/memory/dynamicpolicy/allocation_handlers.go +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/allocation_handlers.go @@ -394,18 +394,18 @@ func (p *DynamicPolicy) adjustAllocationEntries() error { containerId, err := p.metaServer.GetContainerID(curPodUID, curContainerName) if err != nil { klog.Errorf("[MemoryDynamicPolicy.adjustAllocationEntries] get container id of pod: %s container: %s failed with error: %v", - podUID, curContainerName, err) + curPodUID, curContainerName, err) return } err = cgroupcmutils.DropCacheWithTimeoutForContainer(curPodUID, containerId, 30) if err != nil { klog.Errorf("[MemoryDynamicPolicy.adjustAllocationEntries] drop cache of pod: %s container: %s failed with error: %v", - podUID, curContainerName, err) + curPodUID, curContainerName, err) return } - klog.Infof("[MemoryDynamicPolicy.adjustAllocationEntries] drop cache of pod: %s container: %s successfully", podUID, curContainerName) + klog.Infof("[MemoryDynamicPolicy.adjustAllocationEntries] drop cache of pod: %s container: %s successfully", curPodUID, curContainerName) }(podUID, containerName) } } diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy.go index 339aca2e05..a2578fad29 100644 --- a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy.go +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy.go @@ -57,8 +57,6 @@ const ( memsetCheckPeriod = 10 * time.Second stateCheckPeriod = 30 * time.Second maxResidualTime = 5 * time.Minute - - transitionPeriod = 30 * time.Second ) var ( diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_test.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_test.go index 925d5852a7..cf46b86e0a 100644 --- a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_test.go +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_test.go @@ -32,13 +32,14 @@ import ( "k8s.io/apimachinery/pkg/util/uuid" pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" + "github.com/stretchr/testify/require" + "github.com/kubewharf/katalyst-api/pkg/consts" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/memory/dynamicpolicy/state" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/util" "github.com/kubewharf/katalyst-core/pkg/config/generic" "github.com/kubewharf/katalyst-core/pkg/metrics" "github.com/kubewharf/katalyst-core/pkg/util/machine" - "github.com/stretchr/testify/require" ) func getTestDynamicPolicyWithInitialization(topology *machine.CPUTopology, machineInfo *info.MachineInfo, stateFileDirectory string) (*DynamicPolicy, error) { diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/state/checkpoint.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/state/checkpoint.go index 6b4aecb167..b846f4b847 100644 --- a/pkg/agent/qrm-plugins/memory/dynamicpolicy/state/checkpoint.go +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/state/checkpoint.go @@ -41,7 +41,7 @@ func NewMemoryPluginCheckpoint() *MemoryPluginCheckpoint { } } -// MarshalCheckpoint returns marshalled checkpoint +// MarshalCheckpoint returns marshaled checkpoint func (cp *MemoryPluginCheckpoint) MarshalCheckpoint() ([]byte, error) { // make sure checksum wasn't set before, so it doesn't affect output checksum cp.Checksum = 0 diff --git a/pkg/agent/qrm-plugins/util/util.go b/pkg/agent/qrm-plugins/util/util.go index d1065ec5cf..372ef01f96 100644 --- a/pkg/agent/qrm-plugins/util/util.go +++ b/pkg/agent/qrm-plugins/util/util.go @@ -226,14 +226,16 @@ func GetNUMANodesCountToFitMemoryReq(memoryReq, bytesPerNUMA uint64, numaCount i // GetHintsFromExtraStateFile // if you want to specify cpuset.mems for specific pods (eg. for existing pods) when switching // to katalyst the first time, you can provide an extra hints state file with content like below: -// { -// "memoryEntries": { -// "dp-18a916b04c-bdc9d5fd9-8m7vr-0": "0-1", -// "dp-18a916b04c-bdc9d5fd9-h9tgp-0": "5,7", -// "dp-47320a8d77-f46d6cbc7-5r27s-0": "2-3", -// "dp-d7e988f508-5f66655c5-8n2tf-0": "4,6" -// }, -// } +/* +{ + "memoryEntries": { + "dp-18a916b04c-bdc9d5fd9-8m7vr-0": "0-1", + "dp-18a916b04c-bdc9d5fd9-h9tgp-0": "5,7", + "dp-47320a8d77-f46d6cbc7-5r27s-0": "2-3", + "dp-d7e988f508-5f66655c5-8n2tf-0": "4,6" + }, +} +*/ func GetHintsFromExtraStateFile(podName, resourceName, extraHintsStateFileAbsPath string) (map[string]*pluginapi.ListOfTopologyHints, error) { if extraHintsStateFileAbsPath == "" { return nil, nil diff --git a/pkg/agent/qrm-plugins/util/util_test.go b/pkg/agent/qrm-plugins/util/util_test.go index 9aef8d4038..faf0d83ebc 100644 --- a/pkg/agent/qrm-plugins/util/util_test.go +++ b/pkg/agent/qrm-plugins/util/util_test.go @@ -19,10 +19,11 @@ package util import ( "testing" - "github.com/kubewharf/katalyst-core/pkg/util/machine" "github.com/stretchr/testify/require" pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager/bitmask" + + "github.com/kubewharf/katalyst-core/pkg/util/machine" ) func TestDeepCopyTopologyAwareAssignments(t *testing.T) { diff --git a/pkg/agent/resourcemanager/fetcher/kubelet/kubeletplugin.go b/pkg/agent/resourcemanager/fetcher/kubelet/kubeletplugin.go index e78fb15664..94176694e0 100644 --- a/pkg/agent/resourcemanager/fetcher/kubelet/kubeletplugin.go +++ b/pkg/agent/resourcemanager/fetcher/kubelet/kubeletplugin.go @@ -29,6 +29,7 @@ import ( "k8s.io/klog/v2" info "github.com/google/cadvisor/info/v1" + "github.com/kubewharf/katalyst-api/pkg/protocol/reporterplugin/v1alpha1" "github.com/kubewharf/katalyst-core/pkg/agent/resourcemanager/fetcher/kubelet/topology" "github.com/kubewharf/katalyst-core/pkg/agent/resourcemanager/fetcher/plugin" diff --git a/pkg/agent/resourcemanager/fetcher/kubelet/topology/podresourcesserver.go b/pkg/agent/resourcemanager/fetcher/kubelet/topology/podresourcesserver.go index 65408ddd6c..241c03c0ca 100644 --- a/pkg/agent/resourcemanager/fetcher/kubelet/topology/podresourcesserver.go +++ b/pkg/agent/resourcemanager/fetcher/kubelet/topology/podresourcesserver.go @@ -32,6 +32,8 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/klog/v2" + podresv1 "k8s.io/kubelet/pkg/apis/podresources/v1" + nodev1alpha1 "github.com/kubewharf/katalyst-api/pkg/apis/node/v1alpha1" "github.com/kubewharf/katalyst-core/pkg/agent/resourcemanager/fetcher/util/kubelet/podresources" "github.com/kubewharf/katalyst-core/pkg/consts" @@ -39,7 +41,6 @@ import ( metaserverpod "github.com/kubewharf/katalyst-core/pkg/metaserver/agent/pod" "github.com/kubewharf/katalyst-core/pkg/util/general" "github.com/kubewharf/katalyst-core/pkg/util/native" - podresv1 "k8s.io/kubelet/pkg/apis/podresources/v1" ) const ( diff --git a/pkg/agent/resourcemanager/fetcher/kubelet/topology/util.go b/pkg/agent/resourcemanager/fetcher/kubelet/topology/util.go index b126c9c6f7..ba22242309 100644 --- a/pkg/agent/resourcemanager/fetcher/kubelet/topology/util.go +++ b/pkg/agent/resourcemanager/fetcher/kubelet/topology/util.go @@ -23,6 +23,7 @@ import ( "k8s.io/klog/v2" info "github.com/google/cadvisor/info/v1" + nodev1alpha1 "github.com/kubewharf/katalyst-api/pkg/apis/node/v1alpha1" ) diff --git a/pkg/agent/resourcemanager/fetcher/manager_test.go b/pkg/agent/resourcemanager/fetcher/manager_test.go index e5423daa04..220aa1940e 100644 --- a/pkg/agent/resourcemanager/fetcher/manager_test.go +++ b/pkg/agent/resourcemanager/fetcher/manager_test.go @@ -64,7 +64,7 @@ func tmpSocketDir() (socketDir string, err error) { if err != nil { return } - os.MkdirAll(socketDir, 0755) + _ = os.MkdirAll(socketDir, 0755) return } @@ -165,8 +165,8 @@ func TestReporterPluginReRegistration(t *testing.T) { reporterContentsEqual(t, content2, p2GetReportContentResponse.Content) // test the scenario that plugin de-register and graceful shut down - p1.Stop() - p2.Stop() + _ = p1.Stop() + _ = p2.Stop() } func TestHealthz(t *testing.T) { @@ -213,7 +213,7 @@ func TestHealthz(t *testing.T) { } } - p.Stop() + _ = p.Stop() } func setup(t *testing.T, ctx context.Context, content []*v1alpha1.ReportContent, callback plugin.ListAndWatchCallback, socketDir string, pluginSocketName string, reporter reporter.Manager) (registration.AgentPluginHandler, <-chan interface{}, skeleton.GenericPlugin) { diff --git a/pkg/agent/sysadvisor/metacache/checkpoint.go b/pkg/agent/sysadvisor/metacache/checkpoint.go index a8bef0f1f3..872f49a9d0 100644 --- a/pkg/agent/sysadvisor/metacache/checkpoint.go +++ b/pkg/agent/sysadvisor/metacache/checkpoint.go @@ -40,7 +40,7 @@ func NewMetaCacheCheckpoint() *MetaCacheCheckpoint { } } -// MarshalCheckpoint returns marshalled checkpoint +// MarshalCheckpoint returns marshaled checkpoint func (cp *MetaCacheCheckpoint) MarshalCheckpoint() ([]byte, error) { // make sure checksum wasn't set before so it doesn't affect output checksum cp.Checksum = 0 diff --git a/pkg/agent/sysadvisor/plugin/qosaware/reporter/reporter_test.go b/pkg/agent/sysadvisor/plugin/qosaware/reporter/reporter_test.go index dc68f863c7..4fc8dedcde 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/reporter/reporter_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/reporter/reporter_test.go @@ -55,7 +55,7 @@ func tmpSocketDir() (socketDir string, err error) { if err != nil { return } - os.MkdirAll(socketDir, 0755) + _ = os.MkdirAll(socketDir, 0755) return } @@ -138,8 +138,8 @@ func TestReclaimedResourcedReporterWithManager(t *testing.T) { genericPlugin, err := newHeadroomReporterPlugin(metrics.DummyMetrics{}, metaServer, conf, advisorStub) require.NoError(t, err) require.NotNil(t, genericPlugin) - genericPlugin.Start() - defer genericPlugin.Stop() + _ = genericPlugin.Start() + defer func() { _ = genericPlugin.Stop() }() setupReporterManager(t, context.Background(), socketDir, conf) diff --git a/pkg/agent/sysadvisor/plugin/qosaware/server/cpu/cpu_server.go b/pkg/agent/sysadvisor/plugin/qosaware/server/cpu/cpu_server.go index 73b2fa1d4b..b21de70f89 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/server/cpu/cpu_server.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/server/cpu/cpu_server.go @@ -334,6 +334,7 @@ func (cs *cpuServer) serve() error { return nil } +//nolint func (cs *cpuServer) dial(unixSocketPath string, timeout time.Duration) (*grpc.ClientConn, error) { c, err := grpc.Dial(unixSocketPath, grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(timeout), diff --git a/pkg/agent/sysadvisor/plugin/qosaware/server/cpu/helper.go b/pkg/agent/sysadvisor/plugin/qosaware/server/cpu/helper.go index 152bf776ed..887f99e839 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/server/cpu/helper.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/server/cpu/helper.go @@ -18,6 +18,7 @@ package cpu import ( "fmt" + "k8s.io/apimachinery/pkg/util/uuid" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor" @@ -160,7 +161,7 @@ func (ib *internalBlock) join(blockID string, set blockSet) { } // blockSet is a global variable to store, and the mapping relation -// block id -> the internalBlock that belongs to this block id +// block id -> the internalBlock that belongs to this block id // // those internalBlock sharing with the same id should satisfy several constraints // - they belong to the same NUMA Node (though there exists no NUMA concepts here) diff --git a/pkg/client/control/cnc.go b/pkg/client/control/cnc.go index a1e053510c..69acd4577b 100644 --- a/pkg/client/control/cnc.go +++ b/pkg/client/control/cnc.go @@ -25,6 +25,7 @@ import ( "k8s.io/apimachinery/pkg/types" jsonpatch "github.com/evanphx/json-patch" + "github.com/kubewharf/katalyst-api/pkg/apis/config/v1alpha1" clientset "github.com/kubewharf/katalyst-api/pkg/client/clientset/versioned" ) diff --git a/pkg/config/agent/eviction/reclaimed_resources_eviction_plugin.go b/pkg/config/agent/eviction/reclaimed_resources_eviction_plugin.go index 05fd8dfe6f..0dbe296f14 100644 --- a/pkg/config/agent/eviction/reclaimed_resources_eviction_plugin.go +++ b/pkg/config/agent/eviction/reclaimed_resources_eviction_plugin.go @@ -22,7 +22,7 @@ import ( "strconv" "strings" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/sets" "github.com/kubewharf/katalyst-core/pkg/config/dynamic" diff --git a/pkg/config/metric/collector.go b/pkg/config/metric/collector.go index 7cbfe12838..5e60ef9689 100644 --- a/pkg/config/metric/collector.go +++ b/pkg/config/metric/collector.go @@ -17,8 +17,9 @@ limitations under the License. package metric import ( - "k8s.io/apimachinery/pkg/labels" "time" + + "k8s.io/apimachinery/pkg/labels" ) type CollectorConfiguration struct { diff --git a/pkg/controller/kcc/kcct.go b/pkg/controller/kcc/kcct.go index 02c8a1d004..b4b879b74d 100644 --- a/pkg/controller/kcc/kcct.go +++ b/pkg/controller/kcc/kcct.go @@ -186,7 +186,6 @@ func (k *KatalystCustomConfigTargetController) katalystCustomConfigTargetHandler overlapTargets []util.KCCTargetResource ) - isValid = true reason = kccTargetConditionReasonNormal kccKeys := k.targetHandler.GetKCCKeyListByGVR(gvr) if len(kccKeys) != 1 { @@ -247,7 +246,7 @@ func (k *KatalystCustomConfigTargetController) katalystCustomConfigTargetHandler updateTargetResourceStatus(targetResource, isValid, message, reason) if !apiequality.Semantic.DeepEqual(oldKCCTargetResource, targetResource) { klog.V(4).Infof("gvr: %s, target: %s need update status", gvr.String(), native.GenerateUniqObjectNameKey(target)) - target, err = k.unstructuredControl.UpdateUnstructuredStatus(k.ctx, gvr, target, metav1.UpdateOptions{}) + _, err = k.unstructuredControl.UpdateUnstructuredStatus(k.ctx, gvr, target, metav1.UpdateOptions{}) if err != nil { return err } diff --git a/pkg/controller/kcc/kcct_test.go b/pkg/controller/kcc/kcct_test.go index 35087cb543..a991cdbf95 100644 --- a/pkg/controller/kcc/kcct_test.go +++ b/pkg/controller/kcc/kcct_test.go @@ -27,6 +27,10 @@ import ( "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" + apiequality "k8s.io/apimachinery/pkg/api/equality" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "github.com/kubewharf/katalyst-api/pkg/apis/config/v1alpha1" katalyst_base "github.com/kubewharf/katalyst-core/cmd/base" "github.com/kubewharf/katalyst-core/pkg/config" @@ -34,9 +38,6 @@ import ( "github.com/kubewharf/katalyst-core/pkg/metrics" "github.com/kubewharf/katalyst-core/pkg/util" "github.com/kubewharf/katalyst-core/pkg/util/native" - apiequality "k8s.io/apimachinery/pkg/api/equality" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) func toTestUnstructured(obj interface{}) *unstructured.Unstructured { diff --git a/pkg/controller/kcc/util/kcct_test.go b/pkg/controller/kcc/util/kcct_test.go index 188f7765b1..c7c02e2425 100644 --- a/pkg/controller/kcc/util/kcct_test.go +++ b/pkg/controller/kcc/util/kcct_test.go @@ -21,7 +21,7 @@ import ( "testing" "time" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/klog/v2" diff --git a/pkg/controller/spd/spd_test.go b/pkg/controller/spd/spd_test.go index 6f8ff69cf2..3361ddf7ab 100644 --- a/pkg/controller/spd/spd_test.go +++ b/pkg/controller/spd/spd_test.go @@ -233,11 +233,11 @@ func TestSPDController_Run(t *testing.T) { if targetSPD == nil { targetSPD = tt.wantSPD } - newSPD, err := controlCtx.Client.InternalClient.WorkloadV1alpha1(). + newSPD, _ := controlCtx.Client.InternalClient.WorkloadV1alpha1(). ServiceProfileDescriptors(targetSPD.Namespace).Get(ctx, targetSPD.Name, metav1.GetOptions{}) assert.Equal(t, tt.wantSPD, newSPD) - newObject, err := controlCtx.Client.DynamicClient.Resource(stsGVR). + newObject, _ := controlCtx.Client.DynamicClient.Resource(stsGVR). Namespace(tt.fields.workload.GetNamespace()).Get(ctx, tt.fields.workload.GetName(), metav1.GetOptions{}) newWorkload := &appsv1.StatefulSet{} @@ -492,6 +492,8 @@ func TestIndicatorUpdater(t *testing.T) { assert.NoError(t, err) sc, err := NewSPDController(ctx, controlCtx, genericConfig, controllerConf, spdConfig, struct{}{}) + assert.NoError(t, err) + controlCtx.StartInformer(ctx) go sc.Run() synced := cache.WaitForCacheSync(ctx.Done(), sc.syncedFunc...) diff --git a/pkg/controller/vpa/algorithm/recommenders/avg_load_to_cpu_test.go b/pkg/controller/vpa/algorithm/recommenders/avg_load_to_cpu_test.go index c5fea8ca69..75517ffe88 100644 --- a/pkg/controller/vpa/algorithm/recommenders/avg_load_to_cpu_test.go +++ b/pkg/controller/vpa/algorithm/recommenders/avg_load_to_cpu_test.go @@ -90,7 +90,7 @@ func TestGetRecommendedPodResources(t *testing.T) { }{ recommendedResources: []apis.RecommendedContainerResources{ { - ContainerName: pointer.StringPtr("c1"), + ContainerName: pointer.String("c1"), Requests: &apis.RecommendedRequestResources{ Resources: map[v1.ResourceName]resource.Quantity{ v1.ResourceCPU: *resource.NewMilliQuantity(20000, resource.DecimalSI)}, diff --git a/pkg/controller/vpa/algorithm/register.go b/pkg/controller/vpa/algorithm/register.go index 46899c15cb..5471ea22c8 100644 --- a/pkg/controller/vpa/algorithm/register.go +++ b/pkg/controller/vpa/algorithm/register.go @@ -17,9 +17,10 @@ limitations under the License. package algorithm import ( - corev1 "k8s.io/api/core/v1" "sync" + corev1 "k8s.io/api/core/v1" + apis "github.com/kubewharf/katalyst-api/pkg/apis/autoscaling/v1alpha1" workload "github.com/kubewharf/katalyst-api/pkg/apis/workload/v1alpha1" ) diff --git a/pkg/controller/vpa/recommend_test.go b/pkg/controller/vpa/recommend_test.go index d30084f2e2..3c45c427ce 100644 --- a/pkg/controller/vpa/recommend_test.go +++ b/pkg/controller/vpa/recommend_test.go @@ -115,7 +115,7 @@ func TestResourceRecommendController_Run(t *testing.T) { vpaOptions := options.NewVPAOptions() vpaOptions.AddFlags(fss) vpaConf := controller.NewVPAConfig() - vpaOptions.ApplyTo(vpaConf) + _ = vpaOptions.ApplyTo(vpaConf) controlCtx, err := katalystbase.GenerateFakeGenericContext(nil, []runtime.Object{tt.fields.spd, tt.fields.vpa, tt.fields.vparec}, []runtime.Object{tt.fields.workload}) diff --git a/pkg/controller/vpa/util/api_test.go b/pkg/controller/vpa/util/api_test.go index 21db008b7c..73e18af839 100644 --- a/pkg/controller/vpa/util/api_test.go +++ b/pkg/controller/vpa/util/api_test.go @@ -160,7 +160,7 @@ func TestUpdateAPIVPAConditions(t *testing.T) { newvpa *apis.KatalystVerticalPodAutoscaler }{ { - name: "update diffrent type condition type", + name: "update different type condition type", oldvpa: oldvpa1, newvpa: newvpa1, }, diff --git a/pkg/controller/vpa/vpa_test.go b/pkg/controller/vpa/vpa_test.go index 98321fff96..b2d8829040 100644 --- a/pkg/controller/vpa/vpa_test.go +++ b/pkg/controller/vpa/vpa_test.go @@ -343,7 +343,7 @@ func TestVPAControllerSyncVPA(t *testing.T) { vpaOptions := options.NewVPAOptions() vpaOptions.AddFlags(fss) vpaConf := controller.NewVPAConfig() - vpaOptions.ApplyTo(vpaConf) + _ = vpaOptions.ApplyTo(vpaConf) workloadGVResources := []string{"statefulsets.v1.apps"} vpaConf.VPAWorkloadGVResources = workloadGVResources @@ -504,7 +504,7 @@ func TestVPAControllerSyncPod(t *testing.T) { vpaOptions := options.NewVPAOptions() vpaOptions.AddFlags(fss) vpaConf := controller.NewVPAConfig() - vpaOptions.ApplyTo(vpaConf) + _ = vpaOptions.ApplyTo(vpaConf) workloadGVResources := []string{"statefulsets.v1.apps"} vpaConf.VPAWorkloadGVResources = workloadGVResources @@ -665,7 +665,7 @@ func TestVPAControllerSyncWorkload(t *testing.T) { vpaOptions := options.NewVPAOptions() vpaOptions.AddFlags(fss) vpaConf := controller.NewVPAConfig() - vpaOptions.ApplyTo(vpaConf) + _ = vpaOptions.ApplyTo(vpaConf) workloadGVResources := []string{"statefulsets.v1.apps"} vpaConf.VPAWorkloadGVResources = workloadGVResources diff --git a/pkg/custom-metric/collector/prometheus/collector_promethes.go b/pkg/custom-metric/collector/prometheus/collector_promethes.go index db54dbfaec..1337bbc6c7 100644 --- a/pkg/custom-metric/collector/prometheus/collector_promethes.go +++ b/pkg/custom-metric/collector/prometheus/collector_promethes.go @@ -24,7 +24,7 @@ import ( "time" "go.uber.org/atomic" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" @@ -62,8 +62,8 @@ const ( // prometheusCollector implements MetricCollector using self-defined parser functionality // for prometheus formatted contents, and sends to store will standard formats. -// todo: if we restarts, we may lose some metric since the collecting logic interrupts -// need to consider a more reliable way to handle this +// todo: if we restarts, we may lose some metric since the collecting logic interrupts, +// and we need to consider a more reliable way to handle this. type prometheusCollector struct { ctx context.Context collectConf *metric.CollectorConfiguration @@ -252,9 +252,6 @@ func (p *prometheusCollector) checkTargetPod(pod *v1.Pod) bool { // checkTargetNode checks whether the given node is targeted // for metric scrapping logic. func (p *prometheusCollector) checkTargetNode(node *v1.Node) bool { - klog.V(6).Infof("check for node %v: %v, %v, %v", - node.Name, native.NodeReady(node), p.collectConf.NodeSelector.Matches(labels.Set(node.Labels))) - return node != nil && native.NodeReady(node) && p.collectConf.NodeSelector.Matches(labels.Set(node.Labels)) } diff --git a/pkg/custom-metric/collector/prometheus/collector_sharding_promethes.go b/pkg/custom-metric/collector/prometheus/collector_sharding_promethes.go index 6a292a6390..5a70e63d82 100644 --- a/pkg/custom-metric/collector/prometheus/collector_sharding_promethes.go +++ b/pkg/custom-metric/collector/prometheus/collector_sharding_promethes.go @@ -18,6 +18,7 @@ package prometheus import ( "context" + katalystbase "github.com/kubewharf/katalyst-core/cmd/base" "github.com/kubewharf/katalyst-core/pkg/config/metric" "github.com/kubewharf/katalyst-core/pkg/custom-metric/collector" diff --git a/pkg/custom-metric/collector/prometheus/scrape.go b/pkg/custom-metric/collector/prometheus/scrape.go index c7cf59f8d1..9f0344f2ae 100644 --- a/pkg/custom-metric/collector/prometheus/scrape.go +++ b/pkg/custom-metric/collector/prometheus/scrape.go @@ -282,7 +282,7 @@ func (s *ScrapeManager) fetch(ctx context.Context, url string, w io.Writer) erro return nil } -// parseContents analyses the contents scraped from prometheus http service. +// parseContents analyzes the contents scraped from prometheus http service. func parseContents(r io.Reader) (map[string]*dto.MetricFamily, error) { var parser expfmt.TextParser mf, err := parser.TextToMetricFamilies(r) diff --git a/pkg/custom-metric/provider/provider.go b/pkg/custom-metric/provider/provider.go index 429205df7b..29f601f8cc 100644 --- a/pkg/custom-metric/provider/provider.go +++ b/pkg/custom-metric/provider/provider.go @@ -62,7 +62,6 @@ const ( // - GetExternalMetric // --- if metric name is nominated, ignore the metric selector; // --- otherwise, return all the metrics matched with the metric selector; -// type MetricProvider interface { provider.MetricsProvider } diff --git a/pkg/custom-metric/provider/provider_test.go b/pkg/custom-metric/provider/provider_test.go index 3ed666a2cb..3e2c1cf518 100644 --- a/pkg/custom-metric/provider/provider_test.go +++ b/pkg/custom-metric/provider/provider_test.go @@ -26,7 +26,6 @@ import ( "testing" "time" - "github.com/kubewharf/katalyst-core/pkg/util/native" "github.com/stretchr/testify/assert" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -39,6 +38,8 @@ import ( "k8s.io/metrics/pkg/apis/external_metrics" "sigs.k8s.io/custom-metrics-apiserver/pkg/provider" + "github.com/kubewharf/katalyst-core/pkg/util/native" + katalystbase "github.com/kubewharf/katalyst-core/cmd/base" metricconf "github.com/kubewharf/katalyst-core/pkg/config/metric" "github.com/kubewharf/katalyst-core/pkg/custom-metric/store" @@ -230,7 +231,7 @@ func testProvider(t *testing.T, p MetricProvider, s store.MetricStore, ctx conte }, { Data: 2, - Timestamp: now.UnixMilli() - int64(genericConf.OutOfDataPeriod.Milliseconds()+time.Second.Milliseconds()*5), + Timestamp: now.UnixMilli() - genericConf.OutOfDataPeriod.Milliseconds() + time.Second.Milliseconds()*5, }, }, }, @@ -243,7 +244,7 @@ func testProvider(t *testing.T, p MetricProvider, s store.MetricStore, ctx conte Series: []*data.MetricData{ { Data: 2, - Timestamp: now.UnixMilli() - int64(genericConf.OutOfDataPeriod.Milliseconds()+time.Second.Milliseconds()*5), + Timestamp: now.UnixMilli() - genericConf.OutOfDataPeriod.Milliseconds() + time.Second.Milliseconds()*5, }, }, }, @@ -260,7 +261,7 @@ func testProvider(t *testing.T, p MetricProvider, s store.MetricStore, ctx conte }, { Data: 23, - Timestamp: now.UnixMilli() - int64(genericConf.OutOfDataPeriod.Milliseconds()), + Timestamp: now.UnixMilli() - genericConf.OutOfDataPeriod.Milliseconds(), }, }, }, @@ -327,7 +328,7 @@ func testProvider(t *testing.T, p MetricProvider, s store.MetricStore, ctx conte }, { Data: 44, - Timestamp: now.UnixMilli() - int64(genericConf.OutOfDataPeriod.Milliseconds()-time.Second.Milliseconds()*3), + Timestamp: now.UnixMilli() - genericConf.OutOfDataPeriod.Milliseconds() - time.Second.Milliseconds()*3, }, }, }, @@ -357,7 +358,7 @@ func testProvider(t *testing.T, p MetricProvider, s store.MetricStore, ctx conte Series: []*data.MetricData{ { Data: 86, - Timestamp: now.UnixMilli() - int64(genericConf.OutOfDataPeriod.Milliseconds()-time.Second.Milliseconds()*2), + Timestamp: now.UnixMilli() - genericConf.OutOfDataPeriod.Milliseconds() - time.Second.Milliseconds()*2, }, }, }, @@ -371,7 +372,7 @@ func testProvider(t *testing.T, p MetricProvider, s store.MetricStore, ctx conte Series: []*data.MetricData{ { Data: 73, - Timestamp: now.UnixMilli() - int64(genericConf.OutOfDataPeriod.Milliseconds()-time.Second.Milliseconds()*2), + Timestamp: now.UnixMilli() - genericConf.OutOfDataPeriod.Milliseconds() - time.Second.Milliseconds()*2, }, }, }, @@ -432,7 +433,7 @@ func testProvider(t *testing.T, p MetricProvider, s store.MetricStore, ctx conte }, }, }, - Timestamp: metav1.NewTime(time.UnixMilli(now.UnixMilli() - int64(genericConf.OutOfDataPeriod.Milliseconds()-time.Second.Milliseconds()*2))), + Timestamp: metav1.NewTime(time.UnixMilli(now.UnixMilli() - genericConf.OutOfDataPeriod.Milliseconds() - time.Second.Milliseconds()*2)), Value: *resource.NewQuantity(73, resource.DecimalSI), }, oneMetric) @@ -486,7 +487,7 @@ func testProvider(t *testing.T, p MetricProvider, s store.MetricStore, ctx conte }, }, }, - Timestamp: metav1.NewTime(time.UnixMilli(now.UnixMilli() - int64(genericConf.OutOfDataPeriod.Milliseconds()-time.Second.Milliseconds()*2))), + Timestamp: metav1.NewTime(time.UnixMilli(now.UnixMilli() - genericConf.OutOfDataPeriod.Milliseconds() - time.Second.Milliseconds()*2)), Value: *resource.NewQuantity(73, resource.DecimalSI), }, }, batchMetric.Items) @@ -553,7 +554,7 @@ func testProvider(t *testing.T, p MetricProvider, s store.MetricStore, ctx conte }, }, }, - Timestamp: metav1.NewTime(time.UnixMilli(now.UnixMilli() - int64(genericConf.OutOfDataPeriod.Milliseconds()-time.Second.Milliseconds()*3))), + Timestamp: metav1.NewTime(time.UnixMilli(now.UnixMilli() - genericConf.OutOfDataPeriod.Milliseconds() - time.Second.Milliseconds()*3)), Value: *resource.NewQuantity(44, resource.DecimalSI), }, { @@ -570,7 +571,7 @@ func testProvider(t *testing.T, p MetricProvider, s store.MetricStore, ctx conte }, }, }, - Timestamp: metav1.NewTime(time.UnixMilli(now.UnixMilli() - int64(genericConf.OutOfDataPeriod.Milliseconds()-time.Second.Milliseconds()*2))), + Timestamp: metav1.NewTime(time.UnixMilli(now.UnixMilli() - genericConf.OutOfDataPeriod.Milliseconds() - time.Second.Milliseconds()*2)), Value: *resource.NewQuantity(86, resource.DecimalSI), }, }, batchMetric.Items) @@ -610,7 +611,7 @@ func testProvider(t *testing.T, p MetricProvider, s store.MetricStore, ctx conte MetricLabels: map[string]string{ "name": "none_namespace_metric", }, - Timestamp: metav1.NewTime(time.UnixMilli(now.UnixMilli() - int64(genericConf.OutOfDataPeriod.Milliseconds()+time.Second.Milliseconds()*5))), + Timestamp: metav1.NewTime(time.UnixMilli(now.UnixMilli() - genericConf.OutOfDataPeriod.Milliseconds() + time.Second.Milliseconds()*5)), Value: *resource.NewQuantity(2, resource.DecimalSI), }, { @@ -618,7 +619,7 @@ func testProvider(t *testing.T, p MetricProvider, s store.MetricStore, ctx conte MetricLabels: map[string]string{ "name": "none_namespace_metric_all_timeout", }, - Timestamp: metav1.NewTime(time.UnixMilli(now.UnixMilli() - int64(genericConf.OutOfDataPeriod.Milliseconds()+time.Second.Milliseconds()*5))), + Timestamp: metav1.NewTime(time.UnixMilli(now.UnixMilli() - genericConf.OutOfDataPeriod.Milliseconds() + time.Second.Milliseconds()*5)), Value: *resource.NewQuantity(2, resource.DecimalSI), }, }, batchExternal.Items) @@ -642,7 +643,7 @@ func testProvider(t *testing.T, p MetricProvider, s store.MetricStore, ctx conte MetricLabels: map[string]string{ "name": "none_object_metric", }, - Timestamp: metav1.NewTime(time.UnixMilli(now.UnixMilli() - int64(genericConf.OutOfDataPeriod.Milliseconds()))), + Timestamp: metav1.NewTime(time.UnixMilli(now.UnixMilli() - genericConf.OutOfDataPeriod.Milliseconds())), Value: *resource.NewQuantity(23, resource.DecimalSI), }, }, batchExternal.Items) diff --git a/pkg/custom-metric/store/data/cache_test.go b/pkg/custom-metric/store/data/cache_test.go index 5fc700621e..879e2ee9a9 100644 --- a/pkg/custom-metric/store/data/cache_test.go +++ b/pkg/custom-metric/store/data/cache_test.go @@ -73,7 +73,7 @@ func Test_cache(t *testing.T) { }, }, oneMetric[0]) - oneMetric, exist = c.GetMetric("", "m-2", nil) + _, exist = c.GetMetric("", "m-2", nil) assert.Equal(t, false, exist) t.Log("#### 2: Add with namespaced metric") diff --git a/pkg/custom-metric/store/local/local_store.go b/pkg/custom-metric/store/local/local_store.go index 65f7134f4c..b654eb72eb 100644 --- a/pkg/custom-metric/store/local/local_store.go +++ b/pkg/custom-metric/store/local/local_store.go @@ -42,9 +42,8 @@ const MetricStoreNameLocalMemory = "local-memory-store" // LocalMemoryMetricStore implements MetricStore with single-node versioned // in-memory storage, and it will be used as a default implementation, especially // when the amount of internalMetric or the size of cluster is small. -// // todo: this implementation may be not efficient noe, so we may need to use more -// complicated structures in the future, such as indexer/aggregator/sort or so on. +// complicated structures in the future, such as indexer/aggregator/sort or so on. type LocalMemoryMetricStore struct { ctx context.Context storeConf *metricconf.StoreConfiguration diff --git a/pkg/custom-metric/store/remote/remote_store.go b/pkg/custom-metric/store/remote/remote_store.go index b75a20dd9d..6aae149b1c 100644 --- a/pkg/custom-metric/store/remote/remote_store.go +++ b/pkg/custom-metric/store/remote/remote_store.go @@ -23,11 +23,12 @@ import ( "fmt" "io" "io/ioutil" - "k8s.io/klog/v2" "net/http" "sync" "time" + "k8s.io/klog/v2" + "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/pkg/metaserver/agent/metric/malachite/cri.go b/pkg/metaserver/agent/metric/malachite/cri.go index 0e8ce6635d..0a518772e2 100644 --- a/pkg/metaserver/agent/metric/malachite/cri.go +++ b/pkg/metaserver/agent/metric/malachite/cri.go @@ -37,6 +37,7 @@ type containerInfo struct { name string } +//nolint func getConnection(endPoint string) (*grpc.ClientConn, error) { if endPoint == "" { return nil, fmt.Errorf("endpoint is not set") @@ -138,7 +139,7 @@ func getContainerCgroupsPath(client pb.RuntimeServiceClient, containerID string) } n := i + len("\"cgroupsPath\":") - str := string(v[n:]) + str := v[n:] start := strings.IndexByte(str, '"') if start == -1 { @@ -202,7 +203,7 @@ func GetAllPodsContainersCgroupsPath() (map[string]map[string]string, error) { if err != nil { return nil, err } - defer closeConnection(runtimeConn) + defer func() { _ = closeConnection(runtimeConn) }() pods, err := listPodSandbox(runtimeClient) if err != nil { diff --git a/pkg/metaserver/agent/pod/pod.go b/pkg/metaserver/agent/pod/pod.go index 294ee2e2ba..bd26f73ed6 100644 --- a/pkg/metaserver/agent/pod/pod.go +++ b/pkg/metaserver/agent/pod/pod.go @@ -41,9 +41,11 @@ const ( metricsNamePodCacheNotFound = "pod_cache_not_found" ) +type ContextKey string + const ( - BypassCacheKey = "bypass_cache" - BypassCacheTrue = "true" + BypassCacheKey ContextKey = "bypass_cache" + BypassCacheTrue ContextKey = "true" ) type PodFetcher interface { diff --git a/pkg/metaserver/config/checkpoint.go b/pkg/metaserver/config/checkpoint.go index ccb87c0cf1..be3dd2800a 100644 --- a/pkg/metaserver/config/checkpoint.go +++ b/pkg/metaserver/config/checkpoint.go @@ -18,10 +18,11 @@ package config import ( "encoding/json" + "reflect" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/kubernetes/pkg/kubelet/checkpointmanager" "k8s.io/kubernetes/pkg/kubelet/checkpointmanager/checksum" - "reflect" "github.com/kubewharf/katalyst-core/pkg/config/dynamic" ) diff --git a/pkg/metaserver/config/config_test.go b/pkg/metaserver/config/config_test.go index 255104758e..8e6479aa10 100644 --- a/pkg/metaserver/config/config_test.go +++ b/pkg/metaserver/config/config_test.go @@ -26,11 +26,12 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" dynamicfake "k8s.io/client-go/dynamic/fake" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "github.com/kubewharf/katalyst-api/pkg/apis/config/v1alpha1" internalfake "github.com/kubewharf/katalyst-api/pkg/client/clientset/versioned/fake" "github.com/kubewharf/katalyst-core/pkg/client" "github.com/kubewharf/katalyst-core/pkg/metaserver/agent/cnc" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) var ( diff --git a/pkg/metaserver/config/manager_test.go b/pkg/metaserver/config/manager_test.go index b4824fbb6a..948220181a 100644 --- a/pkg/metaserver/config/manager_test.go +++ b/pkg/metaserver/config/manager_test.go @@ -170,13 +170,14 @@ func TestNewDynamicConfigManager(t *testing.T) { require.NoError(t, err) manager, err := NewDynamicConfigManager(clientSet, &metrics.DummyMetrics{}, cncFetcher, conf) + require.NoError(t, err) require.NotNil(t, manager) err = manager.AddConfigWatcher(testTargetGVR) require.NoError(t, err) manager.Register(&DummyConfigurationRegister{}) - manager.InitializeConfig(context.TODO()) + _ = manager.InitializeConfig(context.TODO()) go manager.Run(context.TODO()) } diff --git a/pkg/metaserver/external/manager_linux_test.go b/pkg/metaserver/external/manager_linux_test.go index ce3eef016b..fb559bec89 100644 --- a/pkg/metaserver/external/manager_linux_test.go +++ b/pkg/metaserver/external/manager_linux_test.go @@ -52,6 +52,8 @@ func TestRun(t *testing.T) { externalManager := InitExternalManager(podFetcher) assert.NotNil(t, externalManager) - ctx, _ := context.WithTimeout(context.TODO(), time.Second) + ctx, cancel := context.WithTimeout(context.TODO(), time.Second) + defer cancel() + externalManager.Run(ctx) } diff --git a/pkg/metaserver/spd/checkpoint/checkpoint.go b/pkg/metaserver/spd/checkpoint/checkpoint.go index af9ccdcb93..6208673592 100644 --- a/pkg/metaserver/spd/checkpoint/checkpoint.go +++ b/pkg/metaserver/spd/checkpoint/checkpoint.go @@ -23,9 +23,10 @@ import ( "k8s.io/klog/v2" - "github.com/kubewharf/katalyst-api/pkg/apis/workload/v1alpha1" "k8s.io/kubernetes/pkg/kubelet/checkpointmanager" "k8s.io/kubernetes/pkg/kubelet/checkpointmanager/checksum" + + "github.com/kubewharf/katalyst-api/pkg/apis/workload/v1alpha1" ) const ( @@ -51,7 +52,7 @@ func NewServiceProfileCheckpoint(spd *v1alpha1.ServiceProfileDescriptor) Service return &Data{SPD: spd} } -// MarshalCheckpoint returns marshalled data +// MarshalCheckpoint returns marshaled data func (cp *Data) MarshalCheckpoint() ([]byte, error) { cp.Checksum = checksum.New(*cp.SPD) return json.Marshal(*cp) @@ -72,7 +73,7 @@ func (cp *Data) GetSPD() *v1alpha1.ServiceProfileDescriptor { return cp.SPD } -//getSPDKey returns the full qualified path for the spd checkpoint +// getSPDKey returns the full qualified path for the spd checkpoint func getSPDKey(spd *v1alpha1.ServiceProfileDescriptor) string { return fmt.Sprintf("%s%s%s%s%s.yaml", spdPrefix, delimiter, spd.Namespace, delimiter, spd.Name) } diff --git a/pkg/metaserver/spd/manager.go b/pkg/metaserver/spd/manager.go index bfb39779fc..7fa4ac344b 100644 --- a/pkg/metaserver/spd/manager.go +++ b/pkg/metaserver/spd/manager.go @@ -26,6 +26,10 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/klog/v2" + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/kubernetes/pkg/kubelet/checkpointmanager" + configapis "github.com/kubewharf/katalyst-api/pkg/apis/config/v1alpha1" workloadapis "github.com/kubewharf/katalyst-api/pkg/apis/workload/v1alpha1" "github.com/kubewharf/katalyst-core/pkg/client" @@ -34,9 +38,6 @@ import ( "github.com/kubewharf/katalyst-core/pkg/metrics" "github.com/kubewharf/katalyst-core/pkg/util" "github.com/kubewharf/katalyst-core/pkg/util/native" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/kubernetes/pkg/kubelet/checkpointmanager" ) const ( diff --git a/pkg/metaserver/spd/manager_test.go b/pkg/metaserver/spd/manager_test.go index 68e857240f..bcacaf8233 100644 --- a/pkg/metaserver/spd/manager_test.go +++ b/pkg/metaserver/spd/manager_test.go @@ -27,6 +27,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "github.com/stretchr/testify/require" + "github.com/kubewharf/katalyst-api/pkg/apis/config/v1alpha1" workloadapis "github.com/kubewharf/katalyst-api/pkg/apis/workload/v1alpha1" "github.com/kubewharf/katalyst-api/pkg/consts" @@ -36,7 +38,6 @@ import ( pkgconsts "github.com/kubewharf/katalyst-core/pkg/consts" "github.com/kubewharf/katalyst-core/pkg/metaserver/agent/cnc" "github.com/kubewharf/katalyst-core/pkg/metrics" - "github.com/stretchr/testify/require" ) func generateTestConfiguration(t *testing.T, nodeName string, checkpoint string) *pkgconfig.Configuration { diff --git a/pkg/metrics/metrics-pool/custom_metrics_pool_test.go b/pkg/metrics/metrics-pool/custom_metrics_pool_test.go index 2d32a8d8d5..3dd6a3dc3c 100644 --- a/pkg/metrics/metrics-pool/custom_metrics_pool_test.go +++ b/pkg/metrics/metrics-pool/custom_metrics_pool_test.go @@ -34,6 +34,7 @@ func TestNewCustomMetricsEmitterPool(t *testing.T) { custom, err := m.GetMetricsEmitter(PrometheusMetricOptions{ Path: "/custom-metrics", }) + assert.NoError(t, err) p.SetDefaultMetricsEmitter(custom) } diff --git a/pkg/scheduler/plugins/qosawarenoderesources/fit.go b/pkg/scheduler/plugins/qosawarenoderesources/fit.go index 7dbb5aa9bd..9f27190e72 100644 --- a/pkg/scheduler/plugins/qosawarenoderesources/fit.go +++ b/pkg/scheduler/plugins/qosawarenoderesources/fit.go @@ -181,10 +181,10 @@ func (f *Fit) PreFilterExtensions() framework.PreFilterExtensions { // the max in each dimension iteratively. In contrast, we sum the resource vectors for // regular containers since they run simultaneously. // -// The resources defined for Overhead should be added to the calculated QoSResource request sum -// -// Example: +// the resources defined for Overhead should be added to the calculated QoSResource request sum // +// example: +/* // Pod: // InitContainers // IC1: @@ -202,6 +202,7 @@ func (f *Fit) PreFilterExtensions() framework.PreFilterExtensions { // Memory: 1G // // Result: CPU: 3, Memory: 3G +*/ func computePodQoSResourceRequest(pod *v1.Pod) *preFilterState { result := &preFilterState{} for _, container := range pod.Spec.Containers { diff --git a/pkg/scheduler/plugins/qosawarenoderesources/least_allocated.go b/pkg/scheduler/plugins/qosawarenoderesources/least_allocated.go index aa1b110087..6b95beafa2 100644 --- a/pkg/scheduler/plugins/qosawarenoderesources/least_allocated.go +++ b/pkg/scheduler/plugins/qosawarenoderesources/least_allocated.go @@ -53,5 +53,5 @@ func leastRequestedScore(requested, capacity int64) int64 { return 0 } - return ((capacity - requested) * int64(framework.MaxNodeScore)) / capacity + return ((capacity - requested) * framework.MaxNodeScore) / capacity } diff --git a/pkg/scheduler/plugins/qosawarenoderesources/resource_allocation.go b/pkg/scheduler/plugins/qosawarenoderesources/resource_allocation.go index ce0643c6a7..d1543e8019 100644 --- a/pkg/scheduler/plugins/qosawarenoderesources/resource_allocation.go +++ b/pkg/scheduler/plugins/qosawarenoderesources/resource_allocation.go @@ -17,12 +17,13 @@ limitations under the License. package qosawarenoderesources import ( - "github.com/kubewharf/katalyst-core/pkg/util/native" v1 "k8s.io/api/core/v1" "k8s.io/klog/v2" kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/framework" + "github.com/kubewharf/katalyst-core/pkg/util/native" + "github.com/kubewharf/katalyst-api/pkg/apis/scheduling/config" "github.com/kubewharf/katalyst-api/pkg/consts" "github.com/kubewharf/katalyst-core/pkg/scheduler/cache" diff --git a/pkg/util/cgroup/manager/cgroup_test.go b/pkg/util/cgroup/manager/cgroup_test.go index d56134571d..11010d83bd 100644 --- a/pkg/util/cgroup/manager/cgroup_test.go +++ b/pkg/util/cgroup/manager/cgroup_test.go @@ -25,8 +25,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/kubewharf/katalyst-core/pkg/util/cgroup/common" - "github.com/kubewharf/katalyst-core/pkg/util/cgroup/manager/v1" - "github.com/kubewharf/katalyst-core/pkg/util/cgroup/manager/v2" + v1 "github.com/kubewharf/katalyst-core/pkg/util/cgroup/manager/v1" + v2 "github.com/kubewharf/katalyst-core/pkg/util/cgroup/manager/v2" ) func TestManager(t *testing.T) { diff --git a/pkg/util/cgroup/manager/v2/fs_linux.go b/pkg/util/cgroup/manager/v2/fs_linux.go index 69f13859d5..c35dc72c81 100644 --- a/pkg/util/cgroup/manager/v2/fs_linux.go +++ b/pkg/util/cgroup/manager/v2/fs_linux.go @@ -33,9 +33,10 @@ import ( "github.com/opencontainers/runc/libcontainer/cgroups/fscommon" "k8s.io/klog/v2" + libcgroups "github.com/opencontainers/runc/libcontainer/cgroups" + "github.com/kubewharf/katalyst-core/pkg/util/cgroup/common" "github.com/kubewharf/katalyst-core/pkg/util/general" - libcgroups "github.com/opencontainers/runc/libcontainer/cgroups" ) type manager struct{} diff --git a/pkg/util/external/rdt/manager_test.go b/pkg/util/external/rdt/manager_test.go index 496f20c086..e122ff7b6d 100644 --- a/pkg/util/external/rdt/manager_test.go +++ b/pkg/util/external/rdt/manager_test.go @@ -31,8 +31,6 @@ var ( func TestNewDefaultManager(t *testing.T) { defaultManager := NewDefaultManager() assert.NotNil(t, defaultManager) - - return } func TestCheckSupportRDT(t *testing.T) { @@ -42,8 +40,6 @@ func TestCheckSupportRDT(t *testing.T) { isSupport, err := defaultManager.CheckSupportRDT() assert.Error(t, err) assert.False(t, isSupport) - - return } func TestInitRDT(t *testing.T) { @@ -52,8 +48,6 @@ func TestInitRDT(t *testing.T) { err := defaultManager.InitRDT() assert.Error(t, err) - - return } func TestApplyTasks(t *testing.T) { @@ -62,8 +56,6 @@ func TestApplyTasks(t *testing.T) { err := defaultManager.ApplyTasks(clos, tasks) assert.Error(t, err) - - return } func TestApplyCAT(t *testing.T) { diff --git a/pkg/util/native/pod_sorter.go b/pkg/util/native/pod_sorter.go index eaa304a1cb..d108069628 100644 --- a/pkg/util/native/pod_sorter.go +++ b/pkg/util/native/pod_sorter.go @@ -17,8 +17,9 @@ package native import ( v1 "k8s.io/api/core/v1" - "github.com/kubewharf/katalyst-core/pkg/util/general" corev1helpers "k8s.io/component-helpers/scheduling/corev1" + + "github.com/kubewharf/katalyst-core/pkg/util/general" ) type PodSourceList struct { diff --git a/pkg/util/native/resources.go b/pkg/util/native/resources.go index ef31135b6d..e1c23651fa 100644 --- a/pkg/util/native/resources.go +++ b/pkg/util/native/resources.go @@ -123,9 +123,7 @@ func IsResourceGreaterThan(a resource.Quantity, b resource.Quantity) bool { return (&a).Cmp(b) > 0 } -// PodResourceDiff checks if pod resources (both for requests and limits) -// are NOT the same as the given resource map, -//nolint:gocognit +// PodResourceDiff checks if pod resources are not the same as the given resource map, both for requests and limits. func PodResourceDiff(pod *v1.Pod, containerResourcesToUpdate map[string]v1.ResourceRequirements) bool { for c, resources := range containerResourcesToUpdate { findContainer := false diff --git a/pkg/util/spd_test.go b/pkg/util/spd_test.go index a9a36380cc..9f7c1b8108 100644 --- a/pkg/util/spd_test.go +++ b/pkg/util/spd_test.go @@ -84,7 +84,7 @@ func TestGetSPDForPod(t *testing.T) { u, err := native.ToUnstructured(dp) assert.NoError(t, err) - dpInformer.Informer().GetStore().Add(u) + _ = dpInformer.Informer().GetStore().Add(u) rs := &appsv1.ReplicaSet{ ObjectMeta: metav1.ObjectMeta{ @@ -102,7 +102,7 @@ func TestGetSPDForPod(t *testing.T) { u, err = native.ToUnstructured(rs) assert.NoError(t, err) - rsInformer.Informer().GetStore().Add(u) + _ = rsInformer.Informer().GetStore().Add(u) pod1 := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ @@ -124,7 +124,7 @@ func TestGetSPDForPod(t *testing.T) { internalClient := externalfake.NewSimpleClientset() internalFactory := externalversions.NewSharedInformerFactory(internalClient, 0) spdInformer := internalFactory.Workload().V1alpha1().ServiceProfileDescriptors() - spdInformer.Informer().GetIndexer().AddIndexers(cache.Indexers{ + _ = spdInformer.Informer().GetIndexer().AddIndexers(cache.Indexers{ consts.TargetReferenceIndex: SPDTargetReferenceIndex, }) spd := &apiworkload.ServiceProfileDescriptor{ @@ -137,7 +137,7 @@ func TestGetSPDForPod(t *testing.T) { }, }, } - spdInformer.Informer().GetStore().Add(spd) + _ = spdInformer.Informer().GetStore().Add(spd) s, err := GetSPDForPod(pod1, spdInformer.Informer().GetIndexer(), workloadInformers, spdInformer.Lister()) assert.NoError(t, err) diff --git a/pkg/util/syntax/reflect.go b/pkg/util/syntax/reflect.go index 10b2159840..870ec69bf9 100644 --- a/pkg/util/syntax/reflect.go +++ b/pkg/util/syntax/reflect.go @@ -115,9 +115,11 @@ func ParseBytesByType(b []byte, t reflect.Type) (reflect.Value, error) { // SimpleMergeTwoValues won't support, and a possible one is a struct with a map // or slice member, we will not merge its member object. // for example, consider src and dst with the same type of -// struct newType struct { -// a []string -// }, +/* +type newType struct { + a []string +} +*/ // and src is newType{"a":["2"]}, dst is newType{"a":["1"]}, the simple merge result // is newType{"a":["2"]}, and not newType{"a":["1","2"]} func SimpleMergeTwoValues(src reflect.Value, dst reflect.Value) error { diff --git a/pkg/util/vpa_test.go b/pkg/util/vpa_test.go index e4a8a331dc..c22a574993 100644 --- a/pkg/util/vpa_test.go +++ b/pkg/util/vpa_test.go @@ -233,7 +233,7 @@ func TestGetVPAForPod(t *testing.T) { u, err := native.ToUnstructured(dp) assert.NoError(t, err) - dpInformer.Informer().GetStore().Add(u) + _ = dpInformer.Informer().GetStore().Add(u) rs := &appsv1.ReplicaSet{ ObjectMeta: metav1.ObjectMeta{ @@ -251,7 +251,7 @@ func TestGetVPAForPod(t *testing.T) { u, err = native.ToUnstructured(rs) assert.NoError(t, err) - rsInformer.Informer().GetStore().Add(u) + _ = rsInformer.Informer().GetStore().Add(u) pod1 := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ @@ -273,7 +273,7 @@ func TestGetVPAForPod(t *testing.T) { internalClient := externalfake.NewSimpleClientset() internalFactory := externalversions.NewSharedInformerFactory(internalClient, 0) vpaInformer := internalFactory.Autoscaling().V1alpha1().KatalystVerticalPodAutoscalers() - vpaInformer.Informer().GetIndexer().AddIndexers(cache.Indexers{ + _ = vpaInformer.Informer().GetIndexer().AddIndexers(cache.Indexers{ consts.TargetReferenceIndex: VPATargetReferenceIndex, }) vpa := &apis.KatalystVerticalPodAutoscaler{ @@ -286,7 +286,7 @@ func TestGetVPAForPod(t *testing.T) { }, }, } - vpaInformer.Informer().GetStore().Add(vpa) + _ = vpaInformer.Informer().GetStore().Add(vpa) v, err := GetVPAForPod(pod1, vpaInformer.Informer().GetIndexer(), workloadInformers, vpaInformer.Lister()) assert.NoError(t, err)