diff options
author | Konrad Bańka <k.banka@samsung.com> | 2021-02-25 00:08:05 +0100 |
---|---|---|
committer | Konrad Bańka <k.banka@samsung.com> | 2021-02-25 15:30:45 +0100 |
commit | 22a37f42a54c1acd2f095bc559ab03745e5ae7f9 (patch) | |
tree | 18be25e5475c5bf8d00d2e43a734d4eca2658a7b /src/k8splugin/internal/app/client.go | |
parent | fec64d4a5d7986e4d92b1350f31c9a3c81e82e6e (diff) |
Provide Healthcheck API MVP0.8.0
Implements basic functionality of running starting Healthcheck.
Results can be inspected so-far without dedicated API, by using, for
example, Query API.
Issue-ID: MULTICLOUD-1233
Signed-off-by: Konrad Bańka <k.banka@samsung.com>
Change-Id: Ia4d96d936d573173d7d8f41e6c39d059bf5f8b1f
Diffstat (limited to 'src/k8splugin/internal/app/client.go')
-rw-r--r-- | src/k8splugin/internal/app/client.go | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/src/k8splugin/internal/app/client.go b/src/k8splugin/internal/app/client.go index f0edf8c9..85fefe69 100644 --- a/src/k8splugin/internal/app/client.go +++ b/src/k8splugin/internal/app/client.go @@ -16,6 +16,7 @@ limitations under the License. package app import ( + "io/ioutil" "os" "strings" "time" @@ -32,9 +33,11 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/client-go/discovery" "k8s.io/client-go/discovery/cached/disk" "k8s.io/client-go/dynamic" "k8s.io/client-go/kubernetes" + "k8s.io/client-go/rest" "k8s.io/client-go/restmapper" "k8s.io/client-go/tools/clientcmd" ) @@ -42,6 +45,8 @@ import ( // KubernetesClient encapsulates the different clients' interfaces // we need when interacting with a Kubernetes cluster type KubernetesClient struct { + rawConfig clientcmd.ClientConfig + restConfig *rest.Config clientSet kubernetes.Interface dynamicClient dynamic.Interface discoverClient *disk.CachedDiscoveryClient @@ -168,8 +173,8 @@ func (k *KubernetesClient) getKubeConfig(cloudregion string) (string, error) { return kubeConfigPath, nil } -// init loads the Kubernetes configuation values stored into the local configuration file -func (k *KubernetesClient) init(cloudregion string, iid string) error { +// Init loads the Kubernetes configuation values stored into the local configuration file +func (k *KubernetesClient) Init(cloudregion string, iid string) error { if cloudregion == "" { return pkgerrors.New("Cloudregion is empty") } @@ -209,6 +214,21 @@ func (k *KubernetesClient) init(cloudregion string, iid string) error { } k.restMapper = restmapper.NewDeferredDiscoveryRESTMapper(k.discoverClient) + k.restConfig = config + + //Spawn ClientConfig + kubeFile, err := os.Open(configPath) + if err != nil { + return pkgerrors.Wrap(err, "Opening kubeConfig") + } + kubeData, err := ioutil.ReadAll(kubeFile) + if err != nil { + return pkgerrors.Wrap(err, "Reading kubeConfig") + } + k.rawConfig, err = clientcmd.NewClientConfigFromBytes(kubeData) + if err != nil { + return pkgerrors.Wrap(err, "Creating rawConfig") + } return nil } @@ -423,3 +443,18 @@ func (k *KubernetesClient) GetStandardClient() kubernetes.Interface { func (k *KubernetesClient) GetInstanceID() string { return k.instanceID } + +//Following set of methods are implemented so that KubernetesClient +//implements genericclioptions.RESTClientGetter interface +func (k *KubernetesClient) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error) { + return k.discoverClient, nil +} +func (k *KubernetesClient) ToRESTMapper() (meta.RESTMapper, error) { + return k.GetMapper(), nil +} +func (k *KubernetesClient) ToRawKubeConfigLoader() clientcmd.ClientConfig { + return k.rawConfig +} +func (k *KubernetesClient) ToRESTConfig() (*rest.Config, error) { + return k.restConfig, nil +} |