Skip to content

Commit

Permalink
TAS: Clean up TAS flavor snapshot (#3592)
Browse files Browse the repository at this point in the history
* [WIP] Clean up TAS flavor snapshot, delete sort name, delete domainID refrences, optimize memory, improve code clarity

* Add comments

* Fix typo, rename nodes -> domains

* gst

* Fix bug, add unit test
  • Loading branch information
PBundyra authored Nov 20, 2024
1 parent 4551e39 commit 0b0b003
Show file tree
Hide file tree
Showing 3 changed files with 360 additions and 119 deletions.
237 changes: 237 additions & 0 deletions pkg/cache/tas_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ func TestFindTopologyAssignment(t *testing.T) {
tasHostLabel = "kubernetes.io/hostname"
)

// b1 b2
// / \ / \
// r1 r2 r1 r2
// | / | \ | |
// x1 x2 x3 x4 x5 x6
defaultNodes := []corev1.Node{
{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -188,6 +193,190 @@ func TestFindTopologyAssignment(t *testing.T) {
tasHostLabel,
}

// b1 b2
// / \ / \
// r1 r2 r1 r2
// / \ / \ / \ / \
// x1 x2 x3 x4 x5 x6 x7 x6
binaryTreesNodes := []corev1.Node{
{
ObjectMeta: metav1.ObjectMeta{
Name: "b1-r1-x1",
Labels: map[string]string{
tasBlockLabel: "b1",
tasRackLabel: "r1",
tasHostLabel: "x1",
},
},
Status: corev1.NodeStatus{
Allocatable: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("1Gi"),
},
Conditions: []corev1.NodeCondition{
{
Type: corev1.NodeReady,
Status: corev1.ConditionTrue,
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "b1-r1-x2",
Labels: map[string]string{
tasBlockLabel: "b1",
tasRackLabel: "r1",
tasHostLabel: "x2",
},
},
Status: corev1.NodeStatus{
Allocatable: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("1Gi"),
},
Conditions: []corev1.NodeCondition{
{
Type: corev1.NodeReady,
Status: corev1.ConditionTrue,
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "b1-r2-x3",
Labels: map[string]string{
tasBlockLabel: "b1",
tasRackLabel: "r2",
tasHostLabel: "x3",
},
},
Status: corev1.NodeStatus{
Allocatable: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("1Gi"),
},
Conditions: []corev1.NodeCondition{
{
Type: corev1.NodeReady,
Status: corev1.ConditionTrue,
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "b1-r2-x4",
Labels: map[string]string{
tasBlockLabel: "b1",
tasRackLabel: "r2",
tasHostLabel: "x4",
},
},
Status: corev1.NodeStatus{
Allocatable: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("1Gi"),
},
Conditions: []corev1.NodeCondition{
{
Type: corev1.NodeReady,
Status: corev1.ConditionTrue,
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "b2-r1-x5",
Labels: map[string]string{
tasBlockLabel: "b2",
tasRackLabel: "r1",
tasHostLabel: "x5",
},
},
Status: corev1.NodeStatus{
Allocatable: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("1Gi"),
},
Conditions: []corev1.NodeCondition{
{
Type: corev1.NodeReady,
Status: corev1.ConditionTrue,
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "b2-r1-x6",
Labels: map[string]string{
tasBlockLabel: "b2",
tasRackLabel: "r1",
tasHostLabel: "x6",
},
},
Status: corev1.NodeStatus{
Allocatable: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("1Gi"),
},
Conditions: []corev1.NodeCondition{
{
Type: corev1.NodeReady,
Status: corev1.ConditionTrue,
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "b2-r2-x7",
Labels: map[string]string{
tasBlockLabel: "b2",
tasRackLabel: "r2",
tasHostLabel: "x7",
},
},
Status: corev1.NodeStatus{
Allocatable: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("1Gi"),
},
Conditions: []corev1.NodeCondition{
{
Type: corev1.NodeReady,
Status: corev1.ConditionTrue,
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "b2-r2-x8",
Labels: map[string]string{
tasBlockLabel: "b2",
tasRackLabel: "r2",
tasHostLabel: "x8",
},
},
Status: corev1.NodeStatus{
Allocatable: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("1Gi"),
},
Conditions: []corev1.NodeCondition{
{
Type: corev1.NodeReady,
Status: corev1.ConditionTrue,
},
},
},
},
}

cases := map[string]struct {
request kueue.PodSetTopologyRequest
levels []string
Expand Down Expand Up @@ -383,6 +572,54 @@ func TestFindTopologyAssignment(t *testing.T) {
},
},
},
"block required; 4 pods fit into one host each": {
nodes: binaryTreesNodes,
request: kueue.PodSetTopologyRequest{
Required: ptr.To(tasBlockLabel),
},
levels: defaultThreeLevels,
requests: resources.Requests{
corev1.ResourceCPU: 1000,
},
count: 4,
wantAssignment: &kueue.TopologyAssignment{
Levels: defaultThreeLevels,
Domains: []kueue.TopologyDomainAssignment{
{
Count: 1,
Values: []string{
"b1",
"r1",
"x1",
},
},
{
Count: 1,
Values: []string{
"b1",
"r1",
"x2",
},
},
{
Count: 1,
Values: []string{
"b1",
"r2",
"x3",
},
},
{
Count: 1,
Values: []string{
"b1",
"r2",
"x4",
},
},
},
},
},
"host required; single Pod fits in the host": {
nodes: defaultNodes,
request: kueue.PodSetTopologyRequest{
Expand Down
3 changes: 1 addition & 2 deletions pkg/cache/tas_flavor.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ func (c *TASFlavorCache) snapshotForNodes(log logr.Logger, nodes []corev1.Node,
levelValues := utiltas.LevelValues(c.Levels, node.Labels)
capacity := resources.NewRequests(node.Status.Allocatable)
domainID := utiltas.DomainID(levelValues)
snapshot.levelValuesPerDomain[domainID] = levelValues
snapshot.addCapacity(domainID, capacity)
snapshot.addLeafDomain(levelValues, capacity, domainID)
nodeToDomain[node.Name] = domainID
}
snapshot.initialize()
Expand Down
Loading

0 comments on commit 0b0b003

Please sign in to comment.