Update main.go
All checks were successful
Build Go Binary / build (push) Successful in 43s

This commit is contained in:
holzi1005 2025-08-06 12:42:03 +02:00
parent 144fbdd18b
commit b15afb8c06

28
main.go
View file

@ -30,6 +30,10 @@ type BackendServer struct {
type Backend struct {
Name string
Balance string
Mode string
CookieName string
CookieFlags string
HealthCheck bool
Servers []BackendServer
}
@ -180,10 +184,6 @@ func main() {
backends := []Backend{}
for _, svc := range services {
if svc.Spec.Type != "ClusterIP" {
continue
}
if annotationCheckEnabled {
val, ok := svc.Metadata.Annotations["haproxy/enabled"]
if !ok || val != "true" {
@ -197,9 +197,28 @@ func main() {
continue
}
ann := svc.Metadata.Annotations
b := Backend{
Name: "SRV_" + strings.ReplaceAll(svc.Metadata.Name, " ", "-"),
Balance: "leastconn",
Mode: "tcp", // default
CookieName: "",
CookieFlags: "",
HealthCheck: true,
}
if val, ok := ann["haproxy/mode"]; ok && val != "" {
b.Mode = val
}
if val, ok := ann["haproxy/cookie-name"]; ok && val != "" {
b.CookieName = val
}
if val, ok := ann["haproxy/cookie-flags"]; ok && val != "" {
b.CookieFlags = val
}
if val, ok := ann["haproxy/health-check"]; ok && strings.ToLower(val) == "false" {
b.HealthCheck = false
}
servers := []BackendServer{}
@ -221,7 +240,6 @@ func main() {
}
}
b.Servers = servers
backends = append(backends, b)
}