Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YUNIKORN-2966] Not all tags are created for foreign allocations #936

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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