From 97dd58c941afbc5fd6470bd26bba7e1aeebfb741 Mon Sep 17 00:00:00 2001 From: David Wertenteil Date: Sun, 9 Jun 2024 17:45:54 +0300 Subject: [PATCH] adding apiExtensionsClient Signed-off-by: David Wertenteil --- go.mod | 3 ++- go.sum | 5 ++++- k8sinterface/k8sconfig.go | 30 ++++++++++++++++++++---------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index b68deee..f23cab9 100644 --- a/go.mod +++ b/go.mod @@ -24,6 +24,7 @@ require ( golang.org/x/oauth2 v0.12.0 google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d k8s.io/api v0.29.0 + k8s.io/apiextensions-apiserver v0.27.2 k8s.io/apimachinery v0.29.0 k8s.io/client-go v0.29.0 k8s.io/utils v0.0.0-20230726121419-3b25d923346b @@ -47,7 +48,7 @@ require ( github.com/magiconair/properties v1.8.1 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect - github.com/mitchellh/mapstructure v1.1.2 // indirect + github.com/mitchellh/mapstructure v1.4.1 // indirect github.com/olvrng/ujson v1.1.0 // indirect github.com/pelletier/go-toml v1.2.0 // indirect github.com/spf13/afero v1.6.0 // indirect diff --git a/go.sum b/go.sum index 3a179ff..0dbf6c9 100644 --- a/go.sum +++ b/go.sum @@ -342,8 +342,9 @@ github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eI github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= +github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -792,6 +793,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= k8s.io/api v0.29.0 h1:NiCdQMY1QOp1H8lfRyeEf8eOwV6+0xA6XEE44ohDX2A= k8s.io/api v0.29.0/go.mod h1:sdVmXoz2Bo/cb77Pxi71IPTSErEW32xa4aXwKH7gfBA= +k8s.io/apiextensions-apiserver v0.27.2 h1:iwhyoeS4xj9Y7v8YExhUwbVuBhMr3Q4bd/laClBV6Bo= +k8s.io/apiextensions-apiserver v0.27.2/go.mod h1:Oz9UdvGguL3ULgRdY9QMUzL2RZImotgxvGjdWRq6ZXQ= k8s.io/apimachinery v0.29.0 h1:+ACVktwyicPz0oc6MTMLwa2Pw3ouLAfAon1wPLtG48o= k8s.io/apimachinery v0.29.0/go.mod h1:eVBxQ/cwiJxH58eK/jd/vAk4mrxmVlnpBH5J2GbMeis= k8s.io/client-go v0.29.0 h1:KmlDtFcrdUzOYrBhXHgKw5ycWzc3ryPX5mQe0SkG3y8= diff --git a/k8sinterface/k8sconfig.go b/k8sinterface/k8sconfig.go index 6be67d7..7adc402 100644 --- a/k8sinterface/k8sconfig.go +++ b/k8sinterface/k8sconfig.go @@ -5,6 +5,8 @@ import ( "fmt" "strings" + "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" + logger "github.com/kubescape/go-logger" "github.com/kubescape/go-logger/helpers" "k8s.io/client-go/discovery" @@ -30,11 +32,12 @@ var clientConfigAPI *clientcmdapi.Config // KubernetesApi - type KubernetesApi struct { - KubernetesClient kubernetes.Interface - DynamicClient dynamic.Interface - DiscoveryClient discovery.DiscoveryInterface - Context context.Context - K8SConfig *restclient.Config + ApiExtensionsClient clientset.Interface + KubernetesClient kubernetes.Interface + DynamicClient dynamic.Interface + DiscoveryClient discovery.DiscoveryInterface + Context context.Context + K8SConfig *restclient.Config } // NewKubernetesApi - @@ -62,15 +65,22 @@ func NewKubernetesApi() *KubernetesApi { if err != nil { logger.L().Fatal("failed to initialize a new discovery client", helpers.Error(err)) } + + apiExtensionsClient, err := clientset.NewForConfig(k8sConfig) + if err != nil { + logger.L().Fatal("failed to initialize a new discovery client", helpers.Error(err)) + } + restclient.SetDefaultWarningHandler(restclient.NoWarnings{}) InitializeMapResources(discoveryClient) return &KubernetesApi{ - KubernetesClient: kubernetesClient, - DynamicClient: dynamicClient, - DiscoveryClient: discoveryClient, - Context: context.Background(), - K8SConfig: k8sConfig, + ApiExtensionsClient: apiExtensionsClient, + KubernetesClient: kubernetesClient, + DynamicClient: dynamicClient, + DiscoveryClient: discoveryClient, + Context: context.Background(), + K8SConfig: k8sConfig, } } func (k8sAPI *KubernetesApi) GetKubernetesClient() kubernetes.Interface {