From b37c170eb2fa5a739868859fc94b97a0817201a7 Mon Sep 17 00:00:00 2001 From: Krisztian Litkey Date: Sun, 3 Nov 2024 16:54:29 +0200 Subject: [PATCH] topology-aware: reconfigure implicit affinities. Fix the handling of implicit affinities corresponding to the colocate{Pods,Namespaces} configuration settings. Unregister and reregister disabled and enabled implicit affinities as necessary when we receive a new configuration. Signed-off-by: Krisztian Litkey --- cmd/plugins/topology-aware/policy/affinity.go | 19 ++++++++++++++----- .../policy/topology-aware-policy.go | 2 ++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/cmd/plugins/topology-aware/policy/affinity.go b/cmd/plugins/topology-aware/policy/affinity.go index 21c38309d..5cba1eb39 100644 --- a/cmd/plugins/topology-aware/policy/affinity.go +++ b/cmd/plugins/topology-aware/policy/affinity.go @@ -119,16 +119,25 @@ func (p *policy) registerImplicitAffinities() error { }, } - enabled := map[string]cache.ImplicitAffinity{} + var ( + add = map[string]cache.ImplicitAffinity{} + del = []string{} + ) + for _, a := range affinities { - if a.disabled { + name := PolicyName + ":" + a.name + del = append(del, name) + + if !a.disabled { + log.Info("implicit affinity %s is enabled", a.name) + add[name] = a.affinity + } else { log.Info("implicit affinity %s is disabled", a.name) - continue } - enabled[PolicyName+":"+a.name] = a.affinity } - if err := p.cache.AddImplicitAffinities(enabled); err != nil { + p.cache.DeleteImplicitAffinities(del...) + if err := p.cache.AddImplicitAffinities(add); err != nil { return policyError("failed to register implicit affinities: %v", err) } diff --git a/cmd/plugins/topology-aware/policy/topology-aware-policy.go b/cmd/plugins/topology-aware/policy/topology-aware-policy.go index 687ab63f8..f3012aac0 100644 --- a/cmd/plugins/topology-aware/policy/topology-aware-policy.go +++ b/cmd/plugins/topology-aware/policy/topology-aware-policy.go @@ -484,6 +484,8 @@ func (p *policy) Reconfigure(newCfg interface{}) error { return policyError("failed to reconfigure: %v", err) } + p.registerImplicitAffinities() + for _, grant := range allocations.grants { if err := grant.RefetchNodes(); err != nil { *p = savedPolicy