Skip to content

Commit

Permalink
fix-up some gosimple check
Browse files Browse the repository at this point in the history
  • Loading branch information
tanjunchen committed Oct 15, 2019
1 parent d84e761 commit 896b5b3
Show file tree
Hide file tree
Showing 17 changed files with 20 additions and 36 deletions.
2 changes: 1 addition & 1 deletion node-authorizer/cmd/node-authorizer/server.go
Expand Up @@ -155,7 +155,7 @@ func actionServerCommand(ctx *cli.Context) error {

// waitForCertificates is responsible for waiting for the certificates to appear
func waitForCertificates(files []string, timeout time.Duration) error {
doneCh := make(chan struct{}, 0)
doneCh := make(chan struct{})

go func() {
expires := time.Now().Add(timeout)
Expand Down
4 changes: 2 additions & 2 deletions node-authorizer/pkg/authorizers/aws/verifier.go
Expand Up @@ -49,8 +49,8 @@ func NewVerifier() (server.Verifier, error) {

// Verify is responsible for build a identification document
func (a *awsNodeVerifier) VerifyIdentity(ctx context.Context) ([]byte, error) {
errs := make(chan error, 0)
doneCh := make(chan []byte, 0)
errs := make(chan error)
doneCh := make(chan []byte)

go func() {
encoded, err := func() ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion node-authorizer/pkg/server/admission.go
Expand Up @@ -35,7 +35,7 @@ var (

// authorizeNodeRequest is responsible for handling the incoming authorization request
func (n *NodeAuthorizer) authorizeNodeRequest(ctx context.Context, request *NodeRegistration) error {
doneCh := make(chan error, 0)
doneCh := make(chan error)

// @step: create a context to run under
ctx, cancel := context.WithTimeout(ctx, n.config.AuthorizationTimeout)
Expand Down
6 changes: 1 addition & 5 deletions nodeup/pkg/model/docker.go
Expand Up @@ -805,11 +805,7 @@ func (d *dockerVersion) matches(arch Architecture, dockerVersion string, distro
foundArch = true
}
}
if !foundArch {
return false
}

return true
return foundArch
}

func (b *DockerBuilder) dockerVersion() string {
Expand Down
2 changes: 1 addition & 1 deletion nodeup/pkg/model/file_assets.go
Expand Up @@ -43,7 +43,7 @@ var templateFuncs = template.FuncMap{
// Build is responsible for writing out the file assets from cluster and instanceGroup
func (f *FileAssetsBuilder) Build(c *fi.ModelBuilderContext) error {
// used to keep track of previous file, so a instanceGroup can override a cluster wide one
tracker := make(map[string]bool, 0)
tracker := make(map[string]bool)

// ensure the default path exists
c.EnsureTask(&nodetasks.File{
Expand Down
2 changes: 1 addition & 1 deletion nodeup/pkg/model/hooks.go
Expand Up @@ -39,7 +39,7 @@ var _ fi.ModelBuilder = &HookBuilder{}
// Build is responsible for implementing the cluster hook
func (h *HookBuilder) Build(c *fi.ModelBuilderContext) error {
// we keep a list of hooks name so we can allow local instanceGroup hooks override the cluster ones
hookNames := make(map[string]bool, 0)
hookNames := make(map[string]bool)
for i, spec := range []*[]kops.HookSpec{&h.InstanceGroup.Spec.Hooks, &h.Cluster.Spec.Hooks} {
for j, hook := range *spec {
isInstanceGroup := i == 0
Expand Down
2 changes: 1 addition & 1 deletion nodeup/pkg/model/kube_apiserver.go
Expand Up @@ -503,7 +503,7 @@ func (b *KubeAPIServerBuilder) buildAnnotations() map[string]string {
annotations := make(map[string]string)

if b.Cluster.Spec.API != nil {
if b.Cluster.Spec.API.LoadBalancer == nil || b.Cluster.Spec.API.LoadBalancer.UseForInternalApi != true {
if b.Cluster.Spec.API.LoadBalancer == nil || !b.Cluster.Spec.API.LoadBalancer.UseForInternalApi {
annotations["dns.alpha.kubernetes.io/internal"] = b.Cluster.Spec.MasterInternalName
}

Expand Down
2 changes: 1 addition & 1 deletion nodeup/pkg/model/kube_proxy.go
Expand Up @@ -44,7 +44,7 @@ var _ fi.ModelBuilder = &KubeAPIServerBuilder{}
// @TODO we should probably change this to a daemonset in the future and follow the kubeadm path
func (b *KubeProxyBuilder) Build(c *fi.ModelBuilderContext) error {

if b.Cluster.Spec.KubeProxy.Enabled != nil && *b.Cluster.Spec.KubeProxy.Enabled == false {
if b.Cluster.Spec.KubeProxy.Enabled != nil && !*b.Cluster.Spec.KubeProxy.Enabled {
klog.V(2).Infof("Kube-proxy is disabled, will not create configuration for it.")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/kops/validation/instancegroup.go
Expand Up @@ -98,7 +98,7 @@ func ValidateInstanceGroup(g *kops.InstanceGroup) error {

// @step: iterate and check the volume specs
for i, x := range g.Spec.Volumes {
devices := make(map[string]bool, 0)
devices := make(map[string]bool)
path := field.NewPath("volumes").Index(i)

if err := validateVolumeSpec(path, x); err != nil {
Expand Down
5 changes: 1 addition & 4 deletions pkg/dns/gossip.go
Expand Up @@ -21,8 +21,5 @@ import "strings"
// TODO: Are .local names necessarily invalid for "real DNS"? Do we need more qualification here?
func IsGossipHostname(name string) bool {
normalized := "." + strings.TrimSuffix(name, ".")
if strings.HasSuffix(normalized, ".k8s.local") {
return true
}
return false
return strings.HasSuffix(normalized, ".k8s.local")
}
5 changes: 1 addition & 4 deletions pkg/drain/cordon.go
Expand Up @@ -62,10 +62,7 @@ func NewCordonHelperFromRuntimeObject(nodeObject runtime.Object, scheme *runtime
// or false when no change is needed
func (c *CordonHelper) UpdateIfRequired(desired bool) bool {
c.desired = desired
if c.node.Spec.Unschedulable == c.desired {
return false
}
return true
return c.node.Spec.Unschedulable != c.desired
}

// PatchOrReplace uses given clientset to update the node status, either by patching or
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/bootstrapscript.go
Expand Up @@ -181,7 +181,7 @@ func (b *BootstrapScript) ResourceNodeUp(ig *kops.InstanceGroup, cluster *kops.C

if ig.IsMaster() {
spec["encryptionConfig"] = cs.EncryptionConfig
spec["etcdClusters"] = make(map[string]kops.EtcdClusterSpec, 0)
spec["etcdClusters"] = make(map[string]kops.EtcdClusterSpec)
spec["kubeAPIServer"] = cs.KubeAPIServer
spec["kubeControllerManager"] = cs.KubeControllerManager
spec["kubeScheduler"] = cs.KubeScheduler
Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/fi/cloudup/alitasks/vpc.go
Expand Up @@ -79,7 +79,7 @@ func (e *VPC) Find(c *fi.Context) (*VPC, error) {
}
}

if vpcs == nil || len(vpcs) == 0 {
if len(vpcs) == 0 {
return nil, nil
}

Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/fi/cloudup/aliup/ali_cloud.go
Expand Up @@ -328,7 +328,7 @@ func ZoneToVSwitchID(VPCID string, zones []string, vswitchIDs []string) (map[str
return res, fmt.Errorf("error describing VPC: %v", err)
}

if vpc == nil || len(vpc) == 0 {
if len(vpc) == 0 {
return res, fmt.Errorf("VPC %q not found", VPCID)
}

Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/fi/cloudup/awstasks/helper.go
Expand Up @@ -42,7 +42,7 @@ func buildEphemeralDevices(cloud awsup.AWSCloud, machineType string) (map[string

// buildAdditionalDevices is responsible for creating additional volumes in this lc
func buildAdditionalDevices(volumes []*BlockDeviceMapping) (map[string]*BlockDeviceMapping, error) {
devices := make(map[string]*BlockDeviceMapping, 0)
devices := make(map[string]*BlockDeviceMapping)

// @step: iterate the volumes and create devices from them
for _, x := range volumes {
Expand Down
4 changes: 2 additions & 2 deletions upup/pkg/fi/cloudup/openstacktasks/volume.go
Expand Up @@ -70,10 +70,10 @@ func (c *Volume) Find(context *fi.Context) (*Volume, error) {
}
// remove tags "readonly" and "attached_mode", openstack are adding these and if not removed
// kops will always try to update volumes
if _, ok := actual.Tags["readonly"]; ok {
if actual.Tags["readonly"] != "" {
delete(actual.Tags, "readonly")
}
if _, ok := actual.Tags["attached_mode"]; ok {
if actual.Tags["attached_mode"] != "" {
delete(actual.Tags, "attached_mode")
}
c.ID = actual.ID
Expand Down
10 changes: 2 additions & 8 deletions util/pkg/reflectutils/walk.go
Expand Up @@ -137,8 +137,6 @@ func reflectRecursive(path string, v reflect.Value, visitor visitorFunc) error {
}
}
}
break

case reflect.Map:
keys := v.MapKeys()
for _, key := range keys {
Expand All @@ -156,8 +154,6 @@ func reflectRecursive(path string, v reflect.Value, visitor visitorFunc) error {
}
}
}
break

case reflect.Array, reflect.Slice:
len := v.Len()
for i := 0; i < len; i++ {
Expand All @@ -175,8 +171,6 @@ func reflectRecursive(path string, v reflect.Value, visitor visitorFunc) error {
}
}
}
break

case reflect.Ptr, reflect.Interface:
if !v.IsNil() {
e := v.Elem()
Expand All @@ -185,9 +179,9 @@ func reflectRecursive(path string, v reflect.Value, visitor visitorFunc) error {
return err
}
}
break
default:
klog.Fatalf("Unhandled kind: %v", v.Kind())
}

return nil
}

Expand Down

0 comments on commit 896b5b3

Please sign in to comment.