blob: e5da658f3a4f59c8dae6841dc571acea78138315 [file] [log] [blame]
Matthias Andreas Benkard832a54e2019-01-29 09:27:38 +01001// Copyright 2018 The Kubernetes Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package summary
16
17import (
18 "fmt"
19
20 "k8s.io/client-go/rest"
21)
22
23// GetKubeletConfig fetches connection config for connecting to the Kubelet.
24func GetKubeletConfig(baseKubeConfig *rest.Config, port int, insecureTLS bool, completelyInsecure bool) *KubeletClientConfig {
25 cfg := rest.CopyConfig(baseKubeConfig)
26 if completelyInsecure {
27 cfg = rest.AnonymousClientConfig(cfg) // don't use auth to avoid leaking auth details to insecure endpoints
28 cfg.TLSClientConfig = rest.TLSClientConfig{} // empty TLS config --> no TLS
29 } else if insecureTLS {
30 cfg.TLSClientConfig.Insecure = true
31 cfg.TLSClientConfig.CAData = nil
32 cfg.TLSClientConfig.CAFile = ""
33 }
34 kubeletConfig := &KubeletClientConfig{
35 Port: port,
36 RESTConfig: cfg,
37 DeprecatedCompletelyInsecure: completelyInsecure,
38 }
39
40 return kubeletConfig
41}
42
43// KubeletClientConfig represents configuration for connecting to Kubelets.
44type KubeletClientConfig struct {
45 Port int
46 RESTConfig *rest.Config
47 DeprecatedCompletelyInsecure bool
48}
49
50// KubeletClientFor constructs a new KubeletInterface for the given configuration.
51func KubeletClientFor(config *KubeletClientConfig) (KubeletInterface, error) {
52 transport, err := rest.TransportFor(config.RESTConfig)
53 if err != nil {
54 return nil, fmt.Errorf("unable to construct transport: %v", err)
55 }
56
57 return NewKubeletClient(transport, config.Port, config.DeprecatedCompletelyInsecure)
58}