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 golang-ci linter errors #10128

Merged
merged 7 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions cmd/dataplane/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ package main

import (
"fmt"
"math/rand" // #nosec
"net/http"
"os"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"

Expand All @@ -41,8 +38,6 @@ import (
func main() {
klog.InitFlags(nil)

rand.Seed(time.Now().UnixNano())
z1cheng marked this conversation as resolved.
Show resolved Hide resolved

fmt.Println(version.String())
var err error
showVersion, conf, err := ingressflags.ParseFlags()
Expand Down
3 changes: 0 additions & 3 deletions cmd/nginx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"context"
"fmt"
"math/rand" // #nosec
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -54,8 +53,6 @@ import (
func main() {
klog.InitFlags(nil)

rand.Seed(time.Now().UnixNano())

fmt.Println(version.String())

showVersion, conf, err := ingressflags.ParseFlags()
Expand Down
6 changes: 3 additions & 3 deletions internal/admission/controller/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestHandleAdmission(t *testing.T) {
Checker: failTestChecker{t: t},
}

result, err := adm.HandleAdmission(&admissionv1.AdmissionReview{
_, err := adm.HandleAdmission(&admissionv1.AdmissionReview{
z1cheng marked this conversation as resolved.
Show resolved Hide resolved
Request: &admissionv1.AdmissionRequest{
Kind: v1.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"},
},
Expand All @@ -76,12 +76,12 @@ func TestHandleAdmission(t *testing.T) {
t.Fatalf("with a non ingress resource, the check should not pass")
}

result, err = adm.HandleAdmission(nil)
_, err = adm.HandleAdmission(nil)
if err == nil {
t.Fatalf("with a nil AdmissionReview request, the check should not pass")
}

result, err = adm.HandleAdmission(&admissionv1.AdmissionReview{
result, err := adm.HandleAdmission(&admissionv1.AdmissionReview{
Request: &admissionv1.AdmissionRequest{
Kind: v1.GroupVersionKind{Group: networking.GroupName, Version: "v1", Kind: "Ingress"},
Object: runtime.RawExtension{
Expand Down
40 changes: 0 additions & 40 deletions internal/ingress/controller/nginx.go
z1cheng marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ type NGINXController struct {
store store.Storer

metricCollector metric.Collector
admissionCollector metric.Collector

validationWebhookServer *http.Server

Expand Down Expand Up @@ -799,45 +798,6 @@ func (n *NGINXController) setupSSLProxy() {
}()
}

// Helper function to clear Certificates from the ingress configuration since they should be ignored when
// checking if the new configuration changes can be applied dynamically if dynamic certificates is on
func clearCertificates(config *ingress.Configuration) {
var clearedServers []*ingress.Server
for _, server := range config.Servers {
copyOfServer := *server
copyOfServer.SSLCert = nil
clearedServers = append(clearedServers, &copyOfServer)
}
config.Servers = clearedServers
}

// Helper function to clear endpoints from the ingress configuration since they should be ignored when
// checking if the new configuration changes can be applied dynamically.
func clearL4serviceEndpoints(config *ingress.Configuration) {
var clearedTCPL4Services []ingress.L4Service
var clearedUDPL4Services []ingress.L4Service
for _, service := range config.TCPEndpoints {
copyofService := ingress.L4Service{
Port: service.Port,
Backend: service.Backend,
Endpoints: []ingress.Endpoint{},
Service: nil,
}
clearedTCPL4Services = append(clearedTCPL4Services, copyofService)
}
for _, service := range config.UDPEndpoints {
copyofService := ingress.L4Service{
Port: service.Port,
Backend: service.Backend,
Endpoints: []ingress.Endpoint{},
Service: nil,
}
clearedUDPL4Services = append(clearedUDPL4Services, copyofService)
}
config.TCPEndpoints = clearedTCPL4Services
config.UDPEndpoints = clearedUDPL4Services
}

// configureDynamically encodes new Backends in JSON format and POSTs the
// payload to an internal HTTP endpoint handled by Lua.
func (n *NGINXController) configureDynamically(pcfg *ingress.Configuration) error {
Expand Down
5 changes: 3 additions & 2 deletions internal/ingress/controller/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -1186,15 +1186,16 @@ func buildAuthSignURLLocation(location, authSignURL string) string {
}

var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
var random *rand.Rand
z1cheng marked this conversation as resolved.
Show resolved Hide resolved

func init() {
rand.Seed(time.Now().UnixNano())
random = rand.New(rand.NewSource(time.Now().UnixNano()))
}

func randomString() string {
b := make([]rune, 32)
for i := range b {
b[i] = letters[rand.Intn(len(letters))] // #nosec
b[i] = letters[random.Intn(len(letters))] // #nosec
}

return string(b)
Expand Down
2 changes: 1 addition & 1 deletion internal/net/ssl/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func ConfigureCRL(name string, crl []byte, sslCert *ingress.SSLCert) error {
return fmt.Errorf("CRL file %v contains invalid data, and must be created only with PEM formatted certificates", name)
}

_, err := x509.ParseCRL(pemCRLBlock.Bytes)
_, err := x509.ParseRevocationList(pemCRLBlock.Bytes)
z1cheng marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return fmt.Errorf(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/annotations/affinitymode.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ var _ = framework.DescribeAnnotation("affinitymode", func() {
framework.Sleep()

// validate, there is no backend to serve the request
response = request.WithCookies(cookies).Expect().Status(http.StatusServiceUnavailable)
request.WithCookies(cookies).Expect().Status(http.StatusServiceUnavailable)

// create brand new backends
replicas = 2
Expand Down
7 changes: 0 additions & 7 deletions test/e2e/framework/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,8 @@ type deploymentOptions struct {
name string
namespace string
image string
port int32
replicas int
command []string
args []string
env []corev1.EnvVar
volumeMounts []corev1.VolumeMount
volumes []corev1.Volume
svcAnnotations map[string]string
setProbe bool
}

// WithDeploymentNamespace allows configuring the deployment's namespace
Expand Down
18 changes: 1 addition & 17 deletions test/e2e/framework/httpexpect/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,4 @@ func (c *chain) fail(message string, args ...interface{}) {
}
c.failbit = true
c.reporter.Errorf(message, args...)
}

func (c *chain) reset() {
c.failbit = false
}

func (c *chain) assertFailed(r Reporter) {
if !c.failbit {
r.Errorf("expected chain is failed, but it's ok")
}
}

func (c *chain) assertOK(r Reporter) {
if c.failbit {
r.Errorf("expected chain is ok, but it's failed")
}
}
}
4 changes: 2 additions & 2 deletions test/e2e/status/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var _ = framework.IngressNginxDescribe("[Status] status update", func() {

f.NewEchoDeployment()

ing := f.EnsureIngress(framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, nil))
f.EnsureIngress(framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, nil))

f.WaitForNginxConfiguration(
func(cfg string) bool {
Expand All @@ -84,7 +84,7 @@ var _ = framework.IngressNginxDescribe("[Status] status update", func() {
err = cmd.Process.Kill()
assert.Nil(ginkgo.GinkgoT(), err, "unexpected error terminating kubectl proxy")

ing, err = f.KubeClientSet.NetworkingV1().Ingresses(f.Namespace).Get(context.TODO(), host, metav1.GetOptions{})
ing, err := f.KubeClientSet.NetworkingV1().Ingresses(f.Namespace).Get(context.TODO(), host, metav1.GetOptions{})
assert.Nil(ginkgo.GinkgoT(), err, "unexpected error getting %s/%v Ingress", f.Namespace, host)

ing.Status.LoadBalancer.Ingress = []v1.IngressLoadBalancerIngress{}
Expand Down