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

42
main.go
View file

@ -28,9 +28,13 @@ type BackendServer struct {
}
type Backend struct {
Name string
Balance string
Servers []BackendServer
Name string
Balance string
Mode string
CookieName string
CookieFlags string
HealthCheck bool
Servers []BackendServer
}
func getEnv(key, fallback string) string {
@ -118,8 +122,8 @@ func main() {
type Service struct {
Metadata struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
Name string `json:"name"`
Namespace string `json:"namespace"`
Annotations map[string]string `json:"annotations"`
} `json:"metadata"`
Spec struct {
@ -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",
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)
}