-
Notifications
You must be signed in to change notification settings - Fork 560
Enable "gosimple" linter plugin #3802
Changes from 1 commit
9bdea9f
4e9ac75
ca83a88
98b8d7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 *properties.AgentPoolProfiles[0].SinglePlacementGroup { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need the |
||
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) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no... really, are you sure you're unset? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ func (l *LinuxProfile) Validate() error { | |
|
||
// Validate implements APIObject | ||
func (a *AADProfile) Validate(rbacEnabled *bool) error { | ||
if rbacEnabled == nil || *rbacEnabled == false { | ||
if rbacEnabled == nil || !*rbacEnabled { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see
|
||
return ErrorRBACNotEnabledForAAD | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"] | ||
|
@@ -244,7 +244,6 @@ func TestConvertToV20180331AddonProfile(t *testing.T) { | |
|
||
func TestConvertKubernetesConfigToEnableRBACV20180331AgentPoolOnly(t *testing.T) { | ||
var kc *KubernetesConfig | ||
kc = nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol I'm surprised the compiler accepts this |
||
enableRBAC := convertKubernetesConfigToEnableRBACV20180331AgentPoolOnly(kc) | ||
if enableRBAC == nil { | ||
t.Error("EnableRBAC expected not to be nil") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -384,7 +384,7 @@ func convertV20180331AgentPoolOnlyWindowsProfile(obj *v20180331.WindowsProfile) | |
} | ||
|
||
func convertV20180331AgentPoolOnlyKubernetesConfig(enableRBAC *bool) *KubernetesConfig { | ||
if enableRBAC != nil && *enableRBAC == true { | ||
if enableRBAC != nil && *enableRBAC { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see my above suggestion |
||
// We set default behavior to be false | ||
return &KubernetesConfig{ | ||
EnableRbac: helpers.PointerToBool(true), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"] | ||
|
@@ -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 op.KubernetesConfig.EnableRbac == nil || *op.KubernetesConfig.EnableRbac { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
t.Error("OrchestratorProfile.KubernetesConfig.EnableRbac expected to be *false") | ||
} | ||
|
||
if op.KubernetesConfig.EnableSecureKubelet == nil || *op.KubernetesConfig.EnableSecureKubelet == true { | ||
if op.KubernetesConfig.EnableSecureKubelet == nil || *op.KubernetesConfig.EnableSecureKubelet { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💥 |
||
if kc == nil { | ||
t.Error("kubernetesConfig expected not to be nil") | ||
} | ||
|
@@ -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") | ||
} | ||
|
||
|
@@ -272,15 +271,15 @@ func TestConvertV20180331AgentPoolOnlyKubernetesConfig(t *testing.T) { | |
t.Error("EnableRbac expected not to be nil") | ||
} | ||
|
||
if *kc.EnableRbac != false { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wow |
||
if *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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
if *kc.EnableSecureKubelet { | ||
t.Error("EnableSecureKubelet expected to be false") | ||
} | ||
|
||
|
@@ -297,15 +296,15 @@ func TestConvertV20180331AgentPoolOnlyKubernetesConfig(t *testing.T) { | |
t.Error("EnableRbac expected not to be nil") | ||
} | ||
|
||
if *kc.EnableRbac != false { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... |
||
if *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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make it stop There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It stops here. |
||
if *kc.EnableSecureKubelet { | ||
t.Error("EnableSecureKubelet expected to be false") | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,7 +112,7 @@ func (az *AzureClient) CreateRoleAssignmentSimple(ctx context.Context, resourceG | |
}, | ||
} | ||
|
||
re := regexp.MustCompile("(?i)status=(\\d+)") | ||
re := regexp.MustCompile(`(?i)status=(\d+)`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, that extra There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original regex is a normal, interpreted string literal, so it needed to escape the backslash. Using the backtics syntax makes it a raw string literal, so no escaping is needed. Raw string literals are preferable for regexes for readability and copy-and-pasting. |
||
for { | ||
_, err := az.CreateRoleAssignment( | ||
ctx, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💥 💥 |
||
} | ||
|
||
// HasAllZonesAgentPools will return true if all of the agent pools have zones | ||
|
@@ -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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,7 +212,7 @@ func (d *Deployment) WaitForReplicas(n int, sleep, duration time.Duration) ([]po | |
select { | ||
case err := <-errCh: | ||
return pods, err | ||
case _ = <-readyCh: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wut There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you can elide the no-op assignment inside a |
||
case <-readyCh: | ||
return pods, nil | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'm getting it now that the surrounding quotes were escaping the slashes and then passing those into the regex compiler literally |
||
if err != nil { | ||
log.Printf("Error while trying to create regex for windows outbound check:%s\n", err) | ||
return false, err | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol