Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.

Commit 7a8ea06

Browse files
uniemimutogashidm
authored andcommitted
add bind-api and a getter for kube client
This adds the bind API plus a getter for the kube client and makes the NewMetricsExtender return a pointer. Signed-off-by: Ukri Niemimuukko <ukri.niemimuukko@intel.com>
1 parent 3081377 commit 7a8ea06

File tree

6 files changed

+284
-1
lines changed

6 files changed

+284
-1
lines changed

extender/client.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package extender
2+
3+
import (
4+
"log"
5+
6+
"k8s.io/client-go/kubernetes"
7+
"k8s.io/client-go/rest"
8+
"k8s.io/client-go/tools/clientcmd"
9+
)
10+
11+
// GetKubeClient returns the kube client interface with its config.
12+
func GetKubeClient(kubeConfig string) (kubernetes.Interface, *rest.Config, error) {
13+
clientConfig, err := rest.InClusterConfig()
14+
if err != nil {
15+
log.Print("not in cluster - trying file-based configuration")
16+
clientConfig, err = clientcmd.BuildConfigFromFlags("", kubeConfig)
17+
if err != nil {
18+
return nil, nil, err
19+
}
20+
}
21+
kubeClient, err := kubernetes.NewForConfig(clientConfig)
22+
if err != nil {
23+
return nil, nil, err
24+
}
25+
return kubeClient, clientConfig, nil
26+
}

extender/go.mod

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@ module github.com/intel/platform-aware-scheduling/extender
22

33
go 1.15
44

5-
require k8s.io/api v0.20.2
5+
require (
6+
k8s.io/api v0.20.2
7+
k8s.io/apimachinery v0.20.2
8+
k8s.io/client-go v0.20.2
9+
k8s.io/klog/v2 v2.4.0
10+
)

0 commit comments

Comments
 (0)