Merge pull request #68544 from tanshanshan/lint912-2

fix golint for pkg/util/dbus, node, strings, workqueue/prometheus
This commit is contained in:
k8s-ci-robot 2018-10-23 16:44:31 -07:00 committed by GitHub
commit e7e6c8a95c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 38 deletions

View File

@ -375,7 +375,6 @@ pkg/ssh
pkg/util/bandwidth pkg/util/bandwidth
pkg/util/config pkg/util/config
pkg/util/configz pkg/util/configz
pkg/util/dbus
pkg/util/ebtables pkg/util/ebtables
pkg/util/env pkg/util/env
pkg/util/file pkg/util/file
@ -387,7 +386,6 @@ pkg/util/iptables/testing
pkg/util/labels pkg/util/labels
pkg/util/mount pkg/util/mount
pkg/util/netsh/testing pkg/util/netsh/testing
pkg/util/node
pkg/util/normalizer pkg/util/normalizer
pkg/util/oom pkg/util/oom
pkg/util/parsers pkg/util/parsers
@ -401,7 +399,6 @@ pkg/util/sysctl/testing
pkg/util/system pkg/util/system
pkg/util/taints pkg/util/taints
pkg/util/tolerations pkg/util/tolerations
pkg/util/workqueue/prometheus
pkg/version/verflag pkg/version/verflag
pkg/volume pkg/volume
pkg/volume/azure_dd pkg/volume/azure_dd

View File

@ -209,9 +209,8 @@ func TestFakeDBus(t *testing.T) {
checkName := args[0].(string) checkName := args[0].(string)
if checkName != ownedName { if checkName != ownedName {
return nil, godbus.Error{Name: "org.freedesktop.DBus.Error.NameHasNoOwner", Body: nil} return nil, godbus.Error{Name: "org.freedesktop.DBus.Error.NameHasNoOwner", Body: nil}
} else {
return []interface{}{uniqueName}, nil
} }
return []interface{}{uniqueName}, nil
} else if method == "org.freedesktop.DBus.RequestName" { } else if method == "org.freedesktop.DBus.RequestName" {
reqName := args[0].(string) reqName := args[0].(string)
_ = args[1].(uint32) _ = args[1].(uint32)

View File

@ -23,25 +23,25 @@ import (
godbus "github.com/godbus/dbus" godbus "github.com/godbus/dbus"
) )
// DBusFake is a simple fake Interface type. // Fake is a simple fake Interface type.
type DBusFake struct { type Fake struct {
systemBus *DBusFakeConnection systemBus *FakeConnection
sessionBus *DBusFakeConnection sessionBus *FakeConnection
} }
// DBusFakeConnection represents a fake D-Bus connection // FakeConnection represents a fake D-Bus connection
type DBusFakeConnection struct { type FakeConnection struct {
lock sync.Mutex lock sync.Mutex
busObject *fakeObject busObject *fakeObject
objects map[string]*fakeObject objects map[string]*fakeObject
signalHandlers []chan<- *godbus.Signal signalHandlers []chan<- *godbus.Signal
} }
// DBusFakeHandler is used to handle fake D-Bus method calls // FakeHandler is used to handle fake D-Bus method calls
type DBusFakeHandler func(method string, args ...interface{}) ([]interface{}, error) type FakeHandler func(method string, args ...interface{}) ([]interface{}, error)
type fakeObject struct { type fakeObject struct {
handler DBusFakeHandler handler FakeHandler
} }
type fakeCall struct { type fakeCall struct {
@ -50,46 +50,45 @@ type fakeCall struct {
} }
// NewFake returns a new Interface which will fake talking to D-Bus // NewFake returns a new Interface which will fake talking to D-Bus
func NewFake(systemBus *DBusFakeConnection, sessionBus *DBusFakeConnection) *DBusFake { func NewFake(systemBus *FakeConnection, sessionBus *FakeConnection) *Fake {
return &DBusFake{systemBus, sessionBus} return &Fake{systemBus, sessionBus}
} }
func NewFakeConnection() *DBusFakeConnection { // NewFakeConnection returns a FakeConnection Interface
return &DBusFakeConnection{ func NewFakeConnection() *FakeConnection {
return &FakeConnection{
objects: make(map[string]*fakeObject), objects: make(map[string]*fakeObject),
} }
} }
// SystemBus is part of Interface // SystemBus is part of Interface
func (db *DBusFake) SystemBus() (Connection, error) { func (db *Fake) SystemBus() (Connection, error) {
if db.systemBus != nil { if db.systemBus != nil {
return db.systemBus, nil return db.systemBus, nil
} else {
return nil, fmt.Errorf("DBus is not running")
} }
return nil, fmt.Errorf("DBus is not running")
} }
// SessionBus is part of Interface // SessionBus is part of Interface
func (db *DBusFake) SessionBus() (Connection, error) { func (db *Fake) SessionBus() (Connection, error) {
if db.sessionBus != nil { if db.sessionBus != nil {
return db.sessionBus, nil return db.sessionBus, nil
} else {
return nil, fmt.Errorf("DBus is not running")
} }
return nil, fmt.Errorf("DBus is not running")
} }
// BusObject is part of the Connection interface // BusObject is part of the Connection interface
func (conn *DBusFakeConnection) BusObject() Object { func (conn *FakeConnection) BusObject() Object {
return conn.busObject return conn.busObject
} }
// Object is part of the Connection interface // Object is part of the Connection interface
func (conn *DBusFakeConnection) Object(name, path string) Object { func (conn *FakeConnection) Object(name, path string) Object {
return conn.objects[name+path] return conn.objects[name+path]
} }
// Signal is part of the Connection interface // Signal is part of the Connection interface
func (conn *DBusFakeConnection) Signal(ch chan<- *godbus.Signal) { func (conn *FakeConnection) Signal(ch chan<- *godbus.Signal) {
conn.lock.Lock() conn.lock.Lock()
defer conn.lock.Unlock() defer conn.lock.Unlock()
for i := range conn.signalHandlers { for i := range conn.signalHandlers {
@ -102,17 +101,17 @@ func (conn *DBusFakeConnection) Signal(ch chan<- *godbus.Signal) {
} }
// SetBusObject sets the handler for the BusObject of conn // SetBusObject sets the handler for the BusObject of conn
func (conn *DBusFakeConnection) SetBusObject(handler DBusFakeHandler) { func (conn *FakeConnection) SetBusObject(handler FakeHandler) {
conn.busObject = &fakeObject{handler} conn.busObject = &fakeObject{handler}
} }
// AddObject adds a handler for the Object at name and path // AddObject adds a handler for the Object at name and path
func (conn *DBusFakeConnection) AddObject(name, path string, handler DBusFakeHandler) { func (conn *FakeConnection) AddObject(name, path string, handler FakeHandler) {
conn.objects[name+path] = &fakeObject{handler} conn.objects[name+path] = &fakeObject{handler}
} }
// EmitSignal emits a signal on conn // EmitSignal emits a signal on conn
func (conn *DBusFakeConnection) EmitSignal(name, path, iface, signal string, args ...interface{}) { func (conn *FakeConnection) EmitSignal(name, path, iface, signal string, args ...interface{}) {
conn.lock.Lock() conn.lock.Lock()
defer conn.lock.Unlock() defer conn.lock.Unlock()
sig := &godbus.Signal{ sig := &godbus.Signal{

View File

@ -36,9 +36,11 @@ import (
) )
const ( const (
// The reason and message set on a pod when its state cannot be confirmed as kubelet is unresponsive // NodeUnreachablePodReason is the reason on a pod when its state cannot be confirmed as kubelet is unresponsive
// on the node it is (was) running.
NodeUnreachablePodReason = "NodeLost"
// NodeUnreachablePodMessage is the message on a pod when its state cannot be confirmed as kubelet is unresponsive
// on the node it is (was) running. // on the node it is (was) running.
NodeUnreachablePodReason = "NodeLost"
NodeUnreachablePodMessage = "Node %v which was running pod %v is unresponsive" NodeUnreachablePodMessage = "Node %v which was running pod %v is unresponsive"
) )

View File

@ -22,7 +22,7 @@ import (
"unicode" "unicode"
) )
// SplitQualifiedName Splits a fully qualified name and returns its namespace and name. // SplitQualifiedName splits a fully qualified name and returns its namespace and name.
// Assumes that the input 'str' has been validated. // Assumes that the input 'str' has been validated.
func SplitQualifiedName(str string) (string, string) { func SplitQualifiedName(str string) (string, string) {
parts := strings.Split(str, "/") parts := strings.Split(str, "/")

View File

@ -31,7 +31,7 @@ func init() {
type prometheusMetricsProvider struct{} type prometheusMetricsProvider struct{}
func (_ prometheusMetricsProvider) NewDepthMetric(name string) workqueue.GaugeMetric { func (prometheusMetricsProvider) NewDepthMetric(name string) workqueue.GaugeMetric {
depth := prometheus.NewGauge(prometheus.GaugeOpts{ depth := prometheus.NewGauge(prometheus.GaugeOpts{
Subsystem: name, Subsystem: name,
Name: "depth", Name: "depth",
@ -41,7 +41,7 @@ func (_ prometheusMetricsProvider) NewDepthMetric(name string) workqueue.GaugeMe
return depth return depth
} }
func (_ prometheusMetricsProvider) NewAddsMetric(name string) workqueue.CounterMetric { func (prometheusMetricsProvider) NewAddsMetric(name string) workqueue.CounterMetric {
adds := prometheus.NewCounter(prometheus.CounterOpts{ adds := prometheus.NewCounter(prometheus.CounterOpts{
Subsystem: name, Subsystem: name,
Name: "adds", Name: "adds",
@ -51,7 +51,7 @@ func (_ prometheusMetricsProvider) NewAddsMetric(name string) workqueue.CounterM
return adds return adds
} }
func (_ prometheusMetricsProvider) NewLatencyMetric(name string) workqueue.SummaryMetric { func (prometheusMetricsProvider) NewLatencyMetric(name string) workqueue.SummaryMetric {
latency := prometheus.NewSummary(prometheus.SummaryOpts{ latency := prometheus.NewSummary(prometheus.SummaryOpts{
Subsystem: name, Subsystem: name,
Name: "queue_latency", Name: "queue_latency",
@ -61,7 +61,7 @@ func (_ prometheusMetricsProvider) NewLatencyMetric(name string) workqueue.Summa
return latency return latency
} }
func (_ prometheusMetricsProvider) NewWorkDurationMetric(name string) workqueue.SummaryMetric { func (prometheusMetricsProvider) NewWorkDurationMetric(name string) workqueue.SummaryMetric {
workDuration := prometheus.NewSummary(prometheus.SummaryOpts{ workDuration := prometheus.NewSummary(prometheus.SummaryOpts{
Subsystem: name, Subsystem: name,
Name: "work_duration", Name: "work_duration",
@ -71,7 +71,7 @@ func (_ prometheusMetricsProvider) NewWorkDurationMetric(name string) workqueue.
return workDuration return workDuration
} }
func (_ prometheusMetricsProvider) NewRetriesMetric(name string) workqueue.CounterMetric { func (prometheusMetricsProvider) NewRetriesMetric(name string) workqueue.CounterMetric {
retries := prometheus.NewCounter(prometheus.CounterOpts{ retries := prometheus.NewCounter(prometheus.CounterOpts{
Subsystem: name, Subsystem: name,
Name: "retries", Name: "retries",