fixed naming

This commit is contained in:
ston1th 2021-11-28 17:02:58 +01:00
commit eb2ed92605

View file

@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"net"
"strings"
"git.giftfish.de/ston1th/haproxy-lb/pkg/api/types"
"git.giftfish.de/ston1th/haproxy-lb/pkg/api/v1/schema"
@ -38,8 +39,18 @@ func name(c, n string) string {
return c + "/" + n
}
const lbsep = "_"
func lbname(c, n string) string {
return c + "_" + n
return c + lbsep + n
}
func convlbname(n string) string {
a := strings.SplitN(n, lbsep, 1)
if len(a) != 2 {
return ""
}
return name(a[0], a[1])
}
func getIP(cidr string) (string, error) {
@ -191,13 +202,18 @@ func lbClusterHandler(ctx *types.Context) {
ctx.Err(types.ErrFollower)
return
}
for name, _ := range m {
for n, _ := range m {
name := convlbname(n)
cidr, err := ctx.Data.DB.GetCIDR(name)
if err != nil && err != cluster.ErrKeyNotFound {
ctx.Log.Error(err, "error reading IP of loadbalancer", "cluster", cl, "name", name)
ctx.Err(types.ErrISE)
return
}
if err == cluster.ErrKeyNotFound {
continue
}
err = ctx.Data.Net.FreeCIDR(cidr)
if err != nil && err != cluster.ErrKeyNotFound {
ctx.Log.Error(err, "error freeing IP of loadbalancer", "cluster", cl, "name", name)