MCPcopy Index your code
hub / github.com/devspace-sh/devspace / NewClientFromContext

Function NewClientFromContext

pkg/devspace/kubectl/client.go:105–143  ·  view source on GitHub ↗

NewClientFromContext creates a new kubernetes client from given context @Factory

(context, namespace string, switchContext bool, kubeLoader kubeconfig.Loader)

Source from the content-addressed store, hash-verified

103
104// NewClientFromContext creates a new kubernetes client from given context @Factory
105func NewClientFromContext(context, namespace string, switchContext bool, kubeLoader kubeconfig.Loader) (Client, error) {
106 clientConfig, activeContext, activeNamespace, isInCluster, err := util.NewClientByContext(context, namespace, switchContext, kubeLoader)
107 if err != nil {
108 return nil, err
109 }
110
111 restConfig, err := clientConfig.ClientConfig()
112 if err != nil {
113 return nil, err
114 }
115 restConfig.UserAgent = "DevSpace Version " + upgrade.GetVersion()
116 restConfig.WrapTransport = func(rt http.RoundTripper) http.RoundTripper {
117 return &devSpaceRoundTripper{
118 roundTripper: rt,
119 requestType: "Regular",
120 callback: func(response *http.Response) {
121 if response.Header.Get("X-DevSpace-Response-Type") == "Blocked" {
122 kill.StopDevSpace("Targeted Kubernetes environment has begun sleeping. Please restart DevSpace to wake up the environment")
123 }
124 },
125 }
126 }
127
128 kubeClient, err := kubernetes.NewForConfig(restConfig)
129 if err != nil {
130 return nil, errors.Wrap(err, "new client")
131 }
132
133 return &client{
134 Client: kubeClient,
135 clientConfig: clientConfig,
136 restConfig: restConfig,
137 kubeLoader: kubeLoader,
138
139 namespace: activeNamespace,
140 currentContext: activeContext,
141 isInCluster: isInCluster,
142 }, nil
143}
144
145// ClientConfig returns the underlying kube client config
146func (client *client) ClientConfig() clientcmd.ClientConfig {

Callers 10

logsMethod · 0.92
getClientFromCacheMethod · 0.92
resolveDependencyMethod · 0.92
deploy.goFile · 0.92
TestUserAgentFunction · 0.85
TestCheckKubeContextFunction · 0.85
NewDefaultClientFunction · 0.85
CheckKubeContextFunction · 0.85

Calls 5

NewClientByContextFunction · 0.92
GetVersionFunction · 0.92
StopDevSpaceFunction · 0.92
ClientConfigMethod · 0.65
GetMethod · 0.45

Tested by 3

TestUserAgentFunction · 0.68
TestCheckKubeContextFunction · 0.68