Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Enable "gosimple" linter plugin (#3802)
Browse files Browse the repository at this point in the history
  • Loading branch information
mboersma authored and jackfrancis committed Sep 7, 2018
1 parent 6589616 commit 8eda202
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 56 deletions.
4 changes: 2 additions & 2 deletions pkg/acsengine/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,12 +618,12 @@ func TestSetVMSSDefaults(t *testing.T) {

properties.AgentPoolProfiles[0].Count = 110
setPropertiesDefaults(&mockCS, false, false)
if *properties.AgentPoolProfiles[0].SinglePlacementGroup != false {
if helpers.IsTrueBoolPointer(properties.AgentPoolProfiles[0].SinglePlacementGroup) {
t.Fatalf("AgentPoolProfile[0].SinglePlacementGroup did not have the expected configuration, got %t, expected %t",
*properties.AgentPoolProfiles[0].SinglePlacementGroup, false)
}

if *properties.AgentPoolProfiles[0].SinglePlacementGroup == false && properties.AgentPoolProfiles[0].StorageProfile != api.ManagedDisks {
if !*properties.AgentPoolProfiles[0].SinglePlacementGroup && properties.AgentPoolProfiles[0].StorageProfile != api.ManagedDisks {
t.Fatalf("AgentPoolProfile[0].StorageProfile did not have the expected configuration, got %s, expected %s",
properties.AgentPoolProfiles[0].StorageProfile, api.ManagedDisks)
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/acsengine/tenantid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func TestGetTenantID_UnexpectedResponse(t *testing.T) {

mux.HandleFunc("/subscriptions/foobarsubscription", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest)
return
})

_, err := GetTenantID(server.URL, "foobarsubscription")
Expand All @@ -70,7 +69,6 @@ func TestGetTenantID_InvalidHeader(t *testing.T) {
mux.HandleFunc("/subscriptions/foobarsubscription", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusUnauthorized)
w.Header().Set("fookey", "bazvalue")
return
})

_, err := GetTenantID(server.URL, "foobarsubscription")
Expand Down
2 changes: 1 addition & 1 deletion pkg/acsengine/transform/apimodel_merger.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type APIModelValue struct {

// MapValues converts an arraw of rwa ApiModel values (like ["masterProfile.count=4","linuxProfile.adminUsername=admin"]) to a map
func MapValues(m map[string]APIModelValue, setFlagValues []string) {
if setFlagValues == nil || len(setFlagValues) == 0 {
if len(setFlagValues) == 0 {
return
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/api/agentPoolOnlyApi/v20180331/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"github.com/Azure/acs-engine/pkg/api/common"
"github.com/Azure/acs-engine/pkg/helpers"
"github.com/pkg/errors"
validator "gopkg.in/go-playground/validator.v9"
)
Expand Down Expand Up @@ -40,7 +41,7 @@ func (l *LinuxProfile) Validate() error {

// Validate implements APIObject
func (a *AADProfile) Validate(rbacEnabled *bool) error {
if rbacEnabled == nil || *rbacEnabled == false {
if !helpers.IsTrueBoolPointer(rbacEnabled) {
return ErrorRBACNotEnabledForAAD
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/api/converterfromagentpoolonlyapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func TestConvertToV20180331AddonProfile(t *testing.T) {
if _, ok := p[addonName]; !ok {
t.Error("addon is not found")
}
if p[addonName].Enabled != true {
if !p[addonName].Enabled {
t.Error("addon should be enabled")
}
v, ok := p[addonName].Config["opt1"]
Expand All @@ -244,7 +244,6 @@ func TestConvertToV20180331AddonProfile(t *testing.T) {

func TestConvertKubernetesConfigToEnableRBACV20180331AgentPoolOnly(t *testing.T) {
var kc *KubernetesConfig
kc = nil
enableRBAC := convertKubernetesConfigToEnableRBACV20180331AgentPoolOnly(kc)
if enableRBAC == nil {
t.Error("EnableRBAC expected not to be nil")
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/convertertoagentpoolonlyapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func convertV20180331AgentPoolOnlyWindowsProfile(obj *v20180331.WindowsProfile)
}

func convertV20180331AgentPoolOnlyKubernetesConfig(enableRBAC *bool) *KubernetesConfig {
if enableRBAC != nil && *enableRBAC == true {
if helpers.IsTrueBoolPointer(enableRBAC) {
// We set default behavior to be false
return &KubernetesConfig{
EnableRbac: helpers.PointerToBool(true),
Expand Down
21 changes: 10 additions & 11 deletions pkg/api/convertertoagentpoolonlyapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func TestConvertFromV20180331AddonProfile(t *testing.T) {
if _, ok := api[addonName]; !ok {
t.Error("addon is not found")
}
if api[addonName].Enabled != true {
if !api[addonName].Enabled {
t.Error("addon should be enabled")
}
v, ok := api[addonName].Config["opt1"]
Expand All @@ -226,19 +226,18 @@ func TestConvertV20170831AgentPoolOnlyOrchestratorProfile_KubernetesConfig(t *te
t.Error("OrchestratorProfile.KubernetesConfig expected not to be nil")
}

if op.KubernetesConfig.EnableRbac == nil || *op.KubernetesConfig.EnableRbac == true {
if helpers.IsTrueBoolPointer(op.KubernetesConfig.EnableRbac) {
t.Error("OrchestratorProfile.KubernetesConfig.EnableRbac expected to be *false")
}

if op.KubernetesConfig.EnableSecureKubelet == nil || *op.KubernetesConfig.EnableSecureKubelet == true {
if helpers.IsTrueBoolPointer(op.KubernetesConfig.EnableSecureKubelet) {
t.Error("OrchestratorProfile.KubernetesConfig.EnableSecureKubelet expected to be *false")
}

}

func TestConvertV20180331AgentPoolOnlyKubernetesConfig(t *testing.T) {
var kc *KubernetesConfig
kc = convertV20180331AgentPoolOnlyKubernetesConfig(helpers.PointerToBool(true))
var kc = convertV20180331AgentPoolOnlyKubernetesConfig(helpers.PointerToBool(true))
if kc == nil {
t.Error("kubernetesConfig expected not to be nil")
}
Expand All @@ -247,15 +246,15 @@ func TestConvertV20180331AgentPoolOnlyKubernetesConfig(t *testing.T) {
t.Error("EnableRbac expected not to be nil")
}

if *kc.EnableRbac != true {
if !*kc.EnableRbac {
t.Error("EnableRbac expected to be true")
}

if kc.EnableSecureKubelet == nil {
t.Error("EnableSecureKubelet expected not to be nil")
}

if *kc.EnableSecureKubelet != true {
if !*kc.EnableSecureKubelet {
t.Error("EnableSecureKubelet expected to be true")
}

Expand All @@ -272,15 +271,15 @@ func TestConvertV20180331AgentPoolOnlyKubernetesConfig(t *testing.T) {
t.Error("EnableRbac expected not to be nil")
}

if *kc.EnableRbac != false {
if helpers.IsTrueBoolPointer(kc.EnableRbac) {
t.Error("EnableRbac expected to be false")
}

if kc.EnableSecureKubelet == nil {
t.Error("EnableSecureKubelet expected not to be nil")
}

if *kc.EnableSecureKubelet != false {
if helpers.IsTrueBoolPointer(kc.EnableSecureKubelet) {
t.Error("EnableSecureKubelet expected to be false")
}

Expand All @@ -297,15 +296,15 @@ func TestConvertV20180331AgentPoolOnlyKubernetesConfig(t *testing.T) {
t.Error("EnableRbac expected not to be nil")
}

if *kc.EnableRbac != false {
if helpers.IsTrueBoolPointer(kc.EnableRbac) {
t.Error("EnableRbac expected to be false")
}

if kc.EnableSecureKubelet == nil {
t.Error("EnableSecureKubelet expected not to be nil")
}

if *kc.EnableSecureKubelet != false {
if helpers.IsTrueBoolPointer(kc.EnableSecureKubelet) {
t.Error("EnableSecureKubelet expected to be false")
}

Expand Down
48 changes: 28 additions & 20 deletions pkg/api/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const exampleUserMSIModel = `{
"orchestratorType": "Kubernetes",
"kubernetesConfig": {
"useManagedIdentity": true,
"userAssignedID": "` + exampleUserMSI + `"
"userAssignedID": "` + exampleUserMSI + `"
}
},
"masterProfile": { "count": 1, "dnsPrefix": "", "vmSize": "Standard_D2_v2" },
Expand Down Expand Up @@ -799,7 +799,7 @@ func TestUserAssignedMSI(t *testing.T) {
}
systemMSI := apiModel.Properties.OrchestratorProfile.KubernetesConfig.UseManagedIdentity
actualUserMSI := apiModel.Properties.OrchestratorProfile.KubernetesConfig.UserAssignedID
if systemMSI != true || actualUserMSI != "" {
if !systemMSI || actualUserMSI != "" {
t.Fatalf("found user msi: %t and usermsi: %s", systemMSI, actualUserMSI)
}

Expand All @@ -814,7 +814,7 @@ func TestUserAssignedMSI(t *testing.T) {
}
systemMSI = apiModel.Properties.OrchestratorProfile.KubernetesConfig.UseManagedIdentity
actualUserMSI = apiModel.Properties.OrchestratorProfile.KubernetesConfig.UserAssignedID
if systemMSI != true && actualUserMSI != exampleUserMSI {
if !systemMSI && actualUserMSI != exampleUserMSI {
t.Fatalf("found user msi: %t and usermsi: %s", systemMSI, actualUserMSI)
}
}
Expand Down Expand Up @@ -853,8 +853,9 @@ func TestIsTillerEnabled(t *testing.T) {
},
}
enabled := c.IsTillerEnabled()
if enabled != DefaultTillerAddonEnabled {
t.Fatalf("KubernetesConfig.IsTillerEnabled() should return %t when no tiller addon has been specified, instead returned %t", DefaultTillerAddonEnabled, enabled)
enabledDefault := DefaultTillerAddonEnabled
if enabled != enabledDefault {
t.Fatalf("KubernetesConfig.IsTillerEnabled() should return %t when no tiller addon has been specified, instead returned %t", enabledDefault, enabled)
}
c.Addons = append(c.Addons, getMockAddon(DefaultTillerAddonName))
enabled = c.IsTillerEnabled()
Expand Down Expand Up @@ -883,8 +884,9 @@ func TestIsACIConnectorEnabled(t *testing.T) {
},
}
enabled := c.IsACIConnectorEnabled()
if enabled != DefaultACIConnectorAddonEnabled {
t.Fatalf("KubernetesConfig.IsACIConnectorEnabled() should return %t when no ACI connector addon has been specified, instead returned %t", DefaultACIConnectorAddonEnabled, enabled)
enabledDefault := DefaultACIConnectorAddonEnabled
if enabled != enabledDefault {
t.Fatalf("KubernetesConfig.IsACIConnectorEnabled() should return %t when no ACI connector addon has been specified, instead returned %t", enabledDefault, enabled)
}
c.Addons = append(c.Addons, getMockAddon(DefaultACIConnectorAddonName))
enabled = c.IsACIConnectorEnabled()
Expand Down Expand Up @@ -913,8 +915,9 @@ func TestIsClusterAutoscalerEnabled(t *testing.T) {
},
}
enabled := c.IsClusterAutoscalerEnabled()
if enabled != DefaultClusterAutoscalerAddonEnabled {
t.Fatalf("KubernetesConfig.IsAutoscalerEnabled() should return %t when no cluster autoscaler addon has been specified, instead returned %t", DefaultClusterAutoscalerAddonEnabled, enabled)
enabledDefault := DefaultClusterAutoscalerAddonEnabled
if enabled != enabledDefault {
t.Fatalf("KubernetesConfig.IsAutoscalerEnabled() should return %t when no cluster autoscaler addon has been specified, instead returned %t", enabledDefault, enabled)
}
c.Addons = append(c.Addons, getMockAddon(DefaultClusterAutoscalerAddonName))
enabled = c.IsClusterAutoscalerEnabled()
Expand Down Expand Up @@ -995,16 +998,17 @@ func TestIsContainerMonitoringEnabled(t *testing.T) {
},
}
enabled := o.KubernetesConfig.IsContainerMonitoringEnabled()
if enabled != DefaultContainerMonitoringAddonEnabled {
t.Fatalf("KubernetesConfig.IsContainerMonitoringEnabled() should return %t for kubernetes version %s when no container-monitoring addon has been specified, instead returned %t", DefaultContainerMonitoringAddonEnabled, v, enabled)
enabledDefault := DefaultContainerMonitoringAddonEnabled
if enabled != enabledDefault {
t.Fatalf("KubernetesConfig.IsContainerMonitoringEnabled() should return %t for kubernetes version %s when no container-monitoring addon has been specified, instead returned %t", enabledDefault, v, enabled)
}

b := true
cm := getMockAddon(ContainerMonitoringAddonName)
cm.Enabled = &b
o.KubernetesConfig.Addons = append(o.KubernetesConfig.Addons, cm)
enabled = o.KubernetesConfig.IsContainerMonitoringEnabled()
if enabled != true {
if !enabled {
t.Fatalf("KubernetesConfig.IsContainerMonitoringEnabled() should return %t for kubernetes version %s when the container-monitoring addon has been specified, instead returned %t", true, v, enabled)
}

Expand Down Expand Up @@ -1033,8 +1037,9 @@ func TestIsDashboardEnabled(t *testing.T) {
},
}
enabled := c.IsDashboardEnabled()
if enabled != DefaultDashboardAddonEnabled {
t.Fatalf("KubernetesConfig.IsDashboardEnabled() should return %t when no kubernetes-dashboard addon has been specified, instead returned %t", DefaultDashboardAddonEnabled, enabled)
enabledDefault := DefaultDashboardAddonEnabled
if enabled != enabledDefault {
t.Fatalf("KubernetesConfig.IsDashboardEnabled() should return %t when no kubernetes-dashboard addon has been specified, instead returned %t", enabledDefault, enabled)
}
c.Addons = append(c.Addons, getMockAddon(DefaultDashboardAddonName))
enabled = c.IsDashboardEnabled()
Expand Down Expand Up @@ -1063,8 +1068,9 @@ func TestIsReschedulerEnabled(t *testing.T) {
},
}
enabled := c.IsReschedulerEnabled()
if enabled != DefaultReschedulerAddonEnabled {
t.Fatalf("KubernetesConfig.IsReschedulerEnabled() should return %t when no rescheduler addon has been specified, instead returned %t", DefaultReschedulerAddonEnabled, enabled)
enabledDefault := DefaultReschedulerAddonEnabled
if enabled != enabledDefault {
t.Fatalf("KubernetesConfig.IsReschedulerEnabled() should return %t when no rescheduler addon has been specified, instead returned %t", enabledDefault, enabled)
}
c.Addons = append(c.Addons, getMockAddon(DefaultReschedulerAddonName))
enabled = c.IsReschedulerEnabled()
Expand Down Expand Up @@ -1097,14 +1103,16 @@ func TestIsMetricsServerEnabled(t *testing.T) {
},
}
enabled := o.IsMetricsServerEnabled()
if enabled != DefaultMetricsServerAddonEnabled {
t.Fatalf("KubernetesConfig.IsMetricsServerEnabled() should return %t for kubernetes version %s when no metrics-server addon has been specified, instead returned %t", DefaultMetricsServerAddonEnabled, v, enabled)
enabledDefault := DefaultMetricsServerAddonEnabled
if enabled != enabledDefault {
t.Fatalf("KubernetesConfig.IsMetricsServerEnabled() should return %t for kubernetes version %s when no metrics-server addon has been specified, instead returned %t", enabledDefault, v, enabled)
}

o.KubernetesConfig.Addons = append(o.KubernetesConfig.Addons, getMockAddon(DefaultMetricsServerAddonName))
enabled = o.IsMetricsServerEnabled()
if enabled != DefaultMetricsServerAddonEnabled {
t.Fatalf("KubernetesConfig.IsMetricsServerEnabled() should return %t for kubernetes version %s when the metrics-server addon has been specified, instead returned %t", DefaultMetricsServerAddonEnabled, v, enabled)
enabledDefault = DefaultMetricsServerAddonEnabled
if enabled != enabledDefault {
t.Fatalf("KubernetesConfig.IsMetricsServerEnabled() should return %t for kubernetes version %s when the metrics-server addon has been specified, instead returned %t", enabledDefault, v, enabled)
}

b := true
Expand Down
2 changes: 1 addition & 1 deletion pkg/armhelpers/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (az *AzureClient) CreateRoleAssignmentSimple(ctx context.Context, resourceG
},
}

re := regexp.MustCompile("(?i)status=(\\d+)")
re := regexp.MustCompile(`(?i)status=(\d+)`)
for {
_, err := az.CreateRoleAssignment(
ctx,
Expand Down
2 changes: 1 addition & 1 deletion pkg/helpers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ EPDesL0rH+3s1CKpgkhYdbJ675GFoGoq+X21QaqsdvoXmmuJF9qq9Tq+JaWloUNq
pemBuffer := bytes.Buffer{}
pem.Encode(&pemBuffer, pemBlock)

if string(pemBuffer.Bytes()) != expectedPrivateKeyString {
if pemBuffer.String() != expectedPrivateKeyString {
t.Fatalf("Private Key did not match expected format/value")
}

Expand Down
3 changes: 2 additions & 1 deletion scripts/validate-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ gometalinter \
--enable deadcode \
--enable gofmt \
--enable goimports \
--enable gosimple \
--enable ineffassign \
--enable misspell \
--enable unused \
--enable vet \
--tests \
--vendor \
--deadline 60s \
--deadline 120s \
--skip test/i18n \
--skip pkg/test \
--exclude pkg/i18n/i18n.go \
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/azure/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,7 @@ func (a *Account) IsClusterExpired(d time.Duration) bool {

// FetchActivityLog gets all the failures from the activity log for the provided resource group.
func (a *Account) FetchActivityLog(rg string) (string, error) {
var cmd *exec.Cmd
cmd = exec.Command("az", "monitor", "activity-log", "list", "--resource-group", rg, "--status", "Failed")
var cmd = exec.Command("az", "monitor", "activity-log", "list", "--resource-group", rg, "--status", "Failed")
util.PrintCommand(cmd)
out, err := cmd.CombinedOutput()
if err != nil {
Expand Down
11 changes: 2 additions & 9 deletions test/e2e/engine/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,7 @@ func (e *Engine) HasAddon(name string) (bool, api.KubernetesAddon) {

// HasNetworkPolicy will return true if the specified network policy is enabled
func (e *Engine) HasNetworkPolicy(name string) bool {
if strings.Contains(e.ExpandedDefinition.Properties.OrchestratorProfile.KubernetesConfig.NetworkPolicy, name) {
return true
}

return false
return strings.Contains(e.ExpandedDefinition.Properties.OrchestratorProfile.KubernetesConfig.NetworkPolicy, name)
}

// HasAllZonesAgentPools will return true if all of the agent pools have zones
Expand All @@ -251,10 +247,7 @@ func (e *Engine) HasAllZonesAgentPools() bool {
count++
}
}
if count == len(e.ExpandedDefinition.Properties.AgentPoolProfiles) {
return true
}
return false
return count == len(e.ExpandedDefinition.Properties.AgentPoolProfiles)
}

// Write will write the cluster definition to disk
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/kubernetes/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (d *Deployment) WaitForReplicas(n int, sleep, duration time.Duration) ([]po
select {
case err := <-errCh:
return pods, err
case _ = <-readyCh:
case <-readyCh:
return pods, nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/kubernetes/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ func (p *Pod) ValidateOmsAgentLogs(execCmdString string, sleep, duration time.Du

// CheckWindowsOutboundConnection will keep retrying the check if an error is received until the timeout occurs or it passes. This helps us when DNS may not be available for some time after a pod starts.
func (p *Pod) CheckWindowsOutboundConnection(sleep, duration time.Duration) (bool, error) {
exp, err := regexp.Compile("(StatusCode\\s*:\\s*200)")
exp, err := regexp.Compile(`(StatusCode\s*:\s*200)`)
if err != nil {
log.Printf("Error while trying to create regex for windows outbound check:%s\n", err)
return false, err
Expand Down

0 comments on commit 8eda202

Please sign in to comment.