Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix staticcheck failures for test/images #81895

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions hack/.staticcheck_failures
Expand Up @@ -65,14 +65,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
Expand Down
15 changes: 0 additions & 15 deletions test/images/agnhost/dns/common.go
Expand Up @@ -17,10 +17,8 @@ limitations under the License.
package dns

import (
"bytes"
"fmt"
"io/ioutil"
"os/exec"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -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())
}
15 changes: 15 additions & 0 deletions test/images/agnhost/dns/dns_windows.go
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package dns

import (
"bytes"
"os/exec"
"strings"
)

Expand All @@ -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())
}
1 change: 1 addition & 0 deletions test/images/agnhost/inclusterclient/main.go
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/images/agnhost/net/nat/closewait.go
Expand Up @@ -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
praseodym marked this conversation as resolved.
Show resolved Hide resolved

// CloseWaitServerOptions holds server JSON options.
Expand Down
22 changes: 13 additions & 9 deletions test/images/agnhost/netexec/netexec.go
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
praseodym marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down
4 changes: 0 additions & 4 deletions test/images/agnhost/pause/pause.go
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/images/agnhost/serve-hostname/serve_hostname.go
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions test/images/agnhost/webhook/patch_test.go
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions test/images/pets/peer-finder/peer-finder.go
Expand Up @@ -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
Expand Down