This commit is contained in:
parent
144fbdd18b
commit
b15afb8c06
1 changed files with 30 additions and 12 deletions
28
main.go
28
main.go
|
@ -30,6 +30,10 @@ type BackendServer struct {
|
||||||
type Backend struct {
|
type Backend struct {
|
||||||
Name string
|
Name string
|
||||||
Balance string
|
Balance string
|
||||||
|
Mode string
|
||||||
|
CookieName string
|
||||||
|
CookieFlags string
|
||||||
|
HealthCheck bool
|
||||||
Servers []BackendServer
|
Servers []BackendServer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,10 +184,6 @@ func main() {
|
||||||
backends := []Backend{}
|
backends := []Backend{}
|
||||||
|
|
||||||
for _, svc := range services {
|
for _, svc := range services {
|
||||||
if svc.Spec.Type != "ClusterIP" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if annotationCheckEnabled {
|
if annotationCheckEnabled {
|
||||||
val, ok := svc.Metadata.Annotations["haproxy/enabled"]
|
val, ok := svc.Metadata.Annotations["haproxy/enabled"]
|
||||||
if !ok || val != "true" {
|
if !ok || val != "true" {
|
||||||
|
@ -197,9 +197,28 @@ func main() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ann := svc.Metadata.Annotations
|
||||||
|
|
||||||
b := Backend{
|
b := Backend{
|
||||||
Name: "SRV_" + strings.ReplaceAll(svc.Metadata.Name, " ", "-"),
|
Name: "SRV_" + strings.ReplaceAll(svc.Metadata.Name, " ", "-"),
|
||||||
Balance: "leastconn",
|
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{}
|
servers := []BackendServer{}
|
||||||
|
@ -221,7 +240,6 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.Servers = servers
|
b.Servers = servers
|
||||||
|
|
||||||
backends = append(backends, b)
|
backends = append(backends, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue