Merge pull request #78345 from obitech/fix_golint_pkg_kubelet_stats_client

Fix golint pkg/kubelet/stats/client.go
This commit is contained in:
Kubernetes Prow Robot 2019-08-06 13:14:49 -07:00 committed by GitHub
commit 663796e624
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 14 deletions

View File

@ -107,7 +107,7 @@ func NewServerRunOptions() *ServerRunOptions {
string(api.NodeExternalDNS),
string(api.NodeExternalIP),
},
EnableHttps: true,
EnableHTTPS: true,
HTTPTimeout: time.Duration(5) * time.Second,
},
ServiceNodePortRange: kubeoptions.DefaultServiceNodePortRange,
@ -185,7 +185,7 @@ func (s *ServerRunOptions) Flags() (fss cliflag.NamedFlagSets) {
"Example: '30000-32767'. Inclusive at both ends of the range.")
// Kubelet related flags:
fs.BoolVar(&s.KubeletConfig.EnableHttps, "kubelet-https", s.KubeletConfig.EnableHttps,
fs.BoolVar(&s.KubeletConfig.EnableHTTPS, "kubelet-https", s.KubeletConfig.EnableHTTPS,
"Use https for kubelet connections.")
fs.StringSliceVar(&s.KubeletConfig.PreferredAddressTypes, "kubelet-preferred-address-types", s.KubeletConfig.PreferredAddressTypes,

View File

@ -186,7 +186,7 @@ func TestAddFlags(t *testing.T) {
string(kapi.NodeExternalDNS),
string(kapi.NodeExternalIP),
},
EnableHttps: true,
EnableHTTPS: true,
HTTPTimeout: time.Duration(5) * time.Second,
TLSClientConfig: restclient.TLSClientConfig{
CertFile: "/var/run/kubernetes/ceserver.crt",

View File

@ -114,7 +114,6 @@ pkg/kubelet/apis/config
pkg/kubelet/apis/config/v1beta1
pkg/kubelet/apis/deviceplugin/v1beta1
pkg/kubelet/checkpointmanager/testing/example_checkpoint_formats/v1
pkg/kubelet/client
pkg/kubelet/cm
pkg/kubelet/config
pkg/kubelet/container

View File

@ -22,7 +22,7 @@ import (
"strconv"
"time"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
utilnet "k8s.io/apimachinery/pkg/util/net"
@ -31,11 +31,16 @@ import (
nodeutil "k8s.io/kubernetes/pkg/util/node"
)
// KubeletClientConfig defines config parameters for the kubelet client
type KubeletClientConfig struct {
// Default port - used if no information about Kubelet port can be found in Node.NodeStatus.DaemonEndpoints.
Port uint
// Port specifies the default port - used if no information about Kubelet port can be found in Node.NodeStatus.DaemonEndpoints.
Port uint
// ReadOnlyPort specifies the Port for ReadOnly communications.
ReadOnlyPort uint
EnableHttps bool
// EnableHTTPs specifies if traffic should be encrypted.
EnableHTTPS bool
// PreferredAddressTypes - used to select an address from Node.NodeStatus.Addresses
PreferredAddressTypes []string
@ -66,6 +71,7 @@ type ConnectionInfoGetter interface {
GetConnectionInfo(ctx context.Context, nodeName types.NodeName) (*ConnectionInfo, error)
}
// MakeTransport creates a RoundTripper for HTTP Transport.
func MakeTransport(config *KubeletClientConfig) (http.RoundTripper, error) {
tlsConfig, err := transport.TLSConfigFor(config.transportConfig())
if err != nil {
@ -96,7 +102,7 @@ func (c *KubeletClientConfig) transportConfig() *transport.Config {
},
BearerToken: c.BearerToken,
}
if c.EnableHttps && !cfg.HasCA() {
if c.EnableHTTPS && !cfg.HasCA() {
cfg.TLS.Insecure = true
}
return cfg
@ -110,6 +116,7 @@ type NodeGetter interface {
// NodeGetterFunc allows implementing NodeGetter with a function
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) {
return f(ctx, name, options)
}
@ -128,9 +135,10 @@ type NodeConnectionInfoGetter struct {
preferredAddressTypes []v1.NodeAddressType
}
// NewNodeConnectionInfoGetter creates a new NodeConnectionInfoGetter.
func NewNodeConnectionInfoGetter(nodes NodeGetter, config KubeletClientConfig) (ConnectionInfoGetter, error) {
scheme := "http"
if config.EnableHttps {
if config.EnableHTTPS {
scheme = "https"
}
@ -154,6 +162,7 @@ func NewNodeConnectionInfoGetter(nodes NodeGetter, config KubeletClientConfig) (
}, 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) {
node, err := k.nodes.Get(ctx, string(nodeName), metav1.GetOptions{})
if err != nil {

View File

@ -24,7 +24,7 @@ import (
func TestMakeTransportInvalid(t *testing.T) {
config := &KubeletClientConfig{
EnableHttps: true,
EnableHTTPS: true,
//Invalid certificate and key path
TLSClientConfig: restclient.TLSClientConfig{
CertFile: "../../client/testdata/mycertinvalid.cer",
@ -45,12 +45,12 @@ func TestMakeTransportInvalid(t *testing.T) {
func TestMakeTransportValid(t *testing.T) {
config := &KubeletClientConfig{
Port: 1234,
EnableHttps: true,
EnableHTTPS: true,
TLSClientConfig: restclient.TLSClientConfig{
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",
// TLS Configuration, only applies if EnableHttps is true.
// TLS Configuration, only applies if EnableHTTPS is true.
CAFile: "../../client/testdata/myCA.cer",
},
}

View File

@ -20,12 +20,14 @@ import (
"k8s.io/kubernetes/pkg/volume"
)
// LogMetricsService defines an interface for providing LogMetrics functionality.
type LogMetricsService interface {
createLogMetricsProvider(path string) volume.MetricsProvider
}
type logMetrics struct{}
// NewLogMetricsService returns a new LogMetricsService type struct.
func NewLogMetricsService() LogMetricsService {
return logMetrics{}
}