diff --git a/hack/.staticcheck_failures b/hack/.staticcheck_failures index 70d1a0d504f7..2ee8a4a6745b 100644 --- a/hack/.staticcheck_failures +++ b/hack/.staticcheck_failures @@ -58,14 +58,6 @@ test/e2e/apps test/e2e/autoscaling test/e2e/instrumentation/logging/stackdriver test/e2e/instrumentation/monitoring -test/images/agnhost/dns -test/images/agnhost/inclusterclient -test/images/agnhost/net/nat -test/images/agnhost/netexec -test/images/agnhost/pause -test/images/agnhost/serve-hostname -test/images/agnhost/webhook -test/images/pets/peer-finder test/integration/auth test/integration/client test/integration/deployment diff --git a/test/images/agnhost/dns/common.go b/test/images/agnhost/dns/common.go index 06166e9c2294..92452abec677 100644 --- a/test/images/agnhost/dns/common.go +++ b/test/images/agnhost/dns/common.go @@ -17,10 +17,8 @@ limitations under the License. package dns import ( - "bytes" "fmt" "io/ioutil" - "os/exec" "strings" "github.com/spf13/cobra" @@ -75,16 +73,3 @@ func readFile(fileName string) string { return string(fileData) } - -func runCommand(name string, arg ...string) string { - var out bytes.Buffer - cmd := exec.Command(name, arg...) - cmd.Stdout = &out - - err := cmd.Run() - if err != nil { - panic(err) - } - - return strings.TrimSpace(out.String()) -} diff --git a/test/images/agnhost/dns/dns_windows.go b/test/images/agnhost/dns/dns_windows.go index 68fbf51926c0..191958c65343 100644 --- a/test/images/agnhost/dns/dns_windows.go +++ b/test/images/agnhost/dns/dns_windows.go @@ -17,6 +17,8 @@ limitations under the License. package dns import ( + "bytes" + "os/exec" "strings" ) @@ -39,3 +41,16 @@ func getDNSServerList() []string { panic("Could not find DNS Server list!") } + +func runCommand(name string, arg ...string) string { + var out bytes.Buffer + cmd := exec.Command(name, arg...) + cmd.Stdout = &out + + err := cmd.Run() + if err != nil { + panic(err) + } + + return strings.TrimSpace(out.String()) +} diff --git a/test/images/agnhost/inclusterclient/main.go b/test/images/agnhost/inclusterclient/main.go index 705499d77e24..0f81425cbe07 100644 --- a/test/images/agnhost/inclusterclient/main.go +++ b/test/images/agnhost/inclusterclient/main.go @@ -72,6 +72,7 @@ func main(cmd *cobra.Command, args []string) { c := kubernetes.NewForConfigOrDie(cfg).RESTClient() + //lint:ignore SA1015 noisy positive, `time.Tick` is used in a main function which is fine t := time.Tick(time.Duration(pollInterval) * time.Second) for { <-t diff --git a/test/images/agnhost/net/nat/closewait.go b/test/images/agnhost/net/nat/closewait.go index 934afd7da0a8..6bd1c7c93d21 100644 --- a/test/images/agnhost/net/nat/closewait.go +++ b/test/images/agnhost/net/nat/closewait.go @@ -38,6 +38,7 @@ import ( // leakedConnection is a global variable that should leak the active // connection assigned here. +//lint:ignore U1000 intentional unused variable var leakedConnection *net.TCPConn // CloseWaitServerOptions holds server JSON options. diff --git a/test/images/agnhost/netexec/netexec.go b/test/images/agnhost/netexec/netexec.go index a3d2ad2af9ae..9b95715cec67 100644 --- a/test/images/agnhost/netexec/netexec.go +++ b/test/images/agnhost/netexec/netexec.go @@ -154,7 +154,7 @@ func exitHandler(w http.ResponseWriter, r *http.Request) { func hostnameHandler(w http.ResponseWriter, r *http.Request) { log.Printf("GET /hostname") - fmt.Fprintf(w, getHostName()) + fmt.Fprint(w, getHostName()) } // 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) { } bytes, err := json.Marshal(output) if err == nil { - fmt.Fprintf(w, string(bytes)) + fmt.Fprint(w, string(bytes)) } else { http.Error(w, fmt.Sprintf("response could not be serialized. %v", err), http.StatusExpectationFailed) } @@ -314,7 +314,7 @@ func shellHandler(w http.ResponseWriter, r *http.Request) { log.Printf("Output: %s", output) bytes, err := json.Marshal(output) if err == nil { - fmt.Fprintf(w, string(bytes)) + fmt.Fprint(w, string(bytes)) } else { http.Error(w, fmt.Sprintf("response could not be serialized. %v", err), http.StatusExpectationFailed) } @@ -328,7 +328,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) { result["error"] = "Unable to upload file." bytes, err := json.Marshal(result) if err == nil { - fmt.Fprintf(w, string(bytes)) + fmt.Fprint(w, string(bytes)) } else { http.Error(w, fmt.Sprintf("%s. Also unable to serialize output. %v", result["error"], err), http.StatusInternalServerError) } @@ -342,7 +342,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) { result["error"] = "Unable to open file for write" bytes, err := json.Marshal(result) if err == nil { - fmt.Fprintf(w, string(bytes)) + fmt.Fprint(w, string(bytes)) } else { http.Error(w, fmt.Sprintf("%s. Also unable to serialize output. %v", result["error"], err), http.StatusInternalServerError) } @@ -354,7 +354,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) { result["error"] = "Unable to write file." bytes, err := json.Marshal(result) if err == nil { - fmt.Fprintf(w, string(bytes)) + fmt.Fprint(w, string(bytes)) } else { http.Error(w, fmt.Sprintf("%s. Also unable to serialize output. %v", result["error"], err), http.StatusInternalServerError) } @@ -367,7 +367,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) { result["error"] = "Unable to chmod file." bytes, err := json.Marshal(result) if err == nil { - fmt.Fprintf(w, string(bytes)) + fmt.Fprint(w, string(bytes)) } else { http.Error(w, fmt.Sprintf("%s. Also unable to serialize output. %v", result["error"], err), http.StatusInternalServerError) } @@ -378,12 +378,16 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) { result["output"] = UploadFile w.WriteHeader(http.StatusCreated) bytes, err := json.Marshal(result) - fmt.Fprintf(w, string(bytes)) + if err != nil { + http.Error(w, fmt.Sprintf("%s. Also unable to serialize output. %v", result["error"], err), http.StatusInternalServerError) + return + } + fmt.Fprint(w, string(bytes)) } func hostNameHandler(w http.ResponseWriter, r *http.Request) { log.Printf("GET /hostName") - fmt.Fprintf(w, getHostName()) + fmt.Fprint(w, getHostName()) } // udp server supports the hostName, echo and clientIP commands. diff --git a/test/images/agnhost/pause/pause.go b/test/images/agnhost/pause/pause.go index 3fd01f2f79cf..4d69a9816c76 100644 --- a/test/images/agnhost/pause/pause.go +++ b/test/images/agnhost/pause/pause.go @@ -40,7 +40,6 @@ func pause(cmd *cobra.Command, args []string) { done := make(chan int, 1) signal.Notify(sigCh, syscall.SIGINT) signal.Notify(sigCh, syscall.SIGTERM) - signal.Notify(sigCh, syscall.SIGKILL) go func() { sig := <-sigCh switch sig { @@ -50,9 +49,6 @@ func pause(cmd *cobra.Command, args []string) { case syscall.SIGTERM: done <- 2 os.Exit(2) - case syscall.SIGKILL: - done <- 0 - os.Exit(0) } }() result := <-done diff --git a/test/images/agnhost/serve-hostname/serve_hostname.go b/test/images/agnhost/serve-hostname/serve_hostname.go index 1e0b9b449d9d..add1dcef1c02 100644 --- a/test/images/agnhost/serve-hostname/serve_hostname.go +++ b/test/images/agnhost/serve-hostname/serve_hostname.go @@ -121,7 +121,7 @@ func main(cmd *cobra.Command, args []string) { }() } log.Printf("Serving on port %d.\n", port) - signals := make(chan os.Signal) + signals := make(chan os.Signal, 1) signal.Notify(signals, syscall.SIGTERM) sig := <-signals log.Printf("Shutting down after receiving signal: %s.\n", sig) diff --git a/test/images/agnhost/webhook/patch_test.go b/test/images/agnhost/webhook/patch_test.go index d925afa7e241..252074373baf 100644 --- a/test/images/agnhost/webhook/patch_test.go +++ b/test/images/agnhost/webhook/patch_test.go @@ -129,6 +129,9 @@ func TestJSONPatchForUnstructured(t *testing.T) { t.Fatal(err) } patchedJS, err := patchObj.Apply(crJS) + if err != nil { + t.Fatal(err) + } patchedObj := unstructured.Unstructured{} err = json.Unmarshal(patchedJS, &patchedObj) if err != nil { diff --git a/test/images/pets/peer-finder/peer-finder.go b/test/images/pets/peer-finder/peer-finder.go index 6878fad4549a..6622a5c74213 100644 --- a/test/images/pets/peer-finder/peer-finder.go +++ b/test/images/pets/peer-finder/peer-finder.go @@ -152,8 +152,8 @@ func main() { script = *onChange log.Printf("No on-start supplied, on-change %v will be applied on start.", script) } - for newPeers, peers := sets.NewString(), sets.NewString(); script != ""; time.Sleep(pollPeriod) { - newPeers, err = lookup(*svc) + for peers := sets.NewString(); script != ""; time.Sleep(pollPeriod) { + newPeers, err := lookup(*svc) if err != nil { log.Printf("%v", err) continue