mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 12:32:03 +00:00
Fix golint issues in pkg/kubelet/client
Add comments to exported functions in `pkg/kubelet/client/client.go` In `KubeletClientConfig` rename `EnableHttps` to `EnableHTTPS`. This requires renaming it in `pkg/kubelet/client/client_test.go`
This commit is contained in:
parent
f780ac028b
commit
16d64d6925
@ -151,7 +151,6 @@ pkg/kubelet/apis/deviceplugin/v1beta1
|
|||||||
pkg/kubelet/cadvisor
|
pkg/kubelet/cadvisor
|
||||||
pkg/kubelet/cadvisor/testing
|
pkg/kubelet/cadvisor/testing
|
||||||
pkg/kubelet/checkpointmanager/testing/example_checkpoint_formats/v1
|
pkg/kubelet/checkpointmanager/testing/example_checkpoint_formats/v1
|
||||||
pkg/kubelet/client
|
|
||||||
pkg/kubelet/cm
|
pkg/kubelet/cm
|
||||||
pkg/kubelet/config
|
pkg/kubelet/config
|
||||||
pkg/kubelet/configmap
|
pkg/kubelet/configmap
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
utilnet "k8s.io/apimachinery/pkg/util/net"
|
utilnet "k8s.io/apimachinery/pkg/util/net"
|
||||||
@ -31,11 +31,16 @@ import (
|
|||||||
nodeutil "k8s.io/kubernetes/pkg/util/node"
|
nodeutil "k8s.io/kubernetes/pkg/util/node"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// KubeletClientConfig defines config parameters for the kubelet client
|
||||||
type KubeletClientConfig struct {
|
type KubeletClientConfig struct {
|
||||||
// Default port - used if no information about Kubelet port can be found in Node.NodeStatus.DaemonEndpoints.
|
// Port specifies the default port - used if no information about Kubelet port can be found in Node.NodeStatus.DaemonEndpoints.
|
||||||
Port uint
|
Port uint
|
||||||
|
|
||||||
|
// ReadOnlyPort specifies the Port for ReadOnly communications.
|
||||||
ReadOnlyPort uint
|
ReadOnlyPort uint
|
||||||
EnableHttps bool
|
|
||||||
|
// EnableHTTPs specifies if traffic should be encrypted.
|
||||||
|
EnableHTTPS bool
|
||||||
|
|
||||||
// PreferredAddressTypes - used to select an address from Node.NodeStatus.Addresses
|
// PreferredAddressTypes - used to select an address from Node.NodeStatus.Addresses
|
||||||
PreferredAddressTypes []string
|
PreferredAddressTypes []string
|
||||||
@ -66,6 +71,7 @@ type ConnectionInfoGetter interface {
|
|||||||
GetConnectionInfo(ctx context.Context, nodeName types.NodeName) (*ConnectionInfo, error)
|
GetConnectionInfo(ctx context.Context, nodeName types.NodeName) (*ConnectionInfo, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MakeTransport creates a RoundTripper for HTTP Transport.
|
||||||
func MakeTransport(config *KubeletClientConfig) (http.RoundTripper, error) {
|
func MakeTransport(config *KubeletClientConfig) (http.RoundTripper, error) {
|
||||||
tlsConfig, err := transport.TLSConfigFor(config.transportConfig())
|
tlsConfig, err := transport.TLSConfigFor(config.transportConfig())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -96,7 +102,7 @@ func (c *KubeletClientConfig) transportConfig() *transport.Config {
|
|||||||
},
|
},
|
||||||
BearerToken: c.BearerToken,
|
BearerToken: c.BearerToken,
|
||||||
}
|
}
|
||||||
if c.EnableHttps && !cfg.HasCA() {
|
if c.EnableHTTPS && !cfg.HasCA() {
|
||||||
cfg.TLS.Insecure = true
|
cfg.TLS.Insecure = true
|
||||||
}
|
}
|
||||||
return cfg
|
return cfg
|
||||||
@ -110,6 +116,7 @@ type NodeGetter interface {
|
|||||||
// NodeGetterFunc allows implementing NodeGetter with a function
|
// NodeGetterFunc allows implementing NodeGetter with a function
|
||||||
type NodeGetterFunc func(ctx context.Context, name string, options metav1.GetOptions) (*v1.Node, error)
|
type NodeGetterFunc func(ctx context.Context, name string, options metav1.GetOptions) (*v1.Node, error)
|
||||||
|
|
||||||
|
// Get fetches information via NodeGetterFunc.
|
||||||
func (f NodeGetterFunc) Get(ctx context.Context, name string, options metav1.GetOptions) (*v1.Node, error) {
|
func (f NodeGetterFunc) Get(ctx context.Context, name string, options metav1.GetOptions) (*v1.Node, error) {
|
||||||
return f(ctx, name, options)
|
return f(ctx, name, options)
|
||||||
}
|
}
|
||||||
@ -128,9 +135,10 @@ type NodeConnectionInfoGetter struct {
|
|||||||
preferredAddressTypes []v1.NodeAddressType
|
preferredAddressTypes []v1.NodeAddressType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewNodeConnectionInfoGetter creates a new NodeConnectionInfoGetter.
|
||||||
func NewNodeConnectionInfoGetter(nodes NodeGetter, config KubeletClientConfig) (ConnectionInfoGetter, error) {
|
func NewNodeConnectionInfoGetter(nodes NodeGetter, config KubeletClientConfig) (ConnectionInfoGetter, error) {
|
||||||
scheme := "http"
|
scheme := "http"
|
||||||
if config.EnableHttps {
|
if config.EnableHTTPS {
|
||||||
scheme = "https"
|
scheme = "https"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,6 +162,7 @@ func NewNodeConnectionInfoGetter(nodes NodeGetter, config KubeletClientConfig) (
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetConnectionInfo retrieves connection info from the status of a Node API object.
|
||||||
func (k *NodeConnectionInfoGetter) GetConnectionInfo(ctx context.Context, nodeName types.NodeName) (*ConnectionInfo, error) {
|
func (k *NodeConnectionInfoGetter) GetConnectionInfo(ctx context.Context, nodeName types.NodeName) (*ConnectionInfo, error) {
|
||||||
node, err := k.nodes.Get(ctx, string(nodeName), metav1.GetOptions{})
|
node, err := k.nodes.Get(ctx, string(nodeName), metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
|
|
||||||
func TestMakeTransportInvalid(t *testing.T) {
|
func TestMakeTransportInvalid(t *testing.T) {
|
||||||
config := &KubeletClientConfig{
|
config := &KubeletClientConfig{
|
||||||
EnableHttps: true,
|
EnableHTTPS: true,
|
||||||
//Invalid certificate and key path
|
//Invalid certificate and key path
|
||||||
TLSClientConfig: restclient.TLSClientConfig{
|
TLSClientConfig: restclient.TLSClientConfig{
|
||||||
CertFile: "../../client/testdata/mycertinvalid.cer",
|
CertFile: "../../client/testdata/mycertinvalid.cer",
|
||||||
@ -45,12 +45,12 @@ func TestMakeTransportInvalid(t *testing.T) {
|
|||||||
func TestMakeTransportValid(t *testing.T) {
|
func TestMakeTransportValid(t *testing.T) {
|
||||||
config := &KubeletClientConfig{
|
config := &KubeletClientConfig{
|
||||||
Port: 1234,
|
Port: 1234,
|
||||||
EnableHttps: true,
|
EnableHTTPS: true,
|
||||||
TLSClientConfig: restclient.TLSClientConfig{
|
TLSClientConfig: restclient.TLSClientConfig{
|
||||||
CertFile: "../../client/testdata/mycertvalid.cer",
|
CertFile: "../../client/testdata/mycertvalid.cer",
|
||||||
// TLS Configuration, only applies if EnableHttps is true.
|
// TLS Configuration, only applies if EnableHTTPS is true.
|
||||||
KeyFile: "../../client/testdata/mycertvalid.key",
|
KeyFile: "../../client/testdata/mycertvalid.key",
|
||||||
// TLS Configuration, only applies if EnableHttps is true.
|
// TLS Configuration, only applies if EnableHTTPS is true.
|
||||||
CAFile: "../../client/testdata/myCA.cer",
|
CAFile: "../../client/testdata/myCA.cer",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user