Skip to content

Commit b3060bf

Browse files
authored
Fix golangci-lint errors (#10196)
* Fix golangci-lint errors Signed-off-by: z1cheng <[email protected]> * Fix dupl errors Signed-off-by: z1cheng <[email protected]> * Fix comments Signed-off-by: z1cheng <[email protected]> * Fix errcheck lint errors Signed-off-by: z1cheng <[email protected]> * Fix assert in e2e test Signed-off-by: z1cheng <[email protected]> * Not interrupt the waitForPodsReady Signed-off-by: z1cheng <[email protected]> * Replace string with constant Signed-off-by: z1cheng <[email protected]> * Fix comments Signed-off-by: z1cheng <[email protected]> * Revert write file permision Signed-off-by: z1cheng <[email protected]> --------- Signed-off-by: z1cheng <[email protected]>
1 parent 46d87d3 commit b3060bf

File tree

253 files changed

+2435
-2114
lines changed

Some content is hidden

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

253 files changed

+2435
-2114
lines changed

cmd/dataplane/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ package main
1818

1919
import (
2020
"fmt"
21-
"github.com/prometheus/client_golang/prometheus"
22-
"github.com/prometheus/client_golang/prometheus/collectors"
2321
"net/http"
2422
"os"
2523

24+
"github.com/prometheus/client_golang/prometheus"
25+
"github.com/prometheus/client_golang/prometheus/collectors"
26+
2627
"k8s.io/klog/v2"
2728

2829
"k8s.io/ingress-nginx/internal/ingress/controller"

cmd/dbg/main.go

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ func main() {
114114
fmt.Println(err)
115115
os.Exit(1)
116116
}
117-
118117
}
119118

120119
func backendsAll() {
@@ -155,10 +154,16 @@ func backendsList() {
155154
fmt.Println(unmarshalErr)
156155
return
157156
}
158-
backends := f.([]interface{})
157+
backends, ok := f.([]interface{})
158+
if !ok {
159+
fmt.Printf("unexpected type: %T", f)
160+
}
159161

160162
for _, backendi := range backends {
161-
backend := backendi.(map[string]interface{})
163+
backend, ok := backendi.(map[string]interface{})
164+
if !ok {
165+
fmt.Printf("unexpected type: %T", backendi)
166+
}
162167
fmt.Println(backend["name"].(string))
163168
}
164169
}
@@ -180,12 +185,22 @@ func backendsGet(name string) {
180185
fmt.Println(unmarshalErr)
181186
return
182187
}
183-
backends := f.([]interface{})
188+
backends, ok := f.([]interface{})
189+
if !ok {
190+
fmt.Printf("unexpected type: %T", f)
191+
}
184192

185193
for _, backendi := range backends {
186-
backend := backendi.(map[string]interface{})
194+
backend, ok := backendi.(map[string]interface{})
195+
if !ok {
196+
fmt.Printf("unexpected type: %T", backendi)
197+
}
187198
if backend["name"].(string) == name {
188-
printed, _ := json.MarshalIndent(backend, "", " ")
199+
printed, err := json.MarshalIndent(backend, "", " ")
200+
if err != nil {
201+
fmt.Println(err)
202+
return
203+
}
189204
fmt.Println(string(printed))
190205
return
191206
}
@@ -213,18 +228,7 @@ func certGet(host string) {
213228
}
214229

215230
func general() {
216-
//TODO: refactor to obtain ingress-nginx pod count from the api server
217-
/*
218-
statusCode, body, requestErr := nginx.NewGetStatusRequest(generalPath)
219-
if requestErr != nil {
220-
fmt.Println(requestErr)
221-
return
222-
}
223-
if statusCode != 200 {
224-
fmt.Printf("Nginx returned code %v\n", statusCode)
225-
return
226-
}
227-
*/
231+
// TODO: refactor to obtain ingress-nginx pod count from the api server
228232

229233
var prettyBuffer bytes.Buffer
230234
indentErr := json.Indent(&prettyBuffer, []byte("{}"), "", " ")

cmd/nginx/logger.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,4 @@ func logger(address string) {
4747

4848
server.Wait()
4949
klog.Infof("Stopping logger")
50-
5150
}

cmd/nginx/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ func main() {
153153
if errExists == nil {
154154
conf.IsChroot = true
155155
go logger(conf.InternalLoggerAddress)
156-
157156
}
158157

159158
go metrics.StartHTTPServer(conf.HealthCheckHost, conf.ListenPorts.Health, mux)
@@ -282,10 +281,10 @@ func checkService(key string, kubeClient *kubernetes.Clientset) error {
282281
}
283282

284283
if errors.IsNotFound(err) {
285-
return fmt.Errorf("No service with name %v found in namespace %v: %v", name, ns, err)
284+
return fmt.Errorf("no service with name %v found in namespace %v: %v", name, ns, err)
286285
}
287286

288-
return fmt.Errorf("Unexpected error searching service with name %v in namespace %v: %v", name, ns, err)
287+
return fmt.Errorf("unexpected error searching service with name %v in namespace %v: %v", name, ns, err)
289288
}
290289

291290
return nil

cmd/nginx/main_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestCreateApiserverClient(t *testing.T) {
4747
func init() {
4848
// the default value of nginx.TemplatePath assumes the template exists in
4949
// the root filesystem and not in the rootfs directory
50-
path, err := filepath.Abs(filepath.Join("../../rootfs/", nginx.TemplatePath))
50+
path, err := filepath.Abs(filepath.Join("..", "..", "rootfs", nginx.TemplatePath))
5151
if err == nil {
5252
nginx.TemplatePath = path
5353
}
@@ -87,14 +87,14 @@ func TestHandleSigterm(t *testing.T) {
8787

8888
ingressflags.ResetForTesting(func() { t.Fatal("bad parse") })
8989

90-
os.Setenv("POD_NAME", podName)
91-
os.Setenv("POD_NAMESPACE", namespace)
90+
t.Setenv("POD_NAME", podName)
91+
t.Setenv("POD_NAMESPACE", namespace)
9292

9393
oldArgs := os.Args
9494

9595
defer func() {
96-
os.Setenv("POD_NAME", "")
97-
os.Setenv("POD_NAMESPACE", "")
96+
t.Setenv("POD_NAME", "")
97+
t.Setenv("POD_NAMESPACE", "")
9898
os.Args = oldArgs
9999
}()
100100

cmd/plugin/commands/backends/backends.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ func CreateCommand(flags *genericclioptions.ConfigFlags) *cobra.Command {
6363
return cmd
6464
}
6565

66-
func backends(flags *genericclioptions.ConfigFlags, podName string, deployment string, selector string, container string, backend string, onlyList bool) error {
66+
func backends(flags *genericclioptions.ConfigFlags, podName, deployment, selector, container, backend string, onlyList bool) error {
6767
var command []string
68-
if onlyList {
68+
switch {
69+
case onlyList:
6970
command = []string{"/dbg", "backends", "list"}
70-
} else if backend != "" {
71+
case backend != "":
7172
command = []string{"/dbg", "backends", "get", backend}
72-
} else {
73+
default:
7374
command = []string{"/dbg", "backends", "all"}
7475
}
7576

cmd/plugin/commands/certs/certs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func CreateCommand(flags *genericclioptions.ConfigFlags) *cobra.Command {
5959
return cmd
6060
}
6161

62-
func certs(flags *genericclioptions.ConfigFlags, podName string, deployment string, selector string, container string, host string) error {
62+
func certs(flags *genericclioptions.ConfigFlags, podName, deployment, selector, container, host string) error {
6363
command := []string{"/dbg", "certs", "get", host}
6464

6565
pod, err := request.ChoosePod(flags, podName, deployment, selector)

cmd/plugin/commands/conf/conf.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func CreateCommand(flags *genericclioptions.ConfigFlags) *cobra.Command {
5555
return cmd
5656
}
5757

58-
func conf(flags *genericclioptions.ConfigFlags, host string, podName string, deployment string, selector string, container string) error {
58+
func conf(flags *genericclioptions.ConfigFlags, host, podName, deployment, selector, container string) error {
5959
pod, err := request.ChoosePod(flags, podName, deployment, selector)
6060
if err != nil {
6161
return err

cmd/plugin/commands/exec/exec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type execFlags struct {
5555
Stdin bool
5656
}
5757

58-
func exec(flags *genericclioptions.ConfigFlags, podName string, deployment string, selector string, container string, cmd []string, opts execFlags) error {
58+
func exec(flags *genericclioptions.ConfigFlags, podName, deployment, selector, container string, cmd []string, opts execFlags) error {
5959
pod, err := request.ChoosePod(flags, podName, deployment, selector)
6060
if err != nil {
6161
return err

cmd/plugin/commands/general/general.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func CreateCommand(flags *genericclioptions.ConfigFlags) *cobra.Command {
4747
return cmd
4848
}
4949

50-
func general(flags *genericclioptions.ConfigFlags, podName string, deployment string, selector string, container string) error {
50+
func general(flags *genericclioptions.ConfigFlags, podName, deployment, selector, container string) error {
5151
pod, err := request.ChoosePod(flags, podName, deployment, selector)
5252
if err != nil {
5353
return err

0 commit comments

Comments
 (0)