Merge pull request #7755 from tanjunchen/fix-up-static-error

fix-up staticcheck error
This commit is contained in:
Kubernetes Prow Robot 2019-10-13 08:20:35 -07:00 committed by GitHub
commit 34c7d5a64a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 23 additions and 25 deletions

View File

@ -56,11 +56,11 @@ func (c *ResourceRecordChangeset) Apply() error {
for _, removal := range c.removals { for _, removal := range c.removals {
rrID, err := c.nameToID(removal.Name()) rrID, err := c.nameToID(removal.Name())
if err != nil { if err != nil {
return err
} }
err = recordsets.Delete(c.zone.zones.iface.sc, zoneID, rrID).ExtractErr() err = recordsets.Delete(c.zone.zones.iface.sc, zoneID, rrID).ExtractErr()
if err != nil { if err != nil {
return err
} }
} }
@ -73,14 +73,14 @@ func (c *ResourceRecordChangeset) Apply() error {
} }
_, err := recordsets.Create(c.zone.zones.iface.sc, zoneID, opts).Extract() _, err := recordsets.Create(c.zone.zones.iface.sc, zoneID, opts).Extract()
if err != nil { if err != nil {
return err
} }
} }
for _, upsert := range c.upserts { for _, upsert := range c.upserts {
rrID, err := c.nameToID(upsert.Name()) rrID, err := c.nameToID(upsert.Name())
if err != nil { if err != nil {
return err
} }
uopts := recordsets.UpdateOpts{ uopts := recordsets.UpdateOpts{
TTL: int(upsert.Ttl()), TTL: int(upsert.Ttl()),
@ -96,7 +96,7 @@ func (c *ResourceRecordChangeset) Apply() error {
} }
_, err := recordsets.Create(c.zone.zones.iface.sc, zoneID, copts).Extract() _, err := recordsets.Create(c.zone.zones.iface.sc, zoneID, copts).Extract()
if err != nil { if err != nil {
return err
} }
} }
} }

View File

@ -398,13 +398,13 @@ func (c *NodeupModelContext) UseSecureKubelet() bool {
// @check if we have anything specific to master kubelet // @check if we have anything specific to master kubelet
if c.IsMaster { if c.IsMaster {
if cluster.MasterKubelet != nil && cluster.MasterKubelet.AnonymousAuth != nil && *cluster.MasterKubelet.AnonymousAuth == false { if cluster.MasterKubelet != nil && cluster.MasterKubelet.AnonymousAuth != nil && !*cluster.MasterKubelet.AnonymousAuth {
return true return true
} }
} }
// @check the default settings for master and kubelet // @check the default settings for master and kubelet
if cluster.Kubelet != nil && cluster.Kubelet.AnonymousAuth != nil && *cluster.Kubelet.AnonymousAuth == false { if cluster.Kubelet != nil && cluster.Kubelet.AnonymousAuth != nil && !*cluster.Kubelet.AnonymousAuth {
return true return true
} }

View File

@ -48,9 +48,9 @@ type Visitor interface {
} }
func visit(visitor Visitor, data interface{}, path []string, mutator func(interface{})) error { func visit(visitor Visitor, data interface{}, path []string, mutator func(interface{})) error {
switch data.(type) { switch data := data.(type) {
case string: case string:
err := visitor.VisitString(path, data.(string), func(v string) { err := visitor.VisitString(path, data, func(v string) {
mutator(v) mutator(v)
}) })
if err != nil { if err != nil {
@ -58,7 +58,7 @@ func visit(visitor Visitor, data interface{}, path []string, mutator func(interf
} }
case bool: case bool:
err := visitor.VisitBool(path, data.(bool), func(v bool) { err := visitor.VisitBool(path, data, func(v bool) {
mutator(v) mutator(v)
}) })
if err != nil { if err != nil {
@ -66,7 +66,7 @@ func visit(visitor Visitor, data interface{}, path []string, mutator func(interf
} }
case float64: case float64:
err := visitor.VisitFloat64(path, data.(float64), func(v float64) { err := visitor.VisitFloat64(path, data, func(v float64) {
mutator(v) mutator(v)
}) })
if err != nil { if err != nil {
@ -74,7 +74,7 @@ func visit(visitor Visitor, data interface{}, path []string, mutator func(interf
} }
case map[string]interface{}: case map[string]interface{}:
m := data.(map[string]interface{}) m := data
for k, v := range m { for k, v := range m {
path = append(path, k) path = append(path, k)
@ -88,7 +88,7 @@ func visit(visitor Visitor, data interface{}, path []string, mutator func(interf
} }
case []interface{}: case []interface{}:
s := data.([]interface{}) s := data
for i, v := range s { for i, v := range s {
path = append(path, fmt.Sprintf("[%d]", i)) path = append(path, fmt.Sprintf("[%d]", i))

View File

@ -69,7 +69,7 @@ func (b *KubeletOptionsBuilder) BuildOptions(o interface{}) error {
if clusterSpec.Kubelet.AllowPrivileged != nil { if clusterSpec.Kubelet.AllowPrivileged != nil {
// If it is explicitly set to false, return an error, because this // If it is explicitly set to false, return an error, because this
// behavior is no longer supported in v1.14 (the default was true, prior). // behavior is no longer supported in v1.14 (the default was true, prior).
if *clusterSpec.Kubelet.AllowPrivileged == false { if !*clusterSpec.Kubelet.AllowPrivileged {
klog.Warningf("Kubelet's --allow-privileged flag is no longer supported in v1.14.") klog.Warningf("Kubelet's --allow-privileged flag is no longer supported in v1.14.")
} }
// Explicitly set it to nil, so it won't be passed on the command line. // Explicitly set it to nil, so it won't be passed on the command line.

View File

@ -307,7 +307,7 @@ func (m *KopsModelContext) UseLoadBalancerForAPI() bool {
// HA - see https://github.com/kubernetes/kops/issues/4252 // HA - see https://github.com/kubernetes/kops/issues/4252
func (m *KopsModelContext) UseLoadBalancerForInternalAPI() bool { func (m *KopsModelContext) UseLoadBalancerForInternalAPI() bool {
return m.UseLoadBalancerForAPI() && return m.UseLoadBalancerForAPI() &&
m.Cluster.Spec.API.LoadBalancer.UseForInternalApi == true m.Cluster.Spec.API.LoadBalancer.UseForInternalApi
} }
// UsePrivateDNS checks if we are using private DNS // UsePrivateDNS checks if we are using private DNS

View File

@ -230,7 +230,7 @@ func addUntaggedRouteTables(cloud awsup.AWSCloud, clusterName string, resources
isMain := false isMain := false
for _, a := range rt.Associations { for _, a := range rt.Associations {
if aws.BoolValue(a.Main) == true { if aws.BoolValue(a.Main) {
isMain = true isMain = true
} }
} }

View File

@ -244,7 +244,7 @@ func buildCertificateDirectories(c *EtcdCluster) []string {
tracked := make(map[string]bool, 0) tracked := make(map[string]bool, 0)
for _, x := range []string{c.TLSCA, c.TLSCert, c.TLSKey, c.PeerCA, c.PeerKey, c.PeerKey} { for _, x := range []string{c.TLSCA, c.TLSCert, c.TLSKey, c.PeerCA, c.PeerKey, c.PeerKey} {
if x == "" || tracked[filepath.Dir(x)] == true { if x == "" || tracked[filepath.Dir(x)] {
continue continue
} }
tracked[filepath.Dir(x)] = true tracked[filepath.Dir(x)] = true

View File

@ -102,7 +102,7 @@ func waitForOp(op *compute.Operation, getOperation func(operationName string) (*
return wait.Poll(operationPollInterval, operationPollTimeoutDuration, func() (bool, error) { return wait.Poll(operationPollInterval, operationPollTimeoutDuration, func() (bool, error) {
start := time.Now() start := time.Now()
//gce.operationPollRateLimiter.Accept() //gce.operationPollRateLimiter.Accept()
duration := time.Now().Sub(start) duration := time.Since(start)
if duration > 5*time.Second { if duration > 5*time.Second {
klog.Infof("pollOperation: throttled %v for %v", duration, opName) klog.Infof("pollOperation: throttled %v for %v", duration, opName)
} }
@ -112,7 +112,7 @@ func waitForOp(op *compute.Operation, getOperation func(operationName string) (*
} }
done := opIsDone(pollOp) done := opIsDone(pollOp)
if done { if done {
duration := time.Now().Sub(opStart) duration := time.Since(opStart)
if duration > 1*time.Minute { if duration > 1*time.Minute {
// Log the JSON. It's cleaner than the %v structure. // Log the JSON. It's cleaner than the %v structure.
enc, err := pollOp.MarshalJSON() enc, err := pollOp.MarshalJSON()

View File

@ -803,9 +803,7 @@ func (_ *Elastigroup) update(cloud awsup.AWSCloud, a, e, changes *Elastigroup) e
} }
types := make([]string, len(e.SpotInstanceTypes)) types := make([]string, len(e.SpotInstanceTypes))
for i, typ := range e.SpotInstanceTypes { copy(types, e.SpotInstanceTypes)
types[i] = typ
}
group.Compute.InstanceTypes.SetSpot(types) group.Compute.InstanceTypes.SetSpot(types)
changes.SpotInstanceTypes = nil changes.SpotInstanceTypes = nil

View File

@ -69,7 +69,7 @@ func (v *astSanitizer) visitObjectItem(o *ast.ObjectItem) {
v := text[1 : len(text)-1] v := text[1 : len(text)-1]
safe := true safe := true
for _, c := range v { for _, c := range v {
if strings.IndexRune(safeChars, c) == -1 { if !strings.ContainsRune(safeChars, c) {
safe = false safe = false
break break
} }

View File

@ -28,14 +28,14 @@ func SanitizeString(s string) string {
var out bytes.Buffer var out bytes.Buffer
allowed := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-" allowed := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-"
for _, c := range s { for _, c := range s {
if strings.IndexRune(allowed, c) != -1 { if strings.ContainsRune(allowed, c) {
out.WriteRune(c) out.WriteRune(c)
} else { } else {
out.WriteRune('_') out.WriteRune('_')
} }
} }
return string(out.Bytes()) return out.String()
} }
// ExpandPath replaces common path aliases: ~ -> $HOME // ExpandPath replaces common path aliases: ~ -> $HOME