Fix golang-ci linter errors
Signed-off-by: z1cheng <imchench@gmail.com>
This commit is contained in:
parent
ab99e23bba
commit
2bb2d9ef15
10 changed files with 11 additions and 81 deletions
|
@ -18,11 +18,8 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand" // #nosec
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||||
|
|
||||||
|
@ -41,8 +38,6 @@ import (
|
||||||
func main() {
|
func main() {
|
||||||
klog.InitFlags(nil)
|
klog.InitFlags(nil)
|
||||||
|
|
||||||
rand.Seed(time.Now().UnixNano())
|
|
||||||
|
|
||||||
fmt.Println(version.String())
|
fmt.Println(version.String())
|
||||||
var err error
|
var err error
|
||||||
showVersion, conf, err := ingressflags.ParseFlags()
|
showVersion, conf, err := ingressflags.ParseFlags()
|
||||||
|
|
|
@ -19,7 +19,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand" // #nosec
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -54,8 +53,6 @@ import (
|
||||||
func main() {
|
func main() {
|
||||||
klog.InitFlags(nil)
|
klog.InitFlags(nil)
|
||||||
|
|
||||||
rand.Seed(time.Now().UnixNano())
|
|
||||||
|
|
||||||
fmt.Println(version.String())
|
fmt.Println(version.String())
|
||||||
|
|
||||||
showVersion, conf, err := ingressflags.ParseFlags()
|
showVersion, conf, err := ingressflags.ParseFlags()
|
||||||
|
|
|
@ -67,7 +67,7 @@ func TestHandleAdmission(t *testing.T) {
|
||||||
Checker: failTestChecker{t: t},
|
Checker: failTestChecker{t: t},
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := adm.HandleAdmission(&admissionv1.AdmissionReview{
|
_, err := adm.HandleAdmission(&admissionv1.AdmissionReview{
|
||||||
Request: &admissionv1.AdmissionRequest{
|
Request: &admissionv1.AdmissionRequest{
|
||||||
Kind: v1.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"},
|
Kind: v1.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"},
|
||||||
},
|
},
|
||||||
|
@ -76,12 +76,12 @@ func TestHandleAdmission(t *testing.T) {
|
||||||
t.Fatalf("with a non ingress resource, the check should not pass")
|
t.Fatalf("with a non ingress resource, the check should not pass")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err = adm.HandleAdmission(nil)
|
_, err = adm.HandleAdmission(nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("with a nil AdmissionReview request, the check should not pass")
|
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{
|
Request: &admissionv1.AdmissionRequest{
|
||||||
Kind: v1.GroupVersionKind{Group: networking.GroupName, Version: "v1", Kind: "Ingress"},
|
Kind: v1.GroupVersionKind{Group: networking.GroupName, Version: "v1", Kind: "Ingress"},
|
||||||
Object: runtime.RawExtension{
|
Object: runtime.RawExtension{
|
||||||
|
|
|
@ -249,7 +249,6 @@ type NGINXController struct {
|
||||||
store store.Storer
|
store store.Storer
|
||||||
|
|
||||||
metricCollector metric.Collector
|
metricCollector metric.Collector
|
||||||
admissionCollector metric.Collector
|
|
||||||
|
|
||||||
validationWebhookServer *http.Server
|
validationWebhookServer *http.Server
|
||||||
|
|
||||||
|
@ -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, ©OfServer)
|
|
||||||
}
|
|
||||||
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
|
// configureDynamically encodes new Backends in JSON format and POSTs the
|
||||||
// payload to an internal HTTP endpoint handled by Lua.
|
// payload to an internal HTTP endpoint handled by Lua.
|
||||||
func (n *NGINXController) configureDynamically(pcfg *ingress.Configuration) error {
|
func (n *NGINXController) configureDynamically(pcfg *ingress.Configuration) error {
|
||||||
|
|
|
@ -1186,15 +1186,16 @@ func buildAuthSignURLLocation(location, authSignURL string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||||
|
var random *rand.Rand
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rand.Seed(time.Now().UnixNano())
|
random = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func randomString() string {
|
func randomString() string {
|
||||||
b := make([]rune, 32)
|
b := make([]rune, 32)
|
||||||
for i := range b {
|
for i := range b {
|
||||||
b[i] = letters[rand.Intn(len(letters))] // #nosec
|
b[i] = letters[random.Intn(len(letters))] // #nosec
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(b)
|
return string(b)
|
||||||
|
|
|
@ -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)
|
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)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf(err.Error())
|
return fmt.Errorf(err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ var _ = framework.DescribeAnnotation("affinitymode", func() {
|
||||||
framework.Sleep()
|
framework.Sleep()
|
||||||
|
|
||||||
// validate, there is no backend to serve the request
|
// 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
|
// create brand new backends
|
||||||
replicas = 2
|
replicas = 2
|
||||||
|
|
|
@ -56,15 +56,8 @@ type deploymentOptions struct {
|
||||||
name string
|
name string
|
||||||
namespace string
|
namespace string
|
||||||
image string
|
image string
|
||||||
port int32
|
|
||||||
replicas int
|
replicas int
|
||||||
command []string
|
|
||||||
args []string
|
|
||||||
env []corev1.EnvVar
|
|
||||||
volumeMounts []corev1.VolumeMount
|
|
||||||
volumes []corev1.Volume
|
|
||||||
svcAnnotations map[string]string
|
svcAnnotations map[string]string
|
||||||
setProbe bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithDeploymentNamespace allows configuring the deployment's namespace
|
// WithDeploymentNamespace allows configuring the deployment's namespace
|
||||||
|
|
|
@ -35,20 +35,4 @@ func (c *chain) fail(message string, args ...interface{}) {
|
||||||
}
|
}
|
||||||
c.failbit = true
|
c.failbit = true
|
||||||
c.reporter.Errorf(message, args...)
|
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")
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -71,7 +71,7 @@ var _ = framework.IngressNginxDescribe("[Status] status update", func() {
|
||||||
|
|
||||||
f.NewEchoDeployment()
|
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(
|
f.WaitForNginxConfiguration(
|
||||||
func(cfg string) bool {
|
func(cfg string) bool {
|
||||||
|
@ -84,7 +84,7 @@ var _ = framework.IngressNginxDescribe("[Status] status update", func() {
|
||||||
err = cmd.Process.Kill()
|
err = cmd.Process.Kill()
|
||||||
assert.Nil(ginkgo.GinkgoT(), err, "unexpected error terminating kubectl proxy")
|
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)
|
assert.Nil(ginkgo.GinkgoT(), err, "unexpected error getting %s/%v Ingress", f.Namespace, host)
|
||||||
|
|
||||||
ing.Status.LoadBalancer.Ingress = []v1.IngressLoadBalancerIngress{}
|
ing.Status.LoadBalancer.Ingress = []v1.IngressLoadBalancerIngress{}
|
||||||
|
|
Loading…
Reference in a new issue