Compare commits

..

No commits in common. "master" and "0.0.21" have entirely different histories.

2 changed files with 22 additions and 22 deletions

View file

@ -48,7 +48,8 @@ Environment=KUBERNETES_HOST=https://10.0.20.7:6443
Environment=KUBERNETES_TOKEN=eyJhbGciOi...
Environment=KUBERNETES_VERIFYSSL=false
Environment=HAPROXY_TEMPLATE=/etc/haproxy/haproxy.tmpl
ExecStart=/bin/bash /etc/haproxy/haproxy-generator.sh
ExecStart=/path/to/haproxy-generator > /etc/haproxy/haproxy.cfg.new
ExecStartPost=/bin/bash /etc/haproxy/haproxy-generator-post.sh
```
@ -70,11 +71,10 @@ WantedBy=timers.target
# Reload Script for post start
Copy the script to /etc/haproxy/haproxy-generator.sh
Copy the script to /etc/haproxy/haproxy-generator-post.sh
```
#!/bin/bash
/usr/local/bin/haproxy-generator > /etc/haproxy/haproxy.cfg.new
DIFF=$(diff /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.new)
/sbin/haproxy -f /etc/haproxy/haproxy.cfg.new -c
VALID=$?

12
main.go
View file

@ -188,6 +188,9 @@ func main() {
key := svc.Metadata.Namespace + "/" + svc.Metadata.Name
ep, found := endpointMap[key]
if !found || len(ep.Subsets) == 0 {
continue
}
b := Backend{
Name: "SRV_" + strings.ReplaceAll(svc.Metadata.Name, " ", "-"),
@ -207,6 +210,8 @@ func main() {
}
if val, ok := ann["haproxy/health-check"]; ok && val != "" {
b.HealthCheck = val
} else {
b.HealthCheck = ""
}
if val, ok := ann["haproxy/server-options"]; ok && val != "" {
b.ServerOptions = val
@ -220,8 +225,6 @@ func main() {
}
servers := []BackendServer{}
if found && len(ep.Subsets) > 0 {
for _, subset := range ep.Subsets {
for _, addr := range subset.Addresses {
for _, port := range subset.Ports {
@ -239,17 +242,14 @@ func main() {
}
}
}
}
b.Servers = servers
log.Printf("Backend %s: ServerOptions = %q", b.Name, b.ServerOptions)
backends = append(backends, b)
}
tmplAbsPath, err := filepath.Abs(templatePath)
if err != nil {
log.Fatalf("Failed to get absolute path: %v", err)
}
tmpl, err := getTemplate(tmplAbsPath)
if err != nil {
log.Fatalf("Failed to parse template: %v", err)