From ecc1c68ea732aa0fefb2a68ba4282fd838bc78d7 Mon Sep 17 00:00:00 2001 From: kartik-579 Date: Mon, 12 Aug 2024 15:11:40 +0530 Subject: [PATCH 1/2] updated common lib to a996c33bc3d7c4c625efd40aa --- go.mod | 2 +- go.sum | 4 +- .../common-lib/utils/k8s/K8sUtil.go | 39 +++++++++++++++---- .../devtron-labs/common-lib/utils/k8s/bean.go | 2 +- vendor/modules.txt | 2 +- 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 9abe2b0f86..a1772ab674 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 github.com/devtron-labs/authenticator v0.4.35-0.20240809073103-6e11da8083f8 - github.com/devtron-labs/common-lib v0.0.25-0.20240812080926-4926120ea08d + github.com/devtron-labs/common-lib v0.0.25-0.20240812093942-a996c33bc3d7 github.com/devtron-labs/go-bitbucket v0.9.60-beta github.com/devtron-labs/protos v0.0.3-0.20240802105333-92ee9bb85d80 github.com/evanphx/json-patch v5.7.0+incompatible diff --git a/go.sum b/go.sum index 91acfe0336..8c77ddfc5d 100644 --- a/go.sum +++ b/go.sum @@ -195,8 +195,8 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= github.com/devtron-labs/authenticator v0.4.35-0.20240809073103-6e11da8083f8 h1:2+Q7Jdhpo/uMiaQiZZzAh+ZX7wEJIFuMFG6DEiMuo64= github.com/devtron-labs/authenticator v0.4.35-0.20240809073103-6e11da8083f8/go.mod h1:702R6WIf5y9UzKGoCGxQ+x3l5Ws+l0fXg2xlCpSGFZI= -github.com/devtron-labs/common-lib v0.0.25-0.20240812080926-4926120ea08d h1:/HZhYZVP+zQfbohq9Mxz3IX4rDjt0tokPll5zhh5gC8= -github.com/devtron-labs/common-lib v0.0.25-0.20240812080926-4926120ea08d/go.mod h1:a7aCClaxYfnyYEENSe1RnkQCeW2AwmCAPYsuvgk0aW0= +github.com/devtron-labs/common-lib v0.0.25-0.20240812093942-a996c33bc3d7 h1:XcMRNOBBZRXbjnWxgCxCpTGHljh1neWG3Gf4u7rhv3M= +github.com/devtron-labs/common-lib v0.0.25-0.20240812093942-a996c33bc3d7/go.mod h1:a7aCClaxYfnyYEENSe1RnkQCeW2AwmCAPYsuvgk0aW0= github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU= github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y= github.com/devtron-labs/protos v0.0.3-0.20240802105333-92ee9bb85d80 h1:xwbTeijNTf4/j1v+tSfwVqwLVnReas/NqEKeQHvSTys= diff --git a/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go b/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go index 1b392015e5..7734f432bf 100644 --- a/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go +++ b/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go @@ -59,7 +59,6 @@ import ( "k8s.io/client-go/kubernetes" v12 "k8s.io/client-go/kubernetes/typed/core/v1" "k8s.io/client-go/rest" - restclient "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" "sigs.k8s.io/yaml" ) @@ -72,7 +71,7 @@ type K8sServiceImpl struct { } type K8sService interface { - GetLogsForAPod(kubeClient *kubernetes.Clientset, namespace string, podName string, container string, follow bool) *restclient.Request + GetLogsForAPod(kubeClient *kubernetes.Clientset, namespace string, podName string, container string, follow bool) *rest.Request GetMetricsClientSet(restConfig *rest.Config, k8sHttpClient *http.Client) (*metrics.Clientset, error) GetNmByName(ctx context.Context, metricsClientSet *metrics.Clientset, name string) (*v1beta1.NodeMetrics, error) GetNmList(ctx context.Context, metricsClientSet *metrics.Clientset) (*v1beta1.NodeMetricsList, error) @@ -120,7 +119,7 @@ type K8sService interface { GetK8sDiscoveryClient(clusterConfig *ClusterConfig) (*discovery.DiscoveryClient, error) GetClientForInCluster() (*v12.CoreV1Client, error) GetCoreV1Client(clusterConfig *ClusterConfig) (*v12.CoreV1Client, error) - GetRestConfigByCluster(clusterConfig *ClusterConfig) (*restclient.Config, error) + GetRestConfigByCluster(clusterConfig *ClusterConfig) (*rest.Config, error) GetResource(ctx context.Context, namespace string, name string, gvk schema.GroupVersionKind, restConfig *rest.Config) (*ManifestResponse, error) UpdateResource(ctx context.Context, restConfig *rest.Config, gvk schema.GroupVersionKind, namespace string, k8sRequestPatch string) (*ManifestResponse, error) DeleteResource(ctx context.Context, restConfig *rest.Config, gvk schema.GroupVersionKind, namespace string, name string, forceDelete bool) (*ManifestResponse, error) @@ -140,6 +139,11 @@ type K8sService interface { CreateK8sClientSet(restConfig *rest.Config) (*kubernetes.Clientset, error) CreateOrUpdateSecretByName(client *v12.CoreV1Client, namespace, uniqueSecretName string, secretLabel map[string]string, secretData map[string]string) error //CreateK8sClientSetWithCustomHttpTransport(restConfig *rest.Config) (*kubernetes.Clientset, error) + + //below functions are exposed for K8sUtilExtended + GetRestConfigByClusterWithoutCustomTransport(clusterConfig *ClusterConfig) (*rest.Config, error) + OverrideRestConfigWithCustomTransport(restConfig *rest.Config) (*rest.Config, error) + CreateNs(namespace string, client *v12.CoreV1Client) (ns *v1.Namespace, err error) } func NewK8sUtil(logger *zap.SugaredLogger, runTimeConfig *RuntimeConfig) *K8sServiceImpl { @@ -157,7 +161,20 @@ func NewK8sUtil(logger *zap.SugaredLogger, runTimeConfig *RuntimeConfig) *K8sSer return &K8sServiceImpl{logger: logger, runTimeConfig: runTimeConfig, kubeconfig: kubeconfig, httpClientConfig: httpClientConfig} } -func (impl *K8sServiceImpl) GetRestConfigByCluster(clusterConfig *ClusterConfig) (*restclient.Config, error) { +func (impl *K8sServiceImpl) GetRestConfigByCluster(clusterConfig *ClusterConfig) (*rest.Config, error) { + restConfig, err := impl.GetRestConfigByClusterWithoutCustomTransport(clusterConfig) + if err != nil { + impl.logger.Errorw("error, GetRestConfigByClusterWithoutCustomTransport", "err", err) + return nil, err + } + restConfig, err = impl.OverrideRestConfigWithCustomTransport(restConfig) + if err != nil { + impl.logger.Errorw("error in overriding rest config with custom transport configurations", "err", err) + } + return restConfig, err +} + +func (impl *K8sServiceImpl) GetRestConfigByClusterWithoutCustomTransport(clusterConfig *ClusterConfig) (*rest.Config, error) { bearerToken := clusterConfig.BearerToken var restConfig *rest.Config var err error @@ -171,11 +188,17 @@ func (impl *K8sServiceImpl) GetRestConfigByCluster(clusterConfig *ClusterConfig) restConfig = &rest.Config{Host: clusterConfig.Host, BearerToken: bearerToken} clusterConfig.PopulateTlsConfigurationsInto(restConfig) } + return restConfig, nil +} + +func (impl *K8sServiceImpl) OverrideRestConfigWithCustomTransport(restConfig *rest.Config) (*rest.Config, error) { + var err error restConfig, err = impl.httpClientConfig.OverrideConfigWithCustomTransport(restConfig) if err != nil { impl.logger.Errorw("error in overriding rest config with custom transport configurations", "err", err) + return nil, err } - return restConfig, err + return restConfig, nil } func (impl *K8sServiceImpl) GetCoreV1Client(clusterConfig *ClusterConfig) (*v12.CoreV1Client, error) { @@ -283,7 +306,7 @@ func (impl *K8sServiceImpl) CreateNsIfNotExists(namespace string, clusterConfig return nil } impl.logger.Infow("ns not exists creating", "ns", namespace) - _, err = impl.createNs(namespace, v12Client) + _, err = impl.CreateNs(namespace, v12Client) return err } @@ -302,7 +325,7 @@ func (impl *K8sServiceImpl) CheckIfNsExists(namespace string, client *v12.CoreV1 } -func (impl *K8sServiceImpl) createNs(namespace string, client *v12.CoreV1Client) (ns *v1.Namespace, err error) { +func (impl *K8sServiceImpl) CreateNs(namespace string, client *v12.CoreV1Client) (ns *v1.Namespace, err error) { nsSpec := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}} ns, err = client.Namespaces().Create(context.Background(), nsSpec, metav1.CreateOptions{}) if err != nil { @@ -1087,7 +1110,7 @@ func (impl *K8sServiceImpl) GetMetricsClientSet(restConfig *rest.Config, k8sHttp } return metricsClientSet, err } -func (impl *K8sServiceImpl) GetLogsForAPod(kubeClient *kubernetes.Clientset, namespace string, podName string, container string, follow bool) *restclient.Request { +func (impl *K8sServiceImpl) GetLogsForAPod(kubeClient *kubernetes.Clientset, namespace string, podName string, container string, follow bool) *rest.Request { podLogOpts := &v1.PodLogOptions{ Container: container, Follow: follow, diff --git a/vendor/github.com/devtron-labs/common-lib/utils/k8s/bean.go b/vendor/github.com/devtron-labs/common-lib/utils/k8s/bean.go index ac429273ad..05f5220ea2 100644 --- a/vendor/github.com/devtron-labs/common-lib/utils/k8s/bean.go +++ b/vendor/github.com/devtron-labs/common-lib/utils/k8s/bean.go @@ -234,7 +234,7 @@ func (impl *CustomK8sHttpTransportConfig) OverrideConfigWithCustomTransport(conf } transport := utilnet.SetTransportDefaults(&http.Transport{ - Proxy: http.ProxyFromEnvironment, + Proxy: config.Proxy, TLSHandshakeTimeout: time.Duration(impl.TLSHandshakeTimeout) * time.Second, TLSClientConfig: tlsConfig, MaxIdleConns: impl.MaxIdleConnsPerHost, diff --git a/vendor/modules.txt b/vendor/modules.txt index 3bd137d9a7..576d559ea0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -401,7 +401,7 @@ github.com/devtron-labs/authenticator/jwt github.com/devtron-labs/authenticator/middleware github.com/devtron-labs/authenticator/oidc github.com/devtron-labs/authenticator/password -# github.com/devtron-labs/common-lib v0.0.25-0.20240812080926-4926120ea08d +# github.com/devtron-labs/common-lib v0.0.25-0.20240812093942-a996c33bc3d7 ## explicit; go 1.21 github.com/devtron-labs/common-lib/async github.com/devtron-labs/common-lib/blob-storage From 32e1592d2373e1baca0d24d80ea530882dc3d975 Mon Sep 17 00:00:00 2001 From: kartik-579 Date: Mon, 12 Aug 2024 17:10:28 +0530 Subject: [PATCH 2/2] updated common lib to f14be466613d --- go.mod | 2 +- go.sum | 4 ++-- vendor/modules.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index a1772ab674..3ebbc979a9 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 github.com/devtron-labs/authenticator v0.4.35-0.20240809073103-6e11da8083f8 - github.com/devtron-labs/common-lib v0.0.25-0.20240812093942-a996c33bc3d7 + github.com/devtron-labs/common-lib v0.0.25-0.20240812113340-f14be466613d github.com/devtron-labs/go-bitbucket v0.9.60-beta github.com/devtron-labs/protos v0.0.3-0.20240802105333-92ee9bb85d80 github.com/evanphx/json-patch v5.7.0+incompatible diff --git a/go.sum b/go.sum index 8c77ddfc5d..aafbebf99a 100644 --- a/go.sum +++ b/go.sum @@ -195,8 +195,8 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= github.com/devtron-labs/authenticator v0.4.35-0.20240809073103-6e11da8083f8 h1:2+Q7Jdhpo/uMiaQiZZzAh+ZX7wEJIFuMFG6DEiMuo64= github.com/devtron-labs/authenticator v0.4.35-0.20240809073103-6e11da8083f8/go.mod h1:702R6WIf5y9UzKGoCGxQ+x3l5Ws+l0fXg2xlCpSGFZI= -github.com/devtron-labs/common-lib v0.0.25-0.20240812093942-a996c33bc3d7 h1:XcMRNOBBZRXbjnWxgCxCpTGHljh1neWG3Gf4u7rhv3M= -github.com/devtron-labs/common-lib v0.0.25-0.20240812093942-a996c33bc3d7/go.mod h1:a7aCClaxYfnyYEENSe1RnkQCeW2AwmCAPYsuvgk0aW0= +github.com/devtron-labs/common-lib v0.0.25-0.20240812113340-f14be466613d h1:+iWXiVOyf9E0bcTia6x2sLFTM7xJc+9Z8q+BfbYr6eM= +github.com/devtron-labs/common-lib v0.0.25-0.20240812113340-f14be466613d/go.mod h1:a7aCClaxYfnyYEENSe1RnkQCeW2AwmCAPYsuvgk0aW0= github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU= github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y= github.com/devtron-labs/protos v0.0.3-0.20240802105333-92ee9bb85d80 h1:xwbTeijNTf4/j1v+tSfwVqwLVnReas/NqEKeQHvSTys= diff --git a/vendor/modules.txt b/vendor/modules.txt index 576d559ea0..b9a17ac490 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -401,7 +401,7 @@ github.com/devtron-labs/authenticator/jwt github.com/devtron-labs/authenticator/middleware github.com/devtron-labs/authenticator/oidc github.com/devtron-labs/authenticator/password -# github.com/devtron-labs/common-lib v0.0.25-0.20240812093942-a996c33bc3d7 +# github.com/devtron-labs/common-lib v0.0.25-0.20240812113340-f14be466613d ## explicit; go 1.21 github.com/devtron-labs/common-lib/async github.com/devtron-labs/common-lib/blob-storage