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