Fix comments

Signed-off-by: z1cheng <imchench@gmail.com>
This commit is contained in:
z1cheng 2023-08-09 14:01:30 +00:00
parent 587963a1c6
commit 515de74955
7 changed files with 50 additions and 46 deletions

View file

@ -716,7 +716,7 @@ Do not try to edit it manually.
### [[Flag] watch namespace selector](https://github.com/kubernetes/ingress-nginx/tree/main/test/e2e/settings/namespace_selector.go#L30) ### [[Flag] watch namespace selector](https://github.com/kubernetes/ingress-nginx/tree/main/test/e2e/settings/namespace_selector.go#L30)
- [should ingore Ingress of namespace without label foo=bar and accept those of namespace with label foo=bar](https://github.com/kubernetes/ingress-nginx/tree/main/test/e2e/settings/namespace_selector.go#L63) - [should ignore Ingress of namespace without label foo=bar and accept those of namespace with label foo=bar](https://github.com/kubernetes/ingress-nginx/tree/main/test/e2e/settings/namespace_selector.go#L63)
### [[Security] no-auth-locations](https://github.com/kubernetes/ingress-nginx/tree/main/test/e2e/settings/no_auth_locations.go#L33) ### [[Security] no-auth-locations](https://github.com/kubernetes/ingress-nginx/tree/main/test/e2e/settings/no_auth_locations.go#L33)

View file

@ -65,6 +65,9 @@ func TestParse(t *testing.T) {
if testCase.skipValidation { if testCase.skipValidation {
parser.EnableAnnotationValidation = false parser.EnableAnnotationValidation = false
} }
t.Cleanup(func() {
parser.EnableAnnotationValidation = true
})
result, err := ap.Parse(ing) result, err := ap.Parse(ing)
if (err != nil) != testCase.wantErr { if (err != nil) != testCase.wantErr {
t.Errorf("ParseAliasAnnotation() annotation: %s, error = %v, wantErr %v", testCase.annotations, err, testCase.wantErr) t.Errorf("ParseAliasAnnotation() annotation: %s, error = %v, wantErr %v", testCase.annotations, err, testCase.wantErr)
@ -73,6 +76,4 @@ func TestParse(t *testing.T) {
t.Errorf("expected %v but returned %v, annotations: %s", testCase.expected, result, testCase.annotations) t.Errorf("expected %v but returned %v, annotations: %s", testCase.expected, result, testCase.annotations)
} }
} }
parser.EnableAnnotationValidation = true
} }

View file

@ -86,37 +86,36 @@ type Ingress struct {
CorsConfig cors.Config CorsConfig cors.Config
CustomHTTPErrors []int CustomHTTPErrors []int
DefaultBackend *apiv1.Service DefaultBackend *apiv1.Service
// TODO: Change this back into an error when https://github.com/imdario/mergo/issues/100 is resolved FastCGI fastcgi.Config
FastCGI fastcgi.Config Denied *string
Denied *string ExternalAuth authreq.Config
ExternalAuth authreq.Config EnableGlobalAuth bool
EnableGlobalAuth bool HTTP2PushPreload bool
HTTP2PushPreload bool Opentracing opentracing.Config
Opentracing opentracing.Config Opentelemetry opentelemetry.Config
Opentelemetry opentelemetry.Config Proxy proxy.Config
Proxy proxy.Config ProxySSL proxyssl.Config
ProxySSL proxyssl.Config RateLimit ratelimit.Config
RateLimit ratelimit.Config GlobalRateLimit globalratelimit.Config
GlobalRateLimit globalratelimit.Config Redirect redirect.Config
Redirect redirect.Config Rewrite rewrite.Config
Rewrite rewrite.Config Satisfy string
Satisfy string ServerSnippet string
ServerSnippet string ServiceUpstream bool
ServiceUpstream bool SessionAffinity sessionaffinity.Config
SessionAffinity sessionaffinity.Config SSLPassthrough bool
SSLPassthrough bool UsePortInRedirects bool
UsePortInRedirects bool UpstreamHashBy upstreamhashby.Config
UpstreamHashBy upstreamhashby.Config LoadBalancing string
LoadBalancing string UpstreamVhost string
UpstreamVhost string Denylist ipdenylist.SourceRange
Denylist ipdenylist.SourceRange XForwardedPrefix string
XForwardedPrefix string SSLCipher sslcipher.Config
SSLCipher sslcipher.Config Logs log.Config
Logs log.Config ModSecurity modsecurity.Config
ModSecurity modsecurity.Config Mirror mirror.Config
Mirror mirror.Config StreamSnippet string
StreamSnippet string Allowlist ipallowlist.SourceRange
Allowlist ipallowlist.SourceRange
} }
// Extractor defines the annotation parsers to be used in the extraction of annotations // Extractor defines the annotation parsers to be used in the extraction of annotations

View file

@ -195,7 +195,7 @@ func (n *NGINXController) syncIngress(interface{}) error {
pcfg.ConfigurationChecksum = fmt.Sprintf("%v", hash) pcfg.ConfigurationChecksum = fmt.Sprintf("%v", hash)
err := n.OnUpdate(pcfg) err := n.OnUpdate(*pcfg)
if err != nil { if err != nil {
n.metricCollector.IncReloadErrorCount() n.metricCollector.IncReloadErrorCount()
n.metricCollector.ConfigSuccess(hash, false) n.metricCollector.ConfigSuccess(hash, false)
@ -410,7 +410,7 @@ func (n *NGINXController) CheckIngress(ing *networking.Ingress) error {
testedSize = 1 testedSize = 1
} }
content, err := n.generateTemplate(&cfg, pcfg) content, err := n.generateTemplate(cfg, *pcfg)
if err != nil { if err != nil {
n.metricCollector.IncCheckErrorCount(ing.ObjectMeta.Namespace, ing.Name) n.metricCollector.IncCheckErrorCount(ing.ObjectMeta.Namespace, ing.Name)
return err return err
@ -530,7 +530,7 @@ func (n *NGINXController) getStreamServices(configmapName string, proto apiv1.Pr
klog.V(3).Infof("Searching Endpoints with %v port number %d for Service %q", proto, targetPort, nsName) klog.V(3).Infof("Searching Endpoints with %v port number %d for Service %q", proto, targetPort, nsName)
for i := range svc.Spec.Ports { for i := range svc.Spec.Ports {
sp := svc.Spec.Ports[i] sp := svc.Spec.Ports[i]
//nolint:gosec // Ingore G109 error //nolint:gosec // Ignore G109 error
if sp.Port == int32(targetPort) { if sp.Port == int32(targetPort) {
if sp.Protocol == proto { if sp.Protocol == proto {
endps = getEndpointsFromSlices(svc, &sp, proto, zone, n.store.GetServiceEndpointsSlices) endps = getEndpointsFromSlices(svc, &sp, proto, zone, n.store.GetServiceEndpointsSlices)
@ -1750,7 +1750,7 @@ func externalNamePorts(name string, svc *apiv1.Service) *apiv1.ServicePort {
} }
for _, svcPort := range svc.Spec.Ports { for _, svcPort := range svc.Spec.Ports {
//nolint:gosec // Ingore G109 error //nolint:gosec // Ignore G109 error
if svcPort.Port != int32(port) { if svcPort.Port != int32(port) {
continue continue
} }
@ -1770,7 +1770,7 @@ func externalNamePorts(name string, svc *apiv1.Service) *apiv1.ServicePort {
// ExternalName without port // ExternalName without port
return &apiv1.ServicePort{ return &apiv1.ServicePort{
Protocol: "TCP", Protocol: "TCP",
//nolint:gosec // Ingore G109 error //nolint:gosec // Ignore G109 error
Port: int32(port), Port: int32(port),
TargetPort: intstr.FromInt(port), TargetPort: intstr.FromInt(port),
} }

View file

@ -438,7 +438,9 @@ func (n *NGINXController) DefaultEndpoint() ingress.Endpoint {
} }
// generateTemplate returns the nginx configuration file content // generateTemplate returns the nginx configuration file content
func (n *NGINXController) generateTemplate(cfg *ngx_config.Configuration, ingressCfg *ingress.Configuration) ([]byte, error) { //
//nolint:gocritic // the cfg shouldn't be changed, and shouldn't be mutated by other processes while being rendered.
func (n *NGINXController) generateTemplate(cfg ngx_config.Configuration, ingressCfg ingress.Configuration) ([]byte, error) {
if n.cfg.EnableSSLPassthrough { if n.cfg.EnableSSLPassthrough {
servers := []*tcpproxy.TCPServer{} servers := []*tcpproxy.TCPServer{}
for _, pb := range ingressCfg.PassthroughBackends { for _, pb := range ingressCfg.PassthroughBackends {
@ -598,7 +600,7 @@ func (n *NGINXController) generateTemplate(cfg *ngx_config.Configuration, ingres
Servers: ingressCfg.Servers, Servers: ingressCfg.Servers,
TCPBackends: ingressCfg.TCPEndpoints, TCPBackends: ingressCfg.TCPEndpoints,
UDPBackends: ingressCfg.UDPEndpoints, UDPBackends: ingressCfg.UDPEndpoints,
Cfg: *cfg, Cfg: cfg,
IsIPV6Enabled: n.isIPV6Enabled && !cfg.DisableIpv6, IsIPV6Enabled: n.isIPV6Enabled && !cfg.DisableIpv6,
NginxStatusIpv4Whitelist: cfg.NginxStatusIpv4Whitelist, NginxStatusIpv4Whitelist: cfg.NginxStatusIpv4Whitelist,
NginxStatusIpv6Whitelist: cfg.NginxStatusIpv6Whitelist, NginxStatusIpv6Whitelist: cfg.NginxStatusIpv6Whitelist,
@ -658,11 +660,13 @@ Error: %v
// changes were detected. The received backend Configuration is merged with the // changes were detected. The received backend Configuration is merged with the
// configuration ConfigMap before generating the final configuration file. // configuration ConfigMap before generating the final configuration file.
// Returns nil in case the backend was successfully reloaded. // Returns nil in case the backend was successfully reloaded.
func (n *NGINXController) OnUpdate(ingressCfg *ingress.Configuration) error { //
//nolint:gocritic // the cfg shouldn't be changed, and shouldn't be mutated by other processes while being rendered.
func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) error {
cfg := n.store.GetBackendConfiguration() cfg := n.store.GetBackendConfiguration()
cfg.Resolver = n.resolver cfg.Resolver = n.resolver
content, err := n.generateTemplate(&cfg, ingressCfg) content, err := n.generateTemplate(cfg, ingressCfg)
if err != nil { if err != nil {
return err return err
} }

View file

@ -44,7 +44,7 @@ import (
// which the status should check if an update is required. // which the status should check if an update is required.
var UpdateInterval = 60 var UpdateInterval = 60
// Syncer syncer // Syncer is an interface that implements syncer
type Syncer interface { type Syncer interface {
Run(chan struct{}) Run(chan struct{})
@ -56,7 +56,7 @@ type ingressLister interface {
ListIngresses() []*ingress.Ingress ListIngresses() []*ingress.Ingress
} }
// Config config // Config is a structure that implements Client interfaces
type Config struct { type Config struct {
Client clientset.Interface Client clientset.Interface

View file

@ -59,7 +59,7 @@ var _ = framework.IngressNginxDescribeSerial("[Flag] watch namespace selector",
}) })
ginkgo.Context("With specific watch-namespace-selector flags", func() { ginkgo.Context("With specific watch-namespace-selector flags", func() {
ginkgo.It("should ingore Ingress of namespace without label foo=bar and accept those of namespace with label foo=bar", func() { ginkgo.It("should ignore Ingress of namespace without label foo=bar and accept those of namespace with label foo=bar", func() {
f.WaitForNginxConfiguration(func(cfg string) bool { f.WaitForNginxConfiguration(func(cfg string) bool {
return !strings.Contains(cfg, "server_name bar") && return !strings.Contains(cfg, "server_name bar") &&
strings.Contains(cfg, "server_name foo") strings.Contains(cfg, "server_name foo")