Skip to content

Commit a634e25

Browse files
committed
Fix staticcheck failures for test/images
Errors from staticcheck: test/images/agnhost/dns/common.go:79:6: func runCommand is unused (U1000) test/images/agnhost/inclusterclient/main.go:75:16: using time.Tick leaks the underlying ticker, consider using it only in endless functions, tests and the main package, and use time.NewTicker here (SA1015) test/images/agnhost/net/nat/closewait.go:41:5: var leakedConnection is unused (U1000) test/images/agnhost/netexec/netexec.go:157:17: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006) test/images/agnhost/netexec/netexec.go:250:18: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006) test/images/agnhost/netexec/netexec.go:317:18: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006) test/images/agnhost/netexec/netexec.go:331:19: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006) test/images/agnhost/netexec/netexec.go:345:19: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006) test/images/agnhost/netexec/netexec.go:357:19: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006) test/images/agnhost/netexec/netexec.go:370:19: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006) test/images/agnhost/netexec/netexec.go:380:9: this value of err is never used (SA4006) test/images/agnhost/netexec/netexec.go:381:17: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006) test/images/agnhost/netexec/netexec.go:386:17: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006) test/images/agnhost/pause/pause.go:43:23: syscall.SIGKILL cannot be trapped (did you mean syscall.SIGTERM?) (SA1016) test/images/agnhost/serve-hostname/serve_hostname.go:125:15: the channel used with signal.Notify should be buffered (SA1017) test/images/agnhost/webhook/patch_test.go:131:13: this value of err is never used (SA4006) test/images/pets/peer-finder/peer-finder.go:155:6: this value of newPeers is never used (SA4006)
1 parent 32883e4 commit a634e25

File tree

10 files changed

+36
-39
lines changed

10 files changed

+36
-39
lines changed

hack/.staticcheck_failures

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,6 @@ test/e2e/apps
6565
test/e2e/autoscaling
6666
test/e2e/instrumentation/logging/stackdriver
6767
test/e2e/instrumentation/monitoring
68-
test/images/agnhost/dns
69-
test/images/agnhost/inclusterclient
70-
test/images/agnhost/net/nat
71-
test/images/agnhost/netexec
72-
test/images/agnhost/pause
73-
test/images/agnhost/serve-hostname
74-
test/images/agnhost/webhook
75-
test/images/pets/peer-finder
7668
test/integration/auth
7769
test/integration/client
7870
test/integration/deployment

test/images/agnhost/dns/common.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ limitations under the License.
1717
package dns
1818

1919
import (
20-
"bytes"
2120
"fmt"
2221
"io/ioutil"
23-
"os/exec"
2422
"strings"
2523

2624
"github.com/spf13/cobra"
@@ -75,16 +73,3 @@ func readFile(fileName string) string {
7573

7674
return string(fileData)
7775
}
78-
79-
func runCommand(name string, arg ...string) string {
80-
var out bytes.Buffer
81-
cmd := exec.Command(name, arg...)
82-
cmd.Stdout = &out
83-
84-
err := cmd.Run()
85-
if err != nil {
86-
panic(err)
87-
}
88-
89-
return strings.TrimSpace(out.String())
90-
}

test/images/agnhost/dns/dns_windows.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package dns
1818

1919
import (
20+
"bytes"
21+
"os/exec"
2022
"strings"
2123
)
2224

@@ -39,3 +41,16 @@ func getDNSServerList() []string {
3941

4042
panic("Could not find DNS Server list!")
4143
}
44+
45+
func runCommand(name string, arg ...string) string {
46+
var out bytes.Buffer
47+
cmd := exec.Command(name, arg...)
48+
cmd.Stdout = &out
49+
50+
err := cmd.Run()
51+
if err != nil {
52+
panic(err)
53+
}
54+
55+
return strings.TrimSpace(out.String())
56+
}

test/images/agnhost/inclusterclient/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func main(cmd *cobra.Command, args []string) {
7272

7373
c := kubernetes.NewForConfigOrDie(cfg).RESTClient()
7474

75+
//lint:ignore SA1015 noisy positive, `time.Tick` is used in a main function which is fine
7576
t := time.Tick(time.Duration(pollInterval) * time.Second)
7677
for {
7778
<-t

test/images/agnhost/net/nat/closewait.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838

3939
// leakedConnection is a global variable that should leak the active
4040
// connection assigned here.
41+
//lint:ignore U1000 intentional unused variable
4142
var leakedConnection *net.TCPConn
4243

4344
// CloseWaitServerOptions holds server JSON options.

test/images/agnhost/netexec/netexec.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func exitHandler(w http.ResponseWriter, r *http.Request) {
154154

155155
func hostnameHandler(w http.ResponseWriter, r *http.Request) {
156156
log.Printf("GET /hostname")
157-
fmt.Fprintf(w, getHostName())
157+
fmt.Fprint(w, getHostName())
158158
}
159159

160160
// healthHandler response with a 200 if the UDP server is ready. It also serves
@@ -247,7 +247,7 @@ func dialHandler(w http.ResponseWriter, r *http.Request) {
247247
}
248248
bytes, err := json.Marshal(output)
249249
if err == nil {
250-
fmt.Fprintf(w, string(bytes))
250+
fmt.Fprint(w, string(bytes))
251251
} else {
252252
http.Error(w, fmt.Sprintf("response could not be serialized. %v", err), http.StatusExpectationFailed)
253253
}
@@ -314,7 +314,7 @@ func shellHandler(w http.ResponseWriter, r *http.Request) {
314314
log.Printf("Output: %s", output)
315315
bytes, err := json.Marshal(output)
316316
if err == nil {
317-
fmt.Fprintf(w, string(bytes))
317+
fmt.Fprint(w, string(bytes))
318318
} else {
319319
http.Error(w, fmt.Sprintf("response could not be serialized. %v", err), http.StatusExpectationFailed)
320320
}
@@ -328,7 +328,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
328328
result["error"] = "Unable to upload file."
329329
bytes, err := json.Marshal(result)
330330
if err == nil {
331-
fmt.Fprintf(w, string(bytes))
331+
fmt.Fprint(w, string(bytes))
332332
} else {
333333
http.Error(w, fmt.Sprintf("%s. Also unable to serialize output. %v", result["error"], err), http.StatusInternalServerError)
334334
}
@@ -342,7 +342,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
342342
result["error"] = "Unable to open file for write"
343343
bytes, err := json.Marshal(result)
344344
if err == nil {
345-
fmt.Fprintf(w, string(bytes))
345+
fmt.Fprint(w, string(bytes))
346346
} else {
347347
http.Error(w, fmt.Sprintf("%s. Also unable to serialize output. %v", result["error"], err), http.StatusInternalServerError)
348348
}
@@ -354,7 +354,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
354354
result["error"] = "Unable to write file."
355355
bytes, err := json.Marshal(result)
356356
if err == nil {
357-
fmt.Fprintf(w, string(bytes))
357+
fmt.Fprint(w, string(bytes))
358358
} else {
359359
http.Error(w, fmt.Sprintf("%s. Also unable to serialize output. %v", result["error"], err), http.StatusInternalServerError)
360360
}
@@ -367,7 +367,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
367367
result["error"] = "Unable to chmod file."
368368
bytes, err := json.Marshal(result)
369369
if err == nil {
370-
fmt.Fprintf(w, string(bytes))
370+
fmt.Fprint(w, string(bytes))
371371
} else {
372372
http.Error(w, fmt.Sprintf("%s. Also unable to serialize output. %v", result["error"], err), http.StatusInternalServerError)
373373
}
@@ -378,12 +378,16 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
378378
result["output"] = UploadFile
379379
w.WriteHeader(http.StatusCreated)
380380
bytes, err := json.Marshal(result)
381-
fmt.Fprintf(w, string(bytes))
381+
if err != nil {
382+
http.Error(w, fmt.Sprintf("%s. Also unable to serialize output. %v", result["error"], err), http.StatusInternalServerError)
383+
return
384+
}
385+
fmt.Fprint(w, string(bytes))
382386
}
383387

384388
func hostNameHandler(w http.ResponseWriter, r *http.Request) {
385389
log.Printf("GET /hostName")
386-
fmt.Fprintf(w, getHostName())
390+
fmt.Fprint(w, getHostName())
387391
}
388392

389393
// udp server supports the hostName, echo and clientIP commands.

test/images/agnhost/pause/pause.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func pause(cmd *cobra.Command, args []string) {
4040
done := make(chan int, 1)
4141
signal.Notify(sigCh, syscall.SIGINT)
4242
signal.Notify(sigCh, syscall.SIGTERM)
43-
signal.Notify(sigCh, syscall.SIGKILL)
4443
go func() {
4544
sig := <-sigCh
4645
switch sig {
@@ -50,9 +49,6 @@ func pause(cmd *cobra.Command, args []string) {
5049
case syscall.SIGTERM:
5150
done <- 2
5251
os.Exit(2)
53-
case syscall.SIGKILL:
54-
done <- 0
55-
os.Exit(0)
5652
}
5753
}()
5854
result := <-done

test/images/agnhost/serve-hostname/serve_hostname.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func main(cmd *cobra.Command, args []string) {
121121
}()
122122
}
123123
log.Printf("Serving on port %d.\n", port)
124-
signals := make(chan os.Signal)
124+
signals := make(chan os.Signal, 1)
125125
signal.Notify(signals, syscall.SIGTERM)
126126
sig := <-signals
127127
log.Printf("Shutting down after receiving signal: %s.\n", sig)

test/images/agnhost/webhook/patch_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ func TestJSONPatchForUnstructured(t *testing.T) {
129129
t.Fatal(err)
130130
}
131131
patchedJS, err := patchObj.Apply(crJS)
132+
if err != nil {
133+
t.Fatal(err)
134+
}
132135
patchedObj := unstructured.Unstructured{}
133136
err = json.Unmarshal(patchedJS, &patchedObj)
134137
if err != nil {

test/images/pets/peer-finder/peer-finder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ func main() {
152152
script = *onChange
153153
log.Printf("No on-start supplied, on-change %v will be applied on start.", script)
154154
}
155-
for newPeers, peers := sets.NewString(), sets.NewString(); script != ""; time.Sleep(pollPeriod) {
156-
newPeers, err = lookup(*svc)
155+
for peers := sets.NewString(); script != ""; time.Sleep(pollPeriod) {
156+
newPeers, err := lookup(*svc)
157157
if err != nil {
158158
log.Printf("%v", err)
159159
continue

0 commit comments

Comments
 (0)