forked from intel/platform-aware-scheduling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
37 lines (28 loc) · 947 Bytes
/
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
// 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) {
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)
}
}
kubeClient, err := kubernetes.NewForConfig(clientConfig)
if err != nil {
return nil, nil, fmt.Errorf("failed to create kubeClientset %w", err)
}
clientConfig.Burst = 50
clientConfig.QPS = 20
return kubeClient, clientConfig, nil
}