Skip to content

Commit cd9c959

Browse files
committed
Fix: nginx proxy server list not changed
Signed-off-by: joey <[email protected]>
1 parent f369ffb commit cd9c959

File tree

2 files changed

+39
-37
lines changed

2 files changed

+39
-37
lines changed

internal/ingress/controller/controller.go

+39
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import (
4646
"k8s.io/ingress-nginx/internal/k8s"
4747
"k8s.io/ingress-nginx/internal/nginx"
4848
"k8s.io/ingress-nginx/pkg/apis/ingress"
49+
"k8s.io/ingress-nginx/pkg/tcpproxy"
4950
utilingress "k8s.io/ingress-nginx/pkg/util/ingress"
5051
"k8s.io/klog/v2"
5152
)
@@ -185,6 +186,44 @@ func (n *NGINXController) syncIngress(interface{}) error {
185186
n.metricCollector.SetSSLExpireTime(servers)
186187
n.metricCollector.SetSSLInfo(servers)
187188

189+
if n.cfg.EnableSSLPassthrough {
190+
servers := []*tcpproxy.TCPServer{}
191+
for _, pb := range pcfg.PassthroughBackends {
192+
svc := pb.Service
193+
if svc == nil {
194+
klog.Warningf("Missing Service for SSL Passthrough backend %q", pb.Backend)
195+
continue
196+
}
197+
port, err := strconv.Atoi(pb.Port.String()) // #nosec
198+
if err != nil {
199+
for _, sp := range svc.Spec.Ports {
200+
if sp.Name == pb.Port.String() {
201+
port = int(sp.Port)
202+
break
203+
}
204+
}
205+
} else {
206+
for _, sp := range svc.Spec.Ports {
207+
//nolint:gosec // Ignore G109 error
208+
if sp.Port == int32(port) {
209+
port = int(sp.Port)
210+
break
211+
}
212+
}
213+
}
214+
215+
// TODO: Allow PassthroughBackends to specify they support proxy-protocol
216+
servers = append(servers, &tcpproxy.TCPServer{
217+
Hostname: pb.Hostname,
218+
IP: svc.Spec.ClusterIP,
219+
Port: port,
220+
ProxyProtocol: false,
221+
})
222+
}
223+
224+
n.Proxy.ServerList = servers
225+
}
226+
188227
if n.runningConfig.Equal(pcfg) {
189228
klog.V(3).Infof("No configuration change detected, skipping backend reload")
190229
return nil

internal/ingress/controller/nginx.go

-37
Original file line numberDiff line numberDiff line change
@@ -455,43 +455,6 @@ func (n *NGINXController) DefaultEndpoint() ingress.Endpoint {
455455
//
456456
//nolint:gocritic // the cfg shouldn't be changed, and shouldn't be mutated by other processes while being rendered.
457457
func (n *NGINXController) generateTemplate(cfg ngx_config.Configuration, ingressCfg ingress.Configuration) ([]byte, error) {
458-
if n.cfg.EnableSSLPassthrough {
459-
servers := []*tcpproxy.TCPServer{}
460-
for _, pb := range ingressCfg.PassthroughBackends {
461-
svc := pb.Service
462-
if svc == nil {
463-
klog.Warningf("Missing Service for SSL Passthrough backend %q", pb.Backend)
464-
continue
465-
}
466-
port, err := strconv.Atoi(pb.Port.String()) // #nosec
467-
if err != nil {
468-
for _, sp := range svc.Spec.Ports {
469-
if sp.Name == pb.Port.String() {
470-
port = int(sp.Port)
471-
break
472-
}
473-
}
474-
} else {
475-
for _, sp := range svc.Spec.Ports {
476-
//nolint:gosec // Ignore G109 error
477-
if sp.Port == int32(port) {
478-
port = int(sp.Port)
479-
break
480-
}
481-
}
482-
}
483-
484-
// TODO: Allow PassthroughBackends to specify they support proxy-protocol
485-
servers = append(servers, &tcpproxy.TCPServer{
486-
Hostname: pb.Hostname,
487-
IP: svc.Spec.ClusterIP,
488-
Port: port,
489-
ProxyProtocol: false,
490-
})
491-
}
492-
493-
n.Proxy.ServerList = servers
494-
}
495458

496459
// NGINX cannot resize the hash tables used to store server names. For
497460
// this reason we check if the current size is correct for the host

0 commit comments

Comments
 (0)