Skip to content

Commit d3a7607

Browse files
authored
Merge pull request #17573 from rifelpet/golangcilint-fixes
Golangci-lint v2 fixes
2 parents 3b3df48 + 2de74a7 commit d3a7607

File tree

76 files changed

+168
-210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+168
-210
lines changed

channels/pkg/cmd/apply_channel.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"os"
2525

2626
"github.com/blang/semver/v4"
27-
"github.com/cert-manager/cert-manager/pkg/client/clientset/versioned"
2827
certmanager "github.com/cert-manager/cert-manager/pkg/client/clientset/versioned"
2928
"github.com/spf13/cobra"
3029
"go.uber.org/multierr"
@@ -120,7 +119,7 @@ func RunApplyChannel(ctx context.Context, f *ChannelsFactory, out io.Writer, opt
120119
return applyMenu(ctx, menu, f.VFSContext(), k8sClient, cmClient, dynamicClient, restMapper, options.Yes)
121120
}
122121

123-
func applyMenu(ctx context.Context, menu *channels.AddonMenu, vfsContext *vfs.VFSContext, k8sClient kubernetes.Interface, cmClient versioned.Interface, dynamicClient dynamic.Interface, restMapper *restmapper.DeferredDiscoveryRESTMapper, apply bool) error {
122+
func applyMenu(ctx context.Context, menu *channels.AddonMenu, vfsContext *vfs.VFSContext, k8sClient kubernetes.Interface, cmClient certmanager.Interface, dynamicClient dynamic.Interface, restMapper *restmapper.DeferredDiscoveryRESTMapper, apply bool) error {
124123
// channelVersions is the list of installed addons in the cluster.
125124
// It is keyed by <namespace>:<addon name>.
126125
channelVersions, err := getChannelVersions(ctx, k8sClient)
@@ -198,7 +197,7 @@ func applyMenu(ctx context.Context, menu *channels.AddonMenu, vfsContext *vfs.VF
198197
return merr
199198
}
200199

201-
func getUpdates(ctx context.Context, menu *channels.AddonMenu, k8sClient kubernetes.Interface, cmClient versioned.Interface, channelVersions map[string]*channels.ChannelVersion) ([]*channels.AddonUpdate, []*channels.Addon, error) {
200+
func getUpdates(ctx context.Context, menu *channels.AddonMenu, k8sClient kubernetes.Interface, cmClient certmanager.Interface, channelVersions map[string]*channels.ChannelVersion) ([]*channels.AddonUpdate, []*channels.Addon, error) {
202201
var updates []*channels.AddonUpdate
203202
var needUpdates []*channels.Addon
204203
for _, addon := range menu.Addons {

cloudmock/openstack/mocknetworking/routers.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ func (m *MockClient) routerInterface(w http.ResponseWriter, r *http.Request) {
181181
if err != nil {
182182
panic("error decoding create router interface request")
183183
}
184-
if parts[2] == "add_router_interface" {
184+
switch parts[2] {
185+
case "add_router_interface":
185186
subnet := m.subnets[createInterface.SubnetID]
186187
interfaces := m.routerInterfaces[routerID]
187188
interfaces = append(interfaces, routers.InterfaceInfo{
@@ -201,15 +202,15 @@ func (m *MockClient) routerInterface(w http.ResponseWriter, r *http.Request) {
201202
},
202203
}
203204
m.ports[port.ID] = port
204-
} else if parts[2] == "remove_router_interface" {
205+
case "remove_router_interface":
205206
interfaces := make([]routers.InterfaceInfo, 0)
206207
for _, i := range m.routerInterfaces[routerID] {
207208
if i.SubnetID != createInterface.SubnetID {
208209
interfaces = append(interfaces, i)
209210
}
210211
}
211212
m.routerInterfaces[routerID] = interfaces
212-
} else {
213+
default:
213214
w.WriteHeader(http.StatusBadRequest)
214215
return
215216
}

cloudmock/scaleway/mockdns/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (f *FakeDomainAPI) UpdateDNSZoneRecords(req *domain.UpdateDNSZoneRecordsReq
107107
break
108108
}
109109
}
110-
if found == false {
110+
if !found {
111111
return nil, fmt.Errorf("could not find record %s to delete", *change.Delete.ID)
112112
}
113113

cmd/kops-controller/pkg/server/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func (s *Server) bootstrap(w http.ResponseWriter, r *http.Request) {
161161
if err != nil {
162162
klog.Infof("bootstrap %s read err: %v", r.RemoteAddr, err)
163163
w.WriteHeader(http.StatusBadRequest)
164-
_, _ = w.Write([]byte(fmt.Sprintf("bootstrap %s failed to read body: %v", r.RemoteAddr, err)))
164+
_, _ = fmt.Fprintf(w, "bootstrap %s failed to read body: %v", r.RemoteAddr, err)
165165
return
166166
}
167167

@@ -208,7 +208,7 @@ func (s *Server) bootstrap(w http.ResponseWriter, r *http.Request) {
208208
if err := json.Unmarshal(body, req); err != nil {
209209
klog.Infof("bootstrap %s decode err: %v", r.RemoteAddr, err)
210210
w.WriteHeader(http.StatusBadRequest)
211-
_, _ = w.Write([]byte(fmt.Sprintf("failed to decode: %v", err)))
211+
_, _ = fmt.Fprintf(w, "failed to decode: %v", err)
212212
return
213213
}
214214

@@ -264,7 +264,7 @@ func (s *Server) bootstrap(w http.ResponseWriter, r *http.Request) {
264264
if err != nil {
265265
klog.Infof("bootstrap %s cert %q issue err: %v", r.RemoteAddr, name, err)
266266
w.WriteHeader(http.StatusBadRequest)
267-
_, _ = w.Write([]byte(fmt.Sprintf("failed to issue %q: %v", name, err)))
267+
_, _ = fmt.Fprintf(w, "failed to issue %q: %v", name, err)
268268
return
269269
}
270270
resp.Certs[name] = cert

cmd/kops/create_cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ func parseCloudLabels(s string) (map[string]string, error) {
858858
// Replace commas with newlines to allow a single pass with csv.Reader.
859859
// We can't use csv.Reader for the initial split because it would see each key=value record as a single field
860860
// and significantly complicates using quoted fields as keys or values.
861-
records := strings.Replace(s, ",", "\n", -1)
861+
records := strings.ReplaceAll(s, ",", "\n")
862862

863863
// Let the CSV library do the heavy-lifting in handling nested ='s
864864
r := csv.NewReader(strings.NewReader(records))

cmd/kops/integration_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ func (i *integrationTest) runTestTerraformAWS(t *testing.T) {
16051605
"aws_cloudwatch_event_rule_" + awsup.GetClusterName40(i.clusterName) + "-SpotInterruption_event_pattern",
16061606
"aws_cloudwatch_event_rule_" + awsup.GetClusterName40(i.clusterName) + "-InstanceStateChange_event_pattern",
16071607
"aws_cloudwatch_event_rule_" + awsup.GetClusterName40(i.clusterName) + "-InstanceScheduledChange_event_pattern",
1608-
"aws_sqs_queue_" + strings.Replace(i.clusterName, ".", "-", -1) + "-nth_policy",
1608+
"aws_sqs_queue_" + strings.ReplaceAll(i.clusterName, ".", "-") + "-nth_policy",
16091609
}...)
16101610
}
16111611
if i.nthRebalance {
@@ -1633,7 +1633,8 @@ func (i *integrationTest) runTestPhase(t *testing.T, phase cloudup.Phase) {
16331633

16341634
expectedFilenames := i.expectTerraformFilenames
16351635

1636-
if phase == cloudup.PhaseSecurity {
1636+
switch phase {
1637+
case cloudup.PhaseSecurity:
16371638
expectedFilenames = []string{
16381639
"aws_iam_role_masters." + i.clusterName + "_policy",
16391640
"aws_iam_role_nodes." + i.clusterName + "_policy",
@@ -1648,7 +1649,7 @@ func (i *integrationTest) runTestPhase(t *testing.T, phase cloudup.Phase) {
16481649
"aws_launch_template_bastion." + i.clusterName + "_user_data",
16491650
}...)
16501651
}
1651-
} else if phase == cloudup.PhaseCluster {
1652+
case cloudup.PhaseCluster:
16521653
expectedFilenames = []string{
16531654
"aws_launch_template_nodes." + i.clusterName + "_user_data",
16541655
}

cmd/kops/lifecycle_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (o *LifecycleTestOptions) AddDefaults() {
5656
o.Version = "v1alpha2"
5757
}
5858
if o.ClusterName == "" {
59-
o.ClusterName = strings.Replace(o.SrcDir, "_", "", -1) + ".example.com"
59+
o.ClusterName = strings.ReplaceAll(o.SrcDir, "_", "") + ".example.com"
6060
}
6161

6262
o.SrcDir = "../../tests/integration/update_cluster/" + o.SrcDir

cmd/kops/toolbox_instance-selector.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,8 @@ func decorateWithMixedInstancesPolicy(instanceGroup *kops.InstanceGroup, usageCl
520520
ig := instanceGroup
521521
ig.Spec.MachineType = instanceSelections[0]
522522

523-
if usageClass == ec2types.UsageClassTypeSpot {
523+
switch usageClass {
524+
case ec2types.UsageClassTypeSpot:
524525
ondemandBase := int64(0)
525526
ondemandAboveBase := int64(0)
526527
spotAllocationStrategy := "capacity-optimized"
@@ -530,11 +531,11 @@ func decorateWithMixedInstancesPolicy(instanceGroup *kops.InstanceGroup, usageCl
530531
OnDemandAboveBase: &ondemandAboveBase,
531532
SpotAllocationStrategy: &spotAllocationStrategy,
532533
}
533-
} else if usageClass == ec2types.UsageClassTypeOnDemand {
534+
case ec2types.UsageClassTypeOnDemand:
534535
ig.Spec.MixedInstancesPolicy = &kops.MixedInstancesPolicySpec{
535536
Instances: instanceSelections,
536537
}
537-
} else {
538+
default:
538539
return nil, fmt.Errorf("error node usage class not supported")
539540
}
540541

cmd/kops/validate_cluster.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3737
"k8s.io/klog/v2"
3838
"k8s.io/kops/cmd/kops/util"
39-
"k8s.io/kops/pkg/apis/kops"
4039
kopsapi "k8s.io/kops/pkg/apis/kops"
4140
"k8s.io/kops/pkg/validation"
4241
"k8s.io/kops/util/pkg/tables"
@@ -63,15 +62,15 @@ var (
6362

6463
type ValidateClusterOptions struct {
6564
ClusterName string
66-
InstanceGroupRoles []kops.InstanceGroupRole
65+
InstanceGroupRoles []kopsapi.InstanceGroupRole
6766
output string
6867
wait time.Duration
6968
count int
7069
interval time.Duration
7170
kubeconfig string
7271

7372
// filterInstanceGroups is a function that returns true if the instance group should be validated
74-
filterInstanceGroups func(ig *kops.InstanceGroup) bool
73+
filterInstanceGroups func(ig *kopsapi.InstanceGroup) bool
7574

7675
// filterPodsForValidation is a function that returns true if the pod should be validated
7776
filterPodsForValidation func(pod *v1.Pod) bool

dns-controller/pkg/watchers/node.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,10 @@ func (c *NodeController) updateNodeRecords(node *v1.Node) string {
201201

202202
for _, a := range node.Status.Addresses {
203203
var roleType string
204-
if a.Type == v1.NodeInternalIP {
204+
switch a.Type {
205+
case v1.NodeInternalIP:
205206
roleType = dns.RoleTypeInternal
206-
} else if a.Type == v1.NodeExternalIP {
207+
case v1.NodeExternalIP:
207208
roleType = dns.RoleTypeExternal
208209
}
209210
var recordType dns.RecordType = dns.RecordTypeA

0 commit comments

Comments
 (0)