-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.go
More file actions
40 lines (37 loc) · 1.38 KB
/
client.go
File metadata and controls
40 lines (37 loc) · 1.38 KB
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
// Package k8s provides Kubernetes client access.
package k8s
import (
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
)
// PodClient is a Kubernetes API client that lives inside of a Pod. Pods
// uniformly declare environment variables that we can use to establish a
// client connection.
//
// For a generic client that can read Kubectl configs, see LocalClient.
func PodClient() (*unversioned.Client, error) {
return unversioned.NewInCluster()
}
// LocalClient gets a Kubernetes client from the local environment.
//
// It does a lot of configuration file loading. Use it for cases where you
// have a kubectl client configured.
//
// For cases where you know exactly where the configuration information is,
// you should use Client.
//
// If you are constructing an interactive client, you may also want to look
// at the Kubernetes interactive client configuration.
func LocalClient() (*unversioned.Client, error) {
// Please, if you find these poor Java developers help them find their
// way out of the deep dark forests of Go, and back to the happy
// halls of IntelliJ.
rules := clientcmd.NewDefaultClientConfigLoadingRules()
cfg := &clientcmd.ConfigOverrides{}
kcfg := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(rules, cfg)
ccfg, err := kcfg.ClientConfig()
if err != nil {
return nil, err
}
return unversioned.New(ccfg)
}