Skip to content

Commit

Permalink
[YUNIKORN-2966] Not all tags are created for foreign allocations (#936)
Browse files Browse the repository at this point in the history
Closes: #936

Signed-off-by: Craig Condit <[email protected]>
  • Loading branch information
pbacsko authored and craigcondit committed Nov 8, 2024
1 parent 412d337 commit 52bef67
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
9 changes: 6 additions & 3 deletions pkg/cache/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,10 @@ func assertAddForeignPod(t *testing.T, podName, host string, allocRequest *si.Al
t.Helper()
assert.Equal(t, 1, len(allocRequest.Allocations))
tags := allocRequest.Allocations[0].AllocationTags
assert.Equal(t, 2, len(tags))
assert.Equal(t, 4, len(tags))
assert.Equal(t, siCommon.AllocTypeDefault, tags[siCommon.Foreign])
assert.Equal(t, tags["kubernetes.io/meta/namespace"], "testNamespace")
assert.Equal(t, tags["kubernetes.io/meta/podName"], podName)
assert.Equal(t, podName, allocRequest.Allocations[0].AllocationKey)
assert.Equal(t, host, allocRequest.Allocations[0].NodeID)
}
Expand Down Expand Up @@ -2390,8 +2392,9 @@ func foreignPod(podName, memory, cpu string) *v1.Pod {
APIVersion: "v1",
},
ObjectMeta: apis.ObjectMeta{
Name: podName,
UID: types.UID(podName),
Name: podName,
UID: types.UID(podName),
Namespace: "testNamespace",
},
Spec: v1.PodSpec{
Containers: containers,
Expand Down
9 changes: 4 additions & 5 deletions pkg/common/si_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,17 @@ func CreateAllocationForForeignPod(pod *v1.Pod) *si.AllocationRequest {
}
}

tags := CreateTagsForTask(pod)
tags[common.Foreign] = podType
tags[common.CreationTime] = strconv.FormatInt(pod.CreationTimestamp.Unix(), 10)
allocation := si.Allocation{
AllocationTags: map[string]string{
common.Foreign: podType,
},
AllocationTags: tags,
AllocationKey: string(pod.UID),
ResourcePerAlloc: GetPodResource(pod),
Priority: CreatePriorityForTask(pod),
NodeID: pod.Spec.NodeName,
}

allocation.AllocationTags[common.CreationTime] = strconv.FormatInt(pod.CreationTimestamp.Unix(), 10)

return &si.AllocationRequest{
Allocations: []*si.Allocation{&allocation},
RmID: conf.GetSchedulerConf().ClusterID,
Expand Down
12 changes: 9 additions & 3 deletions pkg/common/si_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@ func TestCreateAllocationForForeignPod(t *testing.T) {
CreationTimestamp: apis.Time{
Time: time.Unix(1, 0),
},
Labels: map[string]string{
"testKey": "testValue",
},
Namespace: "testNamespace",
},
Spec: v1.PodSpec{
Containers: containers,
Expand All @@ -459,9 +463,11 @@ func TestCreateAllocationForForeignPod(t *testing.T) {
assert.Equal(t, int64(500000000), res.Resources["memory"].Value)
assert.Equal(t, int64(1000), res.Resources["vcore"].Value)
assert.Equal(t, int64(1), res.Resources["pods"].Value)
assert.Equal(t, 2, len(alloc.AllocationTags))
assert.Equal(t, 5, len(alloc.AllocationTags))
assert.Equal(t, "1", alloc.AllocationTags[common.CreationTime])
assert.Equal(t, common.AllocTypeDefault, alloc.AllocationTags[common.Foreign])
assert.Equal(t, alloc.AllocationTags["kubernetes.io/meta/namespace"], "testNamespace")
assert.Equal(t, alloc.AllocationTags["kubernetes.io/meta/podName"], "test")
assert.Equal(t, alloc.AllocationTags["kubernetes.io/label/testKey"], "testValue")

// set priority & change pod type to static
prio := int32(12)
Expand All @@ -472,7 +478,7 @@ func TestCreateAllocationForForeignPod(t *testing.T) {
},
}
allocReq = CreateAllocationForForeignPod(pod)
assert.Equal(t, 2, len(alloc.AllocationTags))
assert.Equal(t, 5, len(alloc.AllocationTags))
alloc = allocReq.Allocations[0]
assert.Equal(t, common.AllocTypeStatic, alloc.AllocationTags[common.Foreign])
assert.Equal(t, int32(12), alloc.Priority)
Expand Down

0 comments on commit 52bef67

Please sign in to comment.