-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathclient.go
42 lines (32 loc) · 1.2 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (C) 2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
package extender
import (
"fmt"
"k8s.io/klog/v2"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)
// GetKubeClient returns the kube client interface with its config.
func GetKubeClient(kubeConfig string) (kubernetes.Interface, *rest.Config, error) {
return GetKubeClientExt(kubeConfig, 0, 0)
}
// GetKubeClientExt returns the kube client interface with its config. The given Burst and QPS are set into the config.
func GetKubeClientExt(kubeConfig string, burst int, qps float32) (kubernetes.Interface, *rest.Config, error) {
clientConfig, err := rest.InClusterConfig()
if err != nil {
klog.V(l2).InfoS("not in cluster - trying file-based configuration", "component", "controller")
clientConfig, err = clientcmd.BuildConfigFromFlags("", kubeConfig)
if err != nil {
return nil, nil, fmt.Errorf("failed to get clientconfig: %w", err)
}
}
clientConfig.Burst = burst
clientConfig.QPS = qps
kubeClient, err := kubernetes.NewForConfig(clientConfig)
if err != nil {
return nil, nil, fmt.Errorf("failed to create kubeClientset %w", err)
}
return kubeClient, clientConfig, nil
}