Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

daemon: add BackendSlot to Service6Key.String and Service4Key.String #29581

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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