Skip to content

Commit

Permalink
Merge pull request #4289 from aledbf/static-check
Browse files Browse the repository at this point in the history
Apply fixes suggested by staticcheck
  • Loading branch information
k8s-ci-robot authored Jul 8, 2019
2 parents 82c22e3 + 3d7a093 commit 771fc9f
Show file tree
Hide file tree
Showing 19 changed files with 26 additions and 315 deletions.
4 changes: 2 additions & 2 deletions cmd/dbg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func backendsAll() {
return
}

fmt.Println(string(prettyBuffer.Bytes()))
fmt.Println(prettyBuffer.String())
}

func backendsList() {
Expand Down Expand Up @@ -228,7 +228,7 @@ func general() {
return
}

fmt.Println(string(prettyBuffer.Bytes()))
fmt.Println(prettyBuffer.String())
}

func readNginxConf() {
Expand Down
10 changes: 5 additions & 5 deletions cmd/nginx/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,27 +202,27 @@ Takes the form "<host>:port". If not provided, no admission controller is starte

// check port collisions
if !ing_net.IsPortAvailable(*httpPort) {
return false, nil, fmt.Errorf("Port %v is already in use. Please check the flag --http-port", *httpPort)
return false, nil, fmt.Errorf("port %v is already in use. Please check the flag --http-port", *httpPort)
}

if !ing_net.IsPortAvailable(*httpsPort) {
return false, nil, fmt.Errorf("Port %v is already in use. Please check the flag --https-port", *httpsPort)
return false, nil, fmt.Errorf("port %v is already in use. Please check the flag --https-port", *httpsPort)
}

if !ing_net.IsPortAvailable(*defServerPort) {
return false, nil, fmt.Errorf("Port %v is already in use. Please check the flag --default-server-port", *defServerPort)
return false, nil, fmt.Errorf("port %v is already in use. Please check the flag --default-server-port", *defServerPort)
}

if *enableSSLPassthrough && !ing_net.IsPortAvailable(*sslProxyPort) {
return false, nil, fmt.Errorf("Port %v is already in use. Please check the flag --ssl-passthrough-proxy-port", *sslProxyPort)
return false, nil, fmt.Errorf("port %v is already in use. Please check the flag --ssl-passthrough-proxy-port", *sslProxyPort)
}

if !*enableSSLChainCompletion {
klog.Warningf("SSL certificate chain completion is disabled (--enable-ssl-chain-completion=false)")
}

if *publishSvc != "" && *publishStatusAddress != "" {
return false, nil, fmt.Errorf("Flags --publish-service and --publish-status-address are mutually exclusive")
return false, nil, fmt.Errorf("flags --publish-service and --publish-status-address are mutually exclusive")
}

nginx.HealthPath = *defHealthzURL
Expand Down
2 changes: 0 additions & 2 deletions cmd/nginx/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ func TestHandleSigterm(t *testing.T) {
if code != 1 {
t.Errorf("Expected exit code 1 but %d received", code)
}

return
})

time.Sleep(1 * time.Second)
Expand Down
2 changes: 1 addition & 1 deletion cmd/plugin/commands/backends/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ func backends(flags *genericclioptions.ConfigFlags, podName string, deployment s
return err
}

fmt.Printf(out)
fmt.Print(out)
return nil
}
6 changes: 1 addition & 5 deletions cmd/plugin/lints/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,7 @@ func removedAnnotation(annotationName string, issueNumber int, version string) I
func satisfyDirective(ing networking.Ingress) bool {
for name, val := range ing.Annotations {
if strings.HasSuffix(name, "/configuration-snippet") {
if strings.Index(val, "satisfy") != -1 {
return true
}

return false
return strings.Contains(val, "satisfy")
}
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/plugin/request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func GetNamedPod(flags *genericclioptions.ConfigFlags, name string) (apiv1.Pod,
}
}

return apiv1.Pod{}, fmt.Errorf("Pod %v not found in namespace %v", name, util.GetNamespace(flags))
return apiv1.Pod{}, fmt.Errorf("pod %v not found in namespace %v", name, util.GetNamespace(flags))
}

// GetDeploymentPod finds a pod from a given deployment
Expand All @@ -64,7 +64,7 @@ func GetDeploymentPod(flags *genericclioptions.ConfigFlags, deployment string) (
}

if len(ings) == 0 {
return apiv1.Pod{}, fmt.Errorf("No pods for deployment %v found in namespace %v", deployment, util.GetNamespace(flags))
return apiv1.Pod{}, fmt.Errorf("no pods for deployment %v found in namespace %v", deployment, util.GetNamespace(flags))
}

return ings[0], nil
Expand Down Expand Up @@ -222,7 +222,7 @@ func GetServiceByName(flags *genericclioptions.ConfigFlags, name string, service
}
}

return apiv1.Service{}, fmt.Errorf("Could not find service %v in namespace %v", name, util.GetNamespace(flags))
return apiv1.Service{}, fmt.Errorf("could not find service %v in namespace %v", name, util.GetNamespace(flags))
}

func getPods(flags *genericclioptions.ConfigFlags) ([]apiv1.Pod, error) {
Expand Down
17 changes: 1 addition & 16 deletions cmd/plugin/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,12 @@ func PrintError(e error) {
}
}

func printWithError(s string, e error) {
if e != nil {
fmt.Println(e)
}
fmt.Print(s)
}

func printOrError(s string, e error) error {
if e != nil {
return e
}
fmt.Print(s)
return nil
}

// ParseVersionString returns the major, minor, and patch numbers of a version string
func ParseVersionString(v string) (int, int, int, error) {
parts := versionRegex.FindStringSubmatch(v)

if len(parts) != 4 {
return 0, 0, 0, fmt.Errorf("Could not parse %v as a version string (like 0.20.3)", v)
return 0, 0, 0, fmt.Errorf("could not parse %v as a version string (like 0.20.3)", v)
}

major, _ := strconv.Atoi(parts[1])
Expand Down
7 changes: 1 addition & 6 deletions internal/ingress/annotations/ipwhitelist/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ func (sr1 *SourceRange) Equal(sr2 *SourceRange) bool {
return false
}

match := sets.StringElementsMatch(sr1.CIDR, sr2.CIDR)
if !match {
return false
}

return true
return sets.StringElementsMatch(sr1.CIDR, sr2.CIDR)
}

type ipwhitelist struct {
Expand Down
7 changes: 1 addition & 6 deletions internal/ingress/annotations/ratelimit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,7 @@ func (rt1 *Config) Equal(rt2 *Config) bool {
return false
}

match := sets.StringElementsMatch(rt1.Whitelist, rt2.Whitelist)
if !match {
return false
}

return true
return sets.StringElementsMatch(rt1.Whitelist, rt2.Whitelist)
}

// Zone returns information about the NGINX rate limit (limit_req_zone)
Expand Down
2 changes: 0 additions & 2 deletions internal/ingress/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ import (
"k8s.io/ingress-nginx/internal/net/ssl"
)

const fakeCertificateName = "default-fake-certificate"

type fakeIngressStore struct {
ingresses []*ingress.Ingress
}
Expand Down
5 changes: 2 additions & 3 deletions internal/ingress/controller/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"errors"
"fmt"
"io/ioutil"
"math"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -547,7 +546,7 @@ func (n NGINXController) generateTemplate(cfg ngx_config.Configuration, ingressC
}

if cfg.MaxWorkerConnections == 0 {
maxWorkerConnections := int(math.Ceil(float64(cfg.MaxWorkerOpenFiles * 3.0 / 4)))
maxWorkerConnections := int(float64(cfg.MaxWorkerOpenFiles * 3.0 / 4))
klog.V(3).Infof("Adjusting MaxWorkerConnections variable to %d", maxWorkerConnections)
cfg.MaxWorkerConnections = maxWorkerConnections
}
Expand Down Expand Up @@ -1090,7 +1089,7 @@ func createOpentracingCfg(cfg ngx_config.Configuration) error {
}

// Expand possible environment variables before writing the configuration to file.
expanded := os.ExpandEnv(string(tmplBuf.Bytes()))
expanded := os.ExpandEnv(tmplBuf.String())

return ioutil.WriteFile("/etc/nginx/opentracing.json", []byte(expanded), file.ReadWriteByUser)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ingress/controller/store/backend_ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (s *k8sStore) getPemCertificate(secretName string) (*ingress.SSLCert, error
}
klog.V(3).Info(msg)

} else if ca != nil && len(ca) > 0 {
} else if len(ca) > 0 {
sslCert, err = ssl.CreateCACert(ca)
if err != nil {
return nil, fmt.Errorf("unexpected error creating SSL Cert: %v", err)
Expand Down
Loading

0 comments on commit 771fc9f

Please sign in to comment.