Skip to content

Commit 19ea379

Browse files
committed
add gosimple linter and clean up linter violations
1 parent e1e60e2 commit 19ea379

File tree

10 files changed

+22
-33
lines changed

10 files changed

+22
-33
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ linters:
1717
- goimports
1818
- golint
1919
- gosec
20+
- gosimple
2021
- govet
2122
- ineffassign
2223
- interfacer

api/v1alpha3/azurecluster_validation.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func validateSubnets(subnets Subnets, fldPath *field.Path) field.ErrorList {
151151
}
152152
}
153153
for k, v := range requiredSubnetRoles {
154-
if v == false {
154+
if !v {
155155
allErrs = append(allErrs, field.Required(fldPath,
156156
fmt.Sprintf("required role %s not included in provided subnets", k)))
157157
}
@@ -197,8 +197,7 @@ func validateInternalLBIPAddress(address string, cidrs []string, fldPath *field.
197197
// validateIngressRule validates an IngressRule
198198
func validateIngressRule(ingressRule *IngressRule, fldPath *field.Path) *field.Error {
199199
if ingressRule.Priority < 100 || ingressRule.Priority > 4096 {
200-
return field.Invalid(fldPath, ingressRule.Priority,
201-
fmt.Sprintf("ingress priorities should be between 100 and 4096"))
200+
return field.Invalid(fldPath, ingressRule.Priority, "ingress priorities should be between 100 and 4096")
202201
}
203202

204203
return nil
@@ -234,13 +233,13 @@ func validateAPIServerLB(lb LoadBalancerSpec, old LoadBalancerSpec, cidrs []stri
234233
// There should only be one IP config.
235234
if len(lb.FrontendIPs) != 1 {
236235
allErrs = append(allErrs, field.Invalid(fldPath.Child("frontendIPConfigs"), lb.FrontendIPs,
237-
fmt.Sprintf("API Server Load balancer should have 1 Frontend IP configuration")))
236+
"API Server Load balancer should have 1 Frontend IP configuration"))
238237
} else {
239238
// if Internal, IP config should not have a public IP.
240239
if lb.Type == Internal {
241240
if lb.FrontendIPs[0].PublicIP != nil {
242241
allErrs = append(allErrs, field.Forbidden(fldPath.Child("frontendIPConfigs").Index(0).Child("publicIP"),
243-
fmt.Sprintf("Internal Load Balancers cannot have a Public IP")))
242+
"Internal Load Balancers cannot have a Public IP"))
244243
}
245244
if lb.FrontendIPs[0].PrivateIPAddress != "" {
246245
if err := validateInternalLBIPAddress(lb.FrontendIPs[0].PrivateIPAddress, cidrs,
@@ -257,7 +256,7 @@ func validateAPIServerLB(lb LoadBalancerSpec, old LoadBalancerSpec, cidrs []stri
257256
if lb.Type == Public {
258257
if lb.FrontendIPs[0].PrivateIPAddress != "" {
259258
allErrs = append(allErrs, field.Forbidden(fldPath.Child("frontendIPConfigs").Index(0).Child("privateIP"),
260-
fmt.Sprintf("Public Load Balancers cannot have a Private IP")))
259+
"Public Load Balancers cannot have a Private IP"))
261260
}
262261
}
263262
}

api/v1alpha3/azuremachine_validation.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,8 @@ func ValidateManagedDisk(old, new ManagedDisk, fieldPath *field.Path) field.Erro
168168
func validateDiffDiskSetings(d *DiffDiskSettings, fldPath *field.Path) *field.Error {
169169
if d != nil {
170170
if d.Option != string(compute.Local) {
171-
return field.Invalid(
172-
fldPath.Child("option"),
173-
d,
174-
fmt.Sprintf("changing ephemeral os settings after machine creation is not allowed"),
175-
)
171+
msg := "changing ephemeral os settings after machine creation is not allowed"
172+
return field.Invalid(fldPath.Child("option"), d, msg)
176173
}
177174
}
178175
return nil
@@ -183,25 +180,18 @@ func validateDiffDiskSettingsUpdate(old, new *DiffDiskSettings, fieldPath *field
183180
fldPath := fieldPath.Child("diffDiskSettings")
184181

185182
if old == nil && new != nil {
186-
allErrs = append(allErrs, field.Invalid(fldPath, new, fmt.Sprintf("enabling ephemeral os after machine creation is not allowed")))
183+
allErrs = append(allErrs, field.Invalid(fldPath, new, "enabling ephemeral os after machine creation is not allowed"))
187184
return allErrs
188185
}
189186
if old != nil && new == nil {
190-
allErrs = append(allErrs, field.Invalid(fldPath, new, fmt.Sprintf("disabling ephemeral os after machine creation is not allowed")))
187+
allErrs = append(allErrs, field.Invalid(fldPath, new, "disabling ephemeral os after machine creation is not allowed"))
191188
return allErrs
192189
}
193190

194191
if old != nil && new != nil {
195192
if old.Option != new.Option {
196-
allErrs = append(
197-
allErrs,
198-
field.Invalid(
199-
fldPath.Child("option"),
200-
new,
201-
fmt.Sprintf("changing ephemeral os settings after machine creation is not allowed"),
202-
),
203-
)
204-
return allErrs
193+
msg := "changing ephemeral os settings after machine creation is not allowed"
194+
return append(allErrs, field.Invalid(fldPath.Child("option"), new, msg))
205195
}
206196
}
207197

cloud/scope/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ func (s *ClusterScope) APIServerHost() string {
472472
// SetFailureDomain will set the spec for a for a given key
473473
func (s *ClusterScope) SetFailureDomain(id string, spec clusterv1.FailureDomainSpec) {
474474
if s.AzureCluster.Status.FailureDomains == nil {
475-
s.AzureCluster.Status.FailureDomains = make(clusterv1.FailureDomains, 0)
475+
s.AzureCluster.Status.FailureDomains = make(clusterv1.FailureDomains)
476476
}
477477
s.AzureCluster.Status.FailureDomains[id] = spec
478478
}

cloud/scope/machine.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (m *MachineScope) TagsSpecs() []azure.TagsSpec {
122122
// PublicIPSpecs returns the public IP specs.
123123
func (m *MachineScope) PublicIPSpecs() []azure.PublicIPSpec {
124124
var spec []azure.PublicIPSpec
125-
if m.AzureMachine.Spec.AllocatePublicIP == true {
125+
if m.AzureMachine.Spec.AllocatePublicIP {
126126
spec = append(spec, azure.PublicIPSpec{
127127
Name: azure.GenerateNodePublicIPName(m.Name()),
128128
})
@@ -168,7 +168,7 @@ func (m *MachineScope) NICSpecs() []azure.NICSpec {
168168
}
169169
}
170170
specs := []azure.NICSpec{spec}
171-
if m.AzureMachine.Spec.AllocatePublicIP == true {
171+
if m.AzureMachine.Spec.AllocatePublicIP {
172172
specs = append(specs, azure.NICSpec{
173173
Name: azure.GeneratePublicNICName(m.Name()),
174174
MachineName: m.Name(),

cloud/services/scalesets/scalesets_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ func TestReconcileVMSS(t *testing.T) {
513513
err := s.Reconcile(context.TODO())
514514
if tc.expectedError != "" {
515515
g.Expect(err).To(HaveOccurred())
516-
g.Expect(err).To(MatchError(tc.expectedError), fmt.Sprintf("%s", err.Error()))
516+
g.Expect(err).To(MatchError(tc.expectedError), err.Error())
517517
} else {
518518
g.Expect(err).NotTo(HaveOccurred())
519519
}

cloud/services/tags/tags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
6868
if err != nil {
6969
return errors.Wrapf(err, "failed to get existing tags")
7070
}
71-
tags := make(map[string]*string, 0)
71+
tags := make(map[string]*string)
7272
if result.Properties != nil && result.Properties.Tags != nil {
7373
tags = result.Properties.Tags
7474
}

cloud/services/virtualmachines/virtualmachines.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,11 @@ func (s *Service) generateImagePlan() *compute.Plan {
251251
if err != nil {
252252
return nil
253253
}
254-
if image.Marketplace == nil || image.Marketplace.ThirdPartyImage == false {
254+
255+
if image.Marketplace == nil || !image.Marketplace.ThirdPartyImage {
255256
return nil
256257
}
258+
257259
if image.Marketplace.Publisher == "" || image.Marketplace.SKU == "" || image.Marketplace.Offer == "" {
258260
return nil
259261
}

controllers/azurejson_machine_controller.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ type filterUnclonedMachinesPredicate struct {
6868
}
6969

7070
func (f filterUnclonedMachinesPredicate) Create(e event.CreateEvent) bool {
71-
return f.Generic(event.GenericEvent{
72-
Meta: e.Meta,
73-
Object: e.Object,
74-
})
71+
return f.Generic(event.GenericEvent(e))
7572
}
7673

7774
func (f filterUnclonedMachinesPredicate) Update(e event.UpdateEvent) bool {

internal/test/env/env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var (
5353
logger = record.NewLogger(record.WithThreshold(to.IntPtr(1)), record.WithWriter(ginkgo.GinkgoWriter))
5454
scheme = runtime.NewScheme()
5555
env *envtest.Environment
56-
clusterAPIVersionRegex = regexp.MustCompile("^(\\W)sigs.k8s.io/cluster-api v(.+)")
56+
clusterAPIVersionRegex = regexp.MustCompile(`^(\W)sigs.k8s.io/cluster-api v(.+)`)
5757
)
5858

5959
func init() {

0 commit comments

Comments
 (0)