/
kube_config.go
33 lines (29 loc) · 985 Bytes
/
kube_config.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
package config
import (
"github.com/pachyderm/pachyderm/v2/src/internal/errors"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/clientcmd/api"
)
// KubeConfig gets the kubernetes config
func KubeConfig(context *Context) clientcmd.ClientConfig {
rules := clientcmd.NewDefaultClientConfigLoadingRules()
overrides := &clientcmd.ConfigOverrides{}
if context != nil {
overrides.Context = api.Context{
LocationOfOrigin: "pachyderm",
Cluster: context.ClusterName,
AuthInfo: context.AuthInfo,
Namespace: context.Namespace,
}
}
return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(rules, overrides)
}
// RawKubeConfig gets the "raw" kube config, e.g. without overrides
func RawKubeConfig() (api.Config, error) {
kubeConfig := KubeConfig(nil)
kubeRawConfig, err := kubeConfig.RawConfig()
if err != nil {
return api.Config{}, errors.Wrapf(err, "could not read raw kube config: %v", err)
}
return kubeRawConfig, nil
}