mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Merge pull request #78345 from obitech/fix_golint_pkg_kubelet_stats_client
Fix golint pkg/kubelet/stats/client.go
This commit is contained in:
commit
663796e624
@ -107,7 +107,7 @@ func NewServerRunOptions() *ServerRunOptions {
|
|||||||
string(api.NodeExternalDNS),
|
string(api.NodeExternalDNS),
|
||||||
string(api.NodeExternalIP),
|
string(api.NodeExternalIP),
|
||||||
},
|
},
|
||||||
EnableHttps: true,
|
EnableHTTPS: true,
|
||||||
HTTPTimeout: time.Duration(5) * time.Second,
|
HTTPTimeout: time.Duration(5) * time.Second,
|
||||||
},
|
},
|
||||||
ServiceNodePortRange: kubeoptions.DefaultServiceNodePortRange,
|
ServiceNodePortRange: kubeoptions.DefaultServiceNodePortRange,
|
||||||
@ -185,7 +185,7 @@ func (s *ServerRunOptions) Flags() (fss cliflag.NamedFlagSets) {
|
|||||||
"Example: '30000-32767'. Inclusive at both ends of the range.")
|
"Example: '30000-32767'. Inclusive at both ends of the range.")
|
||||||
|
|
||||||
// Kubelet related flags:
|
// 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.")
|
"Use https for kubelet connections.")
|
||||||
|
|
||||||
fs.StringSliceVar(&s.KubeletConfig.PreferredAddressTypes, "kubelet-preferred-address-types", s.KubeletConfig.PreferredAddressTypes,
|
fs.StringSliceVar(&s.KubeletConfig.PreferredAddressTypes, "kubelet-preferred-address-types", s.KubeletConfig.PreferredAddressTypes,
|
||||||
|
@ -186,7 +186,7 @@ func TestAddFlags(t *testing.T) {
|
|||||||
string(kapi.NodeExternalDNS),
|
string(kapi.NodeExternalDNS),
|
||||||
string(kapi.NodeExternalIP),
|
string(kapi.NodeExternalIP),
|
||||||
},
|
},
|
||||||
EnableHttps: true,
|
EnableHTTPS: true,
|
||||||
HTTPTimeout: time.Duration(5) * time.Second,
|
HTTPTimeout: time.Duration(5) * time.Second,
|
||||||
TLSClientConfig: restclient.TLSClientConfig{
|
TLSClientConfig: restclient.TLSClientConfig{
|
||||||
CertFile: "/var/run/kubernetes/ceserver.crt",
|
CertFile: "/var/run/kubernetes/ceserver.crt",
|
||||||
|
@ -114,7 +114,6 @@ pkg/kubelet/apis/config
|
|||||||
pkg/kubelet/apis/config/v1beta1
|
pkg/kubelet/apis/config/v1beta1
|
||||||
pkg/kubelet/apis/deviceplugin/v1beta1
|
pkg/kubelet/apis/deviceplugin/v1beta1
|
||||||
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/container
|
pkg/kubelet/container
|
||||||
|
@ -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",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,14 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// LogMetricsService defines an interface for providing LogMetrics functionality.
|
||||||
type LogMetricsService interface {
|
type LogMetricsService interface {
|
||||||
createLogMetricsProvider(path string) volume.MetricsProvider
|
createLogMetricsProvider(path string) volume.MetricsProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
type logMetrics struct{}
|
type logMetrics struct{}
|
||||||
|
|
||||||
|
// NewLogMetricsService returns a new LogMetricsService type struct.
|
||||||
func NewLogMetricsService() LogMetricsService {
|
func NewLogMetricsService() LogMetricsService {
|
||||||
return logMetrics{}
|
return logMetrics{}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user