Fix golangci-lint errors (#10196)
* Fix golangci-lint errors Signed-off-by: z1cheng <imchench@gmail.com> * Fix dupl errors Signed-off-by: z1cheng <imchench@gmail.com> * Fix comments Signed-off-by: z1cheng <imchench@gmail.com> * Fix errcheck lint errors Signed-off-by: z1cheng <imchench@gmail.com> * Fix assert in e2e test Signed-off-by: z1cheng <imchench@gmail.com> * Not interrupt the waitForPodsReady Signed-off-by: z1cheng <imchench@gmail.com> * Replace string with constant Signed-off-by: z1cheng <imchench@gmail.com> * Fix comments Signed-off-by: z1cheng <imchench@gmail.com> * Revert write file permision Signed-off-by: z1cheng <imchench@gmail.com> --------- Signed-off-by: z1cheng <imchench@gmail.com>
This commit is contained in:
parent
46d87d3462
commit
b3060bfbd0
253 changed files with 2434 additions and 2113 deletions
|
|
@ -60,51 +60,56 @@ import (
|
|||
"k8s.io/ingress-nginx/pkg/util/file"
|
||||
)
|
||||
|
||||
const (
|
||||
exampleBackend = "example-http-svc-1-80"
|
||||
TRUE = "true"
|
||||
)
|
||||
|
||||
type fakeIngressStore struct {
|
||||
ingresses []*ingress.Ingress
|
||||
configuration ngx_config.Configuration
|
||||
}
|
||||
|
||||
func (fakeIngressStore) GetIngressClass(ing *networking.Ingress, icConfig *ingressclass.IngressClassConfiguration) (string, error) {
|
||||
func (fakeIngressStore) GetIngressClass(_ *networking.Ingress, _ *ingressclass.Configuration) (string, error) {
|
||||
return "nginx", nil
|
||||
}
|
||||
|
||||
func (fis fakeIngressStore) GetBackendConfiguration() ngx_config.Configuration {
|
||||
func (fis *fakeIngressStore) GetBackendConfiguration() ngx_config.Configuration {
|
||||
return fis.configuration
|
||||
}
|
||||
|
||||
func (fis fakeIngressStore) GetSecurityConfiguration() defaults.SecurityConfiguration {
|
||||
func (fis *fakeIngressStore) GetSecurityConfiguration() defaults.SecurityConfiguration {
|
||||
return defaults.SecurityConfiguration{
|
||||
AnnotationsRiskLevel: fis.configuration.AnnotationsRiskLevel,
|
||||
AllowCrossNamespaceResources: fis.configuration.AllowCrossNamespaceResources,
|
||||
}
|
||||
}
|
||||
|
||||
func (fakeIngressStore) GetConfigMap(key string) (*corev1.ConfigMap, error) {
|
||||
func (fakeIngressStore) GetConfigMap(_ string) (*corev1.ConfigMap, error) {
|
||||
return nil, fmt.Errorf("test error")
|
||||
}
|
||||
|
||||
func (fakeIngressStore) GetSecret(key string) (*corev1.Secret, error) {
|
||||
func (fakeIngressStore) GetSecret(_ string) (*corev1.Secret, error) {
|
||||
return nil, fmt.Errorf("test error")
|
||||
}
|
||||
|
||||
func (fakeIngressStore) GetService(key string) (*corev1.Service, error) {
|
||||
func (fakeIngressStore) GetService(_ string) (*corev1.Service, error) {
|
||||
return nil, fmt.Errorf("test error")
|
||||
}
|
||||
|
||||
func (fakeIngressStore) GetServiceEndpointsSlices(key string) ([]*discoveryv1.EndpointSlice, error) {
|
||||
func (fakeIngressStore) GetServiceEndpointsSlices(_ string) ([]*discoveryv1.EndpointSlice, error) {
|
||||
return nil, fmt.Errorf("test error")
|
||||
}
|
||||
|
||||
func (fis fakeIngressStore) ListIngresses() []*ingress.Ingress {
|
||||
func (fis *fakeIngressStore) ListIngresses() []*ingress.Ingress {
|
||||
return fis.ingresses
|
||||
}
|
||||
|
||||
func (fis fakeIngressStore) FilterIngresses(ingresses []*ingress.Ingress, filterFunc store.IngressFilterFunc) []*ingress.Ingress {
|
||||
func (fis *fakeIngressStore) FilterIngresses(ingresses []*ingress.Ingress, _ store.IngressFilterFunc) []*ingress.Ingress {
|
||||
return ingresses
|
||||
}
|
||||
|
||||
func (fakeIngressStore) GetLocalSSLCert(name string) (*ingress.SSLCert, error) {
|
||||
func (fakeIngressStore) GetLocalSSLCert(_ string) (*ingress.SSLCert, error) {
|
||||
return nil, fmt.Errorf("test error")
|
||||
}
|
||||
|
||||
|
|
@ -120,7 +125,7 @@ func (fakeIngressStore) GetDefaultBackend() defaults.Backend {
|
|||
return defaults.Backend{}
|
||||
}
|
||||
|
||||
func (fakeIngressStore) Run(stopCh chan struct{}) {}
|
||||
func (fakeIngressStore) Run(_ chan struct{}) {}
|
||||
|
||||
type testNginxTestCommand struct {
|
||||
t *testing.T
|
||||
|
|
@ -129,7 +134,7 @@ type testNginxTestCommand struct {
|
|||
err error
|
||||
}
|
||||
|
||||
func (ntc testNginxTestCommand) ExecCommand(args ...string) *exec.Cmd {
|
||||
func (ntc testNginxTestCommand) ExecCommand(_ ...string) *exec.Cmd {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -152,7 +157,7 @@ func (ntc testNginxTestCommand) Test(cfg string) ([]byte, error) {
|
|||
|
||||
type fakeTemplate struct{}
|
||||
|
||||
func (fakeTemplate) Write(conf ngx_config.TemplateConfig) ([]byte, error) {
|
||||
func (fakeTemplate) Write(conf *ngx_config.TemplateConfig) ([]byte, error) {
|
||||
r := []byte{}
|
||||
for _, s := range conf.Servers {
|
||||
if len(r) > 0 {
|
||||
|
|
@ -196,7 +201,7 @@ func TestCheckIngress(t *testing.T) {
|
|||
nginx.metricCollector = metric.DummyCollector{}
|
||||
|
||||
nginx.t = fakeTemplate{}
|
||||
nginx.store = fakeIngressStore{
|
||||
nginx.store = &fakeIngressStore{
|
||||
ingresses: []*ingress.Ingress{},
|
||||
}
|
||||
|
||||
|
|
@ -226,7 +231,7 @@ func TestCheckIngress(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("When the hostname is updated", func(t *testing.T) {
|
||||
nginx.store = fakeIngressStore{
|
||||
nginx.store = &fakeIngressStore{
|
||||
ingresses: []*ingress.Ingress{
|
||||
{
|
||||
Ingress: *ing,
|
||||
|
|
@ -273,7 +278,7 @@ func TestCheckIngress(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("When snippets are disabled and user tries to use snippet annotation", func(t *testing.T) {
|
||||
nginx.store = fakeIngressStore{
|
||||
nginx.store = &fakeIngressStore{
|
||||
ingresses: []*ingress.Ingress{},
|
||||
configuration: ngx_config.Configuration{
|
||||
AllowSnippetAnnotations: false,
|
||||
|
|
@ -290,7 +295,7 @@ func TestCheckIngress(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("When invalid directives are used in annotation values", func(t *testing.T) {
|
||||
nginx.store = fakeIngressStore{
|
||||
nginx.store = &fakeIngressStore{
|
||||
ingresses: []*ingress.Ingress{},
|
||||
configuration: ngx_config.Configuration{
|
||||
AnnotationValueWordBlocklist: "invalid_directive, another_directive",
|
||||
|
|
@ -366,12 +371,11 @@ func TestCheckIngress(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCheckWarning(t *testing.T) {
|
||||
|
||||
// Ensure no panic with wrong arguments
|
||||
var nginx = &NGINXController{}
|
||||
nginx := &NGINXController{}
|
||||
|
||||
nginx.t = fakeTemplate{}
|
||||
nginx.store = fakeIngressStore{
|
||||
nginx.store = &fakeIngressStore{
|
||||
ingresses: []*ingress.Ingress{},
|
||||
}
|
||||
|
||||
|
|
@ -390,7 +394,7 @@ func TestCheckWarning(t *testing.T) {
|
|||
},
|
||||
}
|
||||
t.Run("when a deprecated annotation is used a warning should be returned", func(t *testing.T) {
|
||||
ing.ObjectMeta.Annotations[parser.GetAnnotationWithPrefix("enable-influxdb")] = "true"
|
||||
ing.ObjectMeta.Annotations[parser.GetAnnotationWithPrefix("enable-influxdb")] = TRUE
|
||||
defer func() {
|
||||
ing.ObjectMeta.Annotations = map[string]string{}
|
||||
}()
|
||||
|
|
@ -407,7 +411,6 @@ func TestCheckWarning(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("When an invalid pathType is used, a warning should be returned", func(t *testing.T) {
|
||||
|
||||
rules := ing.Spec.DeepCopy().Rules
|
||||
ing.Spec.Rules = []networking.IngressRule{
|
||||
{
|
||||
|
|
@ -443,8 +446,8 @@ func TestCheckWarning(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("adding invalid annotations increases the warning count", func(t *testing.T) {
|
||||
ing.ObjectMeta.Annotations[parser.GetAnnotationWithPrefix("enable-influxdb")] = "true"
|
||||
ing.ObjectMeta.Annotations[parser.GetAnnotationWithPrefix("secure-verify-ca-secret")] = "true"
|
||||
ing.ObjectMeta.Annotations[parser.GetAnnotationWithPrefix("enable-influxdb")] = TRUE
|
||||
ing.ObjectMeta.Annotations[parser.GetAnnotationWithPrefix("secure-verify-ca-secret")] = TRUE
|
||||
ing.ObjectMeta.Annotations[parser.GetAnnotationWithPrefix("influxdb-host")] = "blabla"
|
||||
defer func() {
|
||||
ing.ObjectMeta.Annotations = map[string]string{}
|
||||
|
|
@ -472,6 +475,7 @@ func TestCheckWarning(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
//nolint:dupl // Ignore dupl errors for similar test case
|
||||
func TestMergeAlternativeBackends(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
ingress *ingress.Ingress
|
||||
|
|
@ -1537,8 +1541,8 @@ func TestExtractTLSSecretName(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
//nolint:gocyclo // Ignore function complexity error
|
||||
func TestGetBackendServers(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
Ingresses []*ingress.Ingress
|
||||
Validate func(ingresses []*ingress.Ingress, upstreams []*ingress.Backend, servers []*ingress.Server)
|
||||
|
|
@ -2078,7 +2082,7 @@ func TestGetBackendServers(t *testing.T) {
|
|||
t.Errorf("server hostname should be 'example.com', got '%s'", s.Hostname)
|
||||
}
|
||||
|
||||
if s.Locations[0].Backend != "example-http-svc-1-80" || s.Locations[1].Backend != "example-http-svc-1-80" || s.Locations[2].Backend != "example-http-svc-1-80" {
|
||||
if s.Locations[0].Backend != exampleBackend || s.Locations[1].Backend != exampleBackend || s.Locations[2].Backend != exampleBackend {
|
||||
t.Errorf("all location backend should be 'example-http-svc-1-80'")
|
||||
}
|
||||
|
||||
|
|
@ -2087,7 +2091,7 @@ func TestGetBackendServers(t *testing.T) {
|
|||
return
|
||||
}
|
||||
|
||||
if upstreams[0].Name != "example-http-svc-1-80" {
|
||||
if upstreams[0].Name != exampleBackend {
|
||||
t.Errorf("example-http-svc-1-80 should be first upstream, got %s", upstreams[0].Name)
|
||||
return
|
||||
}
|
||||
|
|
@ -2101,6 +2105,7 @@ func TestGetBackendServers(t *testing.T) {
|
|||
SetConfigMap: testConfigMap,
|
||||
},
|
||||
{
|
||||
//nolint:dupl // Ignore dupl errors for similar test case
|
||||
Ingresses: []*ingress.Ingress{
|
||||
{
|
||||
Ingress: networking.Ingress{
|
||||
|
|
@ -2208,6 +2213,7 @@ func TestGetBackendServers(t *testing.T) {
|
|||
SetConfigMap: testConfigMap,
|
||||
},
|
||||
{
|
||||
//nolint:dupl // Ignore dupl errors for similar test case
|
||||
Ingresses: []*ingress.Ingress{
|
||||
{
|
||||
Ingress: networking.Ingress{
|
||||
|
|
@ -2319,7 +2325,7 @@ func TestGetBackendServers(t *testing.T) {
|
|||
SelfLink: fmt.Sprintf("/api/v1/namespaces/%s/configmaps/config", ns),
|
||||
},
|
||||
Data: map[string]string{
|
||||
"proxy-ssl-location-only": "true",
|
||||
"proxy-ssl-location-only": TRUE,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -2380,7 +2386,7 @@ func TestGetBackendServers(t *testing.T) {
|
|||
SelfLink: fmt.Sprintf("/api/v1/namespaces/%s/configmaps/config", ns),
|
||||
},
|
||||
Data: map[string]string{
|
||||
"proxy-ssl-location-only": "true",
|
||||
"proxy-ssl-location-only": TRUE,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -2449,7 +2455,6 @@ func TestGetBackendServers(t *testing.T) {
|
|||
if len(s.Locations[0].Allowlist.CIDR) != 1 || s.Locations[0].Allowlist.CIDR[0] != "10.0.0.0/24" {
|
||||
t.Errorf("allow list was incorrectly dropped, len should be 1 and contain 10.0.0.0/24")
|
||||
}
|
||||
|
||||
},
|
||||
SetConfigMap: func(ns string) *corev1.ConfigMap {
|
||||
return &corev1.ConfigMap{
|
||||
|
|
@ -2520,7 +2525,7 @@ func newNGINXController(t *testing.T) *NGINXController {
|
|||
channels.NewRingChannel(10),
|
||||
false,
|
||||
true,
|
||||
&ingressclass.IngressClassConfiguration{
|
||||
&ingressclass.Configuration{
|
||||
Controller: "k8s.io/ingress-nginx",
|
||||
AnnotationValue: "nginx",
|
||||
},
|
||||
|
|
@ -2586,7 +2591,7 @@ func newDynamicNginxController(t *testing.T, setConfigMap func(string) *corev1.C
|
|||
channels.NewRingChannel(10),
|
||||
false,
|
||||
true,
|
||||
&ingressclass.IngressClassConfiguration{
|
||||
&ingressclass.Configuration{
|
||||
Controller: "k8s.io/ingress-nginx",
|
||||
AnnotationValue: "nginx",
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue