From 4b4561d127522f63037326f34f7d1b68ed1d3431 Mon Sep 17 00:00:00 2001 From: Pavel Okhlopkov <36456348+ldmonster@users.noreply.github.com> Date: Thu, 7 Nov 2024 12:59:46 +0300 Subject: [PATCH] [shell-operator] bump kube client (#684) Signed-off-by: Pavel Okhlopkov Co-authored-by: Pavel Okhlopkov --- .golangci.yaml | 5 +++++ go.mod | 4 ++-- go.sum | 8 ++++---- pkg/shell-operator/bootstrap.go | 2 +- pkg/shell-operator/kube_client.go | 14 +++++++------- test/integration/suite/run.go | 2 +- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index a418e83a..ece73ad1 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -38,6 +38,11 @@ linters-settings: local-prefixes: github.com/flant/ nolintlint: allow-unused: true + # TODO: replace deprecated methods + # ignore deprecated + # https://staticcheck.dev/docs/checks/#SA1019 + staticcheck: + checks: ["all","-SA1019"] sloglint: # Enforce not mixing key-value pairs and attributes. no-mixed-args: true diff --git a/go.mod b/go.mod index e36a08cc..d5739ada 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/flant/shell-operator go 1.22.8 require ( - github.com/deckhouse/deckhouse/pkg/log v0.0.0-20241102120041-7e44e3e22ab9 - github.com/flant/kube-client v1.2.1 + github.com/deckhouse/deckhouse/pkg/log v0.0.0-20241106140903-258b93b3334e + github.com/flant/kube-client v1.2.2 github.com/flant/libjq-go v1.6.3-0.20201126171326-c46a40ff22ee // branch: master github.com/go-chi/chi/v5 v5.1.0 github.com/go-openapi/spec v0.19.8 diff --git a/go.sum b/go.sum index ba266de3..d25d28f3 100644 --- a/go.sum +++ b/go.sum @@ -24,8 +24,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/deckhouse/deckhouse/pkg/log v0.0.0-20241102120041-7e44e3e22ab9 h1:gCV1iKcaE69x3Knzj8isyVyEtRuG2YI4nmLIzBHBWeQ= -github.com/deckhouse/deckhouse/pkg/log v0.0.0-20241102120041-7e44e3e22ab9/go.mod h1:Mk5HRzkc5pIcDIZ2JJ6DPuuqnwhXVkb3you8M8Mg+4w= +github.com/deckhouse/deckhouse/pkg/log v0.0.0-20241106140903-258b93b3334e h1:QUQy+5Bv7/UzhfrytiG3c5gfLGhPppepVbRpbMisVIw= +github.com/deckhouse/deckhouse/pkg/log v0.0.0-20241106140903-258b93b3334e/go.mod h1:Mk5HRzkc5pIcDIZ2JJ6DPuuqnwhXVkb3you8M8Mg+4w= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g= github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= @@ -33,8 +33,8 @@ github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCv github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/flant/go-openapi-validate v0.19.12-flant.0 h1:xk6kvc9fHKMgUdB6J7kbpbLR5vJOUzKAK8p3nrD7mDk= github.com/flant/go-openapi-validate v0.19.12-flant.0/go.mod h1:Rzou8hA/CBw8donlS6WNEUQupNvUZ0waH08tGe6kAQ4= -github.com/flant/kube-client v1.2.1 h1:8lHF8+wGZrhsXM6TeS3CNAPupXyx7UJLkBvNMpCe/ZI= -github.com/flant/kube-client v1.2.1/go.mod h1:62vCzrIUzWMU4DB0Pn6/02Pu7uwKh5/mHGWy2NmxZAk= +github.com/flant/kube-client v1.2.2 h1:27LBs+PKJEFnkQXjPU9eIps7a7iyI13AKcSYj897DCU= +github.com/flant/kube-client v1.2.2/go.mod h1:eMa3aJ6V1PRWSQ/RCROkObDpY4S74uM84SJS4G/LINg= github.com/flant/libjq-go v1.6.3-0.20201126171326-c46a40ff22ee h1:evii83J+/6QGNvyf6tjQ/p27DPY9iftxIBb37ALJRTg= github.com/flant/libjq-go v1.6.3-0.20201126171326-c46a40ff22ee/go.mod h1:f+REaGl/+pZR97rbTcwHEka/MAipoQQ2Mc0iQUj4ak0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= diff --git a/pkg/shell-operator/bootstrap.go b/pkg/shell-operator/bootstrap.go index cf4ccc4e..760726a4 100644 --- a/pkg/shell-operator/bootstrap.go +++ b/pkg/shell-operator/bootstrap.go @@ -84,7 +84,7 @@ func (op *ShellOperator) AssembleCommonOperator(listenAddress, listenPort string op.setupHookMetricStorage() // 'main' Kubernetes client. - op.KubeClient, err = initDefaultMainKubeClient(op.MetricStorage) + op.KubeClient, err = initDefaultMainKubeClient(op.MetricStorage, op.logger) if err != nil { return err } diff --git a/pkg/shell-operator/kube_client.go b/pkg/shell-operator/kube_client.go index 59287fb4..733341ac 100644 --- a/pkg/shell-operator/kube_client.go +++ b/pkg/shell-operator/kube_client.go @@ -19,8 +19,8 @@ var ( // defaultMainKubeClient creates a Kubernetes client for hooks. No timeout specified, because // timeout will reset connections for Watchers. -func defaultMainKubeClient(metricStorage *metric_storage.MetricStorage, metricLabels map[string]string) *klient.Client { - client := klient.New() +func defaultMainKubeClient(metricStorage *metric_storage.MetricStorage, metricLabels map[string]string, logger *log.Logger) *klient.Client { + client := klient.New(klient.WithLogger(logger)) client.WithContextName(app.KubeContext) client.WithConfigPath(app.KubeConfig) client.WithRateLimiterSettings(app.KubeClientQps, app.KubeClientBurst) @@ -29,10 +29,10 @@ func defaultMainKubeClient(metricStorage *metric_storage.MetricStorage, metricLa return client } -func initDefaultMainKubeClient(metricStorage *metric_storage.MetricStorage) (*klient.Client, error) { +func initDefaultMainKubeClient(metricStorage *metric_storage.MetricStorage, logger *log.Logger) (*klient.Client, error) { //nolint:staticcheck klient.RegisterKubernetesClientMetrics(metricStorage, defaultMainKubeClientMetricLabels) - kubeClient := defaultMainKubeClient(metricStorage, defaultMainKubeClientMetricLabels) + kubeClient := defaultMainKubeClient(metricStorage, defaultMainKubeClientMetricLabels, logger.Named("main-kube-client")) err := kubeClient.Init() if err != nil { return nil, fmt.Errorf("initialize 'main' Kubernetes client: %s\n", err) @@ -41,8 +41,8 @@ func initDefaultMainKubeClient(metricStorage *metric_storage.MetricStorage) (*kl } // defaultObjectPatcherKubeClient initializes a Kubernetes client for ObjectPatcher. Timeout is specified here. -func defaultObjectPatcherKubeClient(metricStorage *metric_storage.MetricStorage, metricLabels map[string]string) *klient.Client { - client := klient.New() +func defaultObjectPatcherKubeClient(metricStorage *metric_storage.MetricStorage, metricLabels map[string]string, logger *log.Logger) *klient.Client { + client := klient.New(klient.WithLogger(logger)) client.WithContextName(app.KubeContext) client.WithConfigPath(app.KubeConfig) client.WithRateLimiterSettings(app.ObjectPatcherKubeClientQps, app.ObjectPatcherKubeClientBurst) @@ -53,7 +53,7 @@ func defaultObjectPatcherKubeClient(metricStorage *metric_storage.MetricStorage, } func initDefaultObjectPatcher(metricStorage *metric_storage.MetricStorage, logger *log.Logger) (*object_patch.ObjectPatcher, error) { - patcherKubeClient := defaultObjectPatcherKubeClient(metricStorage, defaultObjectPatcherKubeClientMetricLabels) + patcherKubeClient := defaultObjectPatcherKubeClient(metricStorage, defaultObjectPatcherKubeClientMetricLabels, logger.Named("object-patcher-kube-client")) err := patcherKubeClient.Init() if err != nil { return nil, fmt.Errorf("initialize Kubernetes client for Object patcher: %s\n", err) diff --git a/test/integration/suite/run.go b/test/integration/suite/run.go index 1144d209..f6fb6dc6 100644 --- a/test/integration/suite/run.go +++ b/test/integration/suite/run.go @@ -32,7 +32,7 @@ func RunIntegrationSuite(t *testing.T, description string, clusterPrefix string) var _ = BeforeSuite(func() { // Initialize kube client out-of-cluster - KubeClient = klient.New() + KubeClient = klient.New(klient.WithLogger(log.NewNop())) KubeClient.WithContextName(ContextName) err := KubeClient.Init() Expect(err).ShouldNot(HaveOccurred())