Skip to content

Commit

Permalink
topology-aware: reconfigure implicit affinities.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
klihub committed Nov 7, 2024
1 parent 438a917 commit 619e7dd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
19 changes: 14 additions & 5 deletions cmd/plugins/topology-aware/policy/affinity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
8 changes: 7 additions & 1 deletion cmd/plugins/topology-aware/policy/topology-aware-policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ func (p *policy) Setup(opts *policyapi.BackendOptions) error {
return policyError("failed to initialize %s policy: %w", PolicyName, err)
}

p.registerImplicitAffinities()
if err := p.registerImplicitAffinities(); err != nil {
return policyError("failed to initialize %s policy: %w", PolicyName, err)
}

log.Info("***** default CPU priority is %s", defaultPrio)

Expand Down Expand Up @@ -484,6 +486,10 @@ func (p *policy) Reconfigure(newCfg interface{}) error {
return policyError("failed to reconfigure: %v", err)
}

if err := p.registerImplicitAffinities(); err != nil {
return policyError("failed to reconfigure: %v", err)
}

for _, grant := range allocations.grants {
if err := grant.RefetchNodes(); err != nil {
*p = savedPolicy
Expand Down

0 comments on commit 619e7dd

Please sign in to comment.