Skip to content

Commit

Permalink
Merge pull request #525 from DataDog/jared.ledvina/cherry-pick-large-…
Browse files Browse the repository at this point in the history
…service-1-12

service: Improve memory usage when handling update of a big service.
  • Loading branch information
jaredledvina authored Sep 28, 2023
2 parents 6d8930c + 93f76f7 commit d67a85e
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 152 deletions.
8 changes: 4 additions & 4 deletions daemon/cmd/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ func (h *putServiceID) Handle(params PutServiceIDParams) middleware.Responder {
if !params.Config.UpdateServices {
return api.Error(PutServiceIDFailureCode, fmt.Errorf("invalid service ID 0"))
}
backends := []loadbalancer.Backend{}
backends := []*loadbalancer.Backend{}
for _, v := range params.Config.BackendAddresses {
b, err := loadbalancer.NewBackendFromBackendModel(v)
if err != nil {
return api.Error(PutServiceIDInvalidBackendCode, err)
}
backends = append(backends, *b)
backends = append(backends, b)
}
if err := h.svc.UpdateBackendsState(backends); err != nil {
return api.Error(PutServiceIDUpdateBackendFailureCode, err)
Expand All @@ -54,13 +54,13 @@ func (h *putServiceID) Handle(params PutServiceIDParams) middleware.Responder {
L3n4Addr: *f,
ID: loadbalancer.ID(params.Config.ID),
}
backends := []loadbalancer.Backend{}
backends := []*loadbalancer.Backend{}
for _, v := range params.Config.BackendAddresses {
b, err := loadbalancer.NewBackendFromBackendModel(v)
if err != nil {
return api.Error(PutServiceIDInvalidBackendCode, err)
}
backends = append(backends, *b)
backends = append(backends, b)
}

var svcType loadbalancer.SVCType
Expand Down
2 changes: 1 addition & 1 deletion pkg/envoy/ciliumenvoyconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ func (s *XDSServer) DeleteEnvoyResources(ctx context.Context, resources Resource
return nil
}

func (s *XDSServer) UpsertEnvoyEndpoints(serviceName service.Name, backendMap map[string][]lb.Backend) error {
func (s *XDSServer) UpsertEnvoyEndpoints(serviceName service.Name, backendMap map[string][]*lb.Backend) error {
var resources Resources
lbEndpoints := []*envoy_config_endpoint.LbEndpoint{}
for port, bes := range backendMap {
Expand Down
12 changes: 6 additions & 6 deletions pkg/k8s/watchers/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ func (k *K8sWatcher) genServiceMappings(pod *slim_corev1.Pod, podIPs []string, l
continue
}

var bes4 []loadbalancer.Backend
var bes6 []loadbalancer.Backend
var bes4 []*loadbalancer.Backend
var bes6 []*loadbalancer.Backend

for _, podIP := range podIPs {
be := loadbalancer.Backend{
Expand All @@ -522,9 +522,9 @@ func (k *K8sWatcher) genServiceMappings(pod *slim_corev1.Pod, podIPs []string, l
},
}
if be.L3n4Addr.IP.To4() != nil {
bes4 = append(bes4, be)
bes4 = append(bes4, &be)
} else {
bes6 = append(bes6, be)
bes6 = append(bes6, &be)
}
}

Expand Down Expand Up @@ -869,8 +869,8 @@ func (k *K8sWatcher) deletePodHostData(pod *slim_corev1.Pod) (bool, error) {
// agent flag `option.Config.K8sEventHandover` this function might only return
// local pods.
// If `option.Config.K8sEventHandover` is:
// - true: returns only local pods received by the pod watcher.
// - false: returns any pod in the cluster received by the pod watcher.
// - true: returns only local pods received by the pod watcher.
// - false: returns any pod in the cluster received by the pod watcher.
func (k *K8sWatcher) GetCachedPod(namespace, name string) (*slim_corev1.Pod, error) {
<-k.controllersStarted
k.WaitForCacheSync(resources.K8sAPIGroupPodV1Core)
Expand Down
4 changes: 2 additions & 2 deletions pkg/k8s/watchers/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ func genCartesianProduct(
feFamilyIPv6 := ip.IsIPv6(fe)

for fePortName, fePort := range ports {
var besValues []loadbalancer.Backend
var besValues []*loadbalancer.Backend
for netIP, backend := range bes.Backends {
parsedIP := net.ParseIP(netIP)

Expand All @@ -738,7 +738,7 @@ func genCartesianProduct(
if backend.Terminating {
backendState = loadbalancer.BackendStateTerminating
}
besValues = append(besValues, loadbalancer.Backend{
besValues = append(besValues, &loadbalancer.Backend{
FEPortName: string(fePortName),
NodeName: backend.NodeName,
L3n4Addr: loadbalancer.L3n4Addr{
Expand Down
Loading

0 comments on commit d67a85e

Please sign in to comment.