Skip to content

Commit

Permalink
daemon: add BackendSlot to Service6Key.String and Service4Key.String
Browse files Browse the repository at this point in the history
    This commit adds BackendSlot value to the Service6Key.String
    and Service4Key.String methods. This is to prevent the
    service key from being deleted when the backend endpoint is deleted.

    Fixes: #29580

Signed-off-by: xyz-li <hui0787411@163.com>
  • Loading branch information
xyz-li authored and joestringer committed Apr 3, 2024
1 parent 0a79dbd commit ecf6ff1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkg/maps/lbmap/ipv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ func (k *Service4Key) String() string {
if kHost.Scope == loadbalancer.ScopeInternal {
addr += "/i"
}
addr = fmt.Sprintf("%s (%d)", addr, kHost.BackendSlot)
return addr
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/maps/lbmap/ipv6.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ func NewService6Key(ip net.IP, port uint16, proto u8proto.U8proto, scope uint8,
func (k *Service6Key) String() string {
kHost := k.ToHost().(*Service6Key)
if kHost.Scope == loadbalancer.ScopeInternal {
return fmt.Sprintf("[%s]:%d/i", kHost.Address, kHost.Port)
return fmt.Sprintf("[%s]:%d/i (%d)", kHost.Address, kHost.Port, kHost.BackendSlot)
} else {
return fmt.Sprintf("[%s]:%d", kHost.Address, kHost.Port)
return fmt.Sprintf("[%s]:%d (%d)", kHost.Address, kHost.Port, kHost.BackendSlot)
}
}

Expand Down
31 changes: 28 additions & 3 deletions test/helpers/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1894,8 +1894,7 @@ func (kub *Kubectl) validateServicePlumbingInCiliumPod(fullName, ciliumPod strin
return fmt.Errorf("unable to validate cilium service by running '%s': %s", cmd, res.OutputPrettyPrint())
}

var lbMap map[string][]string
err = res.Unmarshal(&lbMap)
lbMap, err := parseLBList(res)
if err != nil {
return fmt.Errorf("unable to unmarshal cilium bpf lb list output: %s", err)
}
Expand Down Expand Up @@ -4013,16 +4012,42 @@ func (kub *Kubectl) fillServiceCache() error {
return err
}

err = ciliumLbRes.Unmarshal(&podCache.loadBalancers)
lbMap, err := parseLBList(ciliumLbRes)
if err != nil {
return fmt.Errorf("Unable to unmarshal Cilium bpf lb list: %s", err.Error())
}

podCache.loadBalancers = lbMap
cache.pods = append(cache.pods, podCache)
}
kub.serviceCache = &cache
return nil
}

func parseLBList(res *CmdRes) (map[string][]string, error) {
var resMap map[string][]string
err := res.Unmarshal(&resMap)
if err != nil {
return nil, err
}
// A service for example:
// 10.96.0.10:9153 (1) 10.0.1.251:9153 (7) (1)
// 172.18.0.4:32686/i (1) 10.0.0.179:69 (32) (1)
lbMap := make(map[string][]string)
for frontend, backends := range resMap {
// strip the space and parentheses
index := strings.Index(frontend, " ")
if index > 0 {
frontend = frontend[:index]
}
if len(backends) > 0 {
lbMap[frontend] = append(lbMap[frontend], backends...)
}
}

return lbMap, nil
}

// KubeDNSPreFlightCheck makes sure that kube-dns is plumbed into Cilium.
func (kub *Kubectl) KubeDNSPreFlightCheck() error {
var dnsErr error
Expand Down

0 comments on commit ecf6ff1

Please sign in to comment.