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

MINOR: allows customization of the tcp log format #570

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
28 changes: 23 additions & 5 deletions pkg/handler/tcp-services.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func (handler TCPServices) Update(k store.K8s, h haproxy.HAProxy, a annotations.
}
var r bool
reload = handler.clearFrontends(k, h)
logFormat := annotations.String("tcp-log-format", k.ConfigMaps.Main.Annotations)

var p tcpSvcParser
for port, tcpSvcAnn := range k.ConfigMaps.TCPServices.Annotations {
frontendName := fmt.Sprintf("tcp-%s", port)
Expand All @@ -44,14 +46,15 @@ func (handler TCPServices) Update(k store.K8s, h haproxy.HAProxy, a annotations.
frontend, errGet := h.FrontendGet(frontendName)
// Create Frontend
if errGet != nil {
frontend, r, err = handler.createTCPFrontend(h, frontendName, port, p.sslOffload)
frontend, r, err = handler.createTCPFrontend(h, frontendName, port, p.sslOffload, logFormat)
reload = reload || r
if err != nil {
logger.Error(err)
continue
}
}
// Update Frontend
frontend.LogFormat = logFormat
r, err = handler.updateTCPFrontend(k, h, frontend, p, a)
reload = reload || r
if err != nil {
Expand Down Expand Up @@ -121,12 +124,13 @@ func (handler TCPServices) clearFrontends(k store.K8s, h haproxy.HAProxy) (clear
return
}

func (handler TCPServices) createTCPFrontend(h haproxy.HAProxy, frontendName, bindPort string, sslOffload bool) (frontend models.Frontend, reload bool, err error) {
func (handler TCPServices) createTCPFrontend(h haproxy.HAProxy, frontendName, bindPort string, sslOffload bool, logFormat string) (frontend models.Frontend, reload bool, err error) {
// Create Frontend
frontend = models.Frontend{
Name: frontendName,
Mode: "tcp",
Tcplog: true,
Name: frontendName,
Mode: "tcp",
Tcplog: logFormat == "",
LogFormat: logFormat,
// DefaultBackend: route.BackendName,
}
var errors utils.Errors
Expand Down Expand Up @@ -189,6 +193,20 @@ func (handler TCPServices) updateTCPFrontend(k store.K8s, h haproxy.HAProxy, fro
reload = true
return
}
fe, err := h.FrontendGet(frontend.Name)
if err != nil {
err = fmt.Errorf("failed to get frontend: %w", err)
return
}
if fe.LogFormat != frontend.LogFormat {
err = h.FrontendEdit(frontend)
if err != nil {
err = fmt.Errorf("failed to edit frontend: %w", err)
return
}
logger.Debug("TCP log-format updated, reload required", frontend.Name)
reload = true
}

var svc *service.Service
var r bool
Expand Down
Loading