Skip to content

Commit

Permalink
Merge pull request #101 from kubescape/apiExtensionsClient
Browse files Browse the repository at this point in the history
Adding apiExtensionsClient
  • Loading branch information
David Wertenteil authored Jun 9, 2024
2 parents 2c77cfc + 97dd58c commit 2cb374b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
30 changes: 20 additions & 10 deletions k8sinterface/k8sconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 -
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 2cb374b

Please sign in to comment.