Skip to content

Commit

Permalink
perf: improve scheduling with large numbers of nodes using hostname t…
Browse files Browse the repository at this point in the history
…opologies (#958)
  • Loading branch information
tzneal authored Jan 24, 2024
1 parent fb05378 commit eb8040d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/controllers/provisioning/scheduling/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"sigs.k8s.io/karpenter/pkg/controllers/state"
"sigs.k8s.io/karpenter/pkg/scheduling"
"sigs.k8s.io/karpenter/pkg/utils/functional"
"sigs.k8s.io/karpenter/pkg/utils/pretty"

"k8s.io/apimachinery/pkg/api/errors"

Expand Down Expand Up @@ -164,7 +165,7 @@ func (t *Topology) AddRequirements(podRequirements, nodeRequirements scheduling.
}
domains := topology.Get(p, podDomains, nodeDomains)
if domains.Len() == 0 {
return nil, fmt.Errorf("unsatisfiable topology constraint for %s, key=%s (counts = %v, podDomains = %v, nodeDomains = %v)", topology.Type, topology.Key, topology.domains, podDomains, nodeDomains)
return nil, fmt.Errorf("unsatisfiable topology constraint for %s, key=%s (counts = %s, podDomains = %v, nodeDomains = %v", topology.Type, topology.Key, pretty.Map(topology.domains, 5), podDomains, nodeDomains)
}
requirements.Add(domains)
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/utils/pretty/pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package pretty

import (
"bytes"
"encoding/json"
"fmt"
"strings"
Expand Down Expand Up @@ -45,3 +46,19 @@ func Slice[T any](s []T, maxItems int) string {
}
return sb.String()
}

// Map truncates a map after a certain number of max items to ensure that the
// description in a log doesn't get too long
func Map[K comparable, V any](values map[K]V, maxItems int) string {
var buf bytes.Buffer
for k, v := range values {
fmt.Fprintf(&buf, "%v: %v ", k, v)
if buf.Len() > maxItems {
break
}
}
if maxItems < buf.Len() {
fmt.Fprintf(&buf, "and %d other(s)", buf.Len()-maxItems)
}
return buf.String()
}

0 comments on commit eb8040d

Please sign in to comment.