Compare commits
5 commits
Author | SHA1 | Date | |
---|---|---|---|
65de2adc47 | |||
150373a819 | |||
91fbebd25e | |||
f889527cc7 | |||
1ba52cb8fd |
2 changed files with 38 additions and 23 deletions
21
README_GO.md
21
README_GO.md
|
@ -48,8 +48,7 @@ Environment=KUBERNETES_HOST=https://10.0.20.7:6443
|
||||||
Environment=KUBERNETES_TOKEN=eyJhbGciOi...
|
Environment=KUBERNETES_TOKEN=eyJhbGciOi...
|
||||||
Environment=KUBERNETES_VERIFYSSL=false
|
Environment=KUBERNETES_VERIFYSSL=false
|
||||||
Environment=HAPROXY_TEMPLATE=/etc/haproxy/haproxy.tmpl
|
Environment=HAPROXY_TEMPLATE=/etc/haproxy/haproxy.tmpl
|
||||||
ExecStart=/path/to/haproxy-generator > /etc/haproxy/haproxy.cfg
|
ExecStart=/bin/bash /etc/haproxy/haproxy-generator.sh
|
||||||
ExecStartPost=/bin/systemctl restart haproxy
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -69,6 +68,24 @@ WantedBy=timers.target
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Reload Script for post start
|
||||||
|
|
||||||
|
Copy the script to /etc/haproxy/haproxy-generator.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=$?
|
||||||
|
|
||||||
|
if [ "$DIFF" != "" ] && [ $VALID -eq 0 ]
|
||||||
|
then
|
||||||
|
mv /etc/haproxy/haproxy.cfg.new /etc/haproxy/haproxy.cfg
|
||||||
|
/usr/sbin/service haproxy restart
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
|
||||||
# Service Annotations
|
# Service Annotations
|
||||||
|
|
||||||
| Annotation-Key | Beschreibung | Typ | Beispielwert |
|
| Annotation-Key | Beschreibung | Typ | Beispielwert |
|
||||||
|
|
16
main.go
16
main.go
|
@ -188,9 +188,6 @@ func main() {
|
||||||
|
|
||||||
key := svc.Metadata.Namespace + "/" + svc.Metadata.Name
|
key := svc.Metadata.Namespace + "/" + svc.Metadata.Name
|
||||||
ep, found := endpointMap[key]
|
ep, found := endpointMap[key]
|
||||||
if !found || len(ep.Subsets) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
b := Backend{
|
b := Backend{
|
||||||
Name: "SRV_" + strings.ReplaceAll(svc.Metadata.Name, " ", "-"),
|
Name: "SRV_" + strings.ReplaceAll(svc.Metadata.Name, " ", "-"),
|
||||||
|
@ -210,8 +207,6 @@ func main() {
|
||||||
}
|
}
|
||||||
if val, ok := ann["haproxy/health-check"]; ok && val != "" {
|
if val, ok := ann["haproxy/health-check"]; ok && val != "" {
|
||||||
b.HealthCheck = val
|
b.HealthCheck = val
|
||||||
} else {
|
|
||||||
b.HealthCheck = ""
|
|
||||||
}
|
}
|
||||||
if val, ok := ann["haproxy/server-options"]; ok && val != "" {
|
if val, ok := ann["haproxy/server-options"]; ok && val != "" {
|
||||||
b.ServerOptions = val
|
b.ServerOptions = val
|
||||||
|
@ -225,7 +220,8 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
servers := []BackendServer{}
|
servers := []BackendServer{}
|
||||||
serverIndex := 1
|
|
||||||
|
if found && len(ep.Subsets) > 0 {
|
||||||
for _, subset := range ep.Subsets {
|
for _, subset := range ep.Subsets {
|
||||||
for _, addr := range subset.Addresses {
|
for _, addr := range subset.Addresses {
|
||||||
for _, port := range subset.Ports {
|
for _, port := range subset.Ports {
|
||||||
|
@ -233,8 +229,7 @@ func main() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
cookie := hashString(fmt.Sprintf("%s-%s-%d", svc.Metadata.Name, addr.IP, port.Port))
|
cookie := hashString(fmt.Sprintf("%s-%s-%d", svc.Metadata.Name, addr.IP, port.Port))
|
||||||
serverName := fmt.Sprintf("%s_%d", svc.Metadata.Name, serverIndex)
|
serverName := fmt.Sprintf("%s_%d", svc.Metadata.Name, cookie)
|
||||||
serverIndex++
|
|
||||||
servers = append(servers, BackendServer{
|
servers = append(servers, BackendServer{
|
||||||
Name: serverName,
|
Name: serverName,
|
||||||
Address: addr.IP,
|
Address: addr.IP,
|
||||||
|
@ -244,14 +239,17 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
b.Servers = servers
|
b.Servers = servers
|
||||||
log.Printf("Backend %s: ServerOptions = %q", b.Name, b.ServerOptions)
|
|
||||||
backends = append(backends, b)
|
backends = append(backends, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
tmplAbsPath, err := filepath.Abs(templatePath)
|
tmplAbsPath, err := filepath.Abs(templatePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to get absolute path: %v", err)
|
log.Fatalf("Failed to get absolute path: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpl, err := getTemplate(tmplAbsPath)
|
tmpl, err := getTemplate(tmplAbsPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to parse template: %v", err)
|
log.Fatalf("Failed to parse template: %v", err)
|
||||||
|
|
Loading…
Add table
Reference in a new issue