-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from G-Research/executor-allocation
Refactoring JobLeaseService and ClusterUtilisationService
- Loading branch information
Showing
14 changed files
with
574 additions
and
389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package service | ||
|
||
import ( | ||
"fmt" | ||
"github.com/G-Research/k8s-batch/internal/executor/submitter" | ||
) | ||
|
||
type ClusterAllocationService struct { | ||
LeaseService JobLeaseService | ||
UtilisationService ClusterUtilisationService | ||
JobSubmitter submitter.JobSubmitter | ||
} | ||
|
||
func (allocationService ClusterAllocationService) AllocateSpareClusterCapacity() { | ||
availableResource := allocationService.UtilisationService.GetAvailableClusterCapacity() | ||
|
||
newJobs, err := allocationService.LeaseService.RequestJobLeases(availableResource) | ||
|
||
if err != nil { | ||
fmt.Printf("Failed to lease new jobs because %s \n", err) | ||
} else { | ||
for _, job := range newJobs { | ||
_, err = allocationService.JobSubmitter.SubmitJob(job) | ||
if err != nil { | ||
fmt.Printf("Failed to submit job %s because %s \n", job.Id, err) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
internal/executor/service/cluster_utilisation_service_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package service | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"testing" | ||
) | ||
|
||
func TestFilterAvailableProcessingNodes_ShouldReturnAvailableProcessingNodes(t *testing.T) { | ||
node := v1.Node{ | ||
Spec: v1.NodeSpec{ | ||
Unschedulable: false, | ||
Taints: nil, | ||
}, | ||
} | ||
|
||
nodes := []*v1.Node{&node} | ||
result := filterAvailableProcessingNodes(nodes) | ||
|
||
assert.Equal(t, len(result), 1) | ||
} | ||
|
||
func TestFilterAvailableProcessingNodes_ShouldFilterUnschedulableNodes(t *testing.T) { | ||
node := v1.Node{ | ||
Spec: v1.NodeSpec{ | ||
Unschedulable: true, | ||
Taints: nil, | ||
}, | ||
} | ||
|
||
nodes := []*v1.Node{&node} | ||
result := filterAvailableProcessingNodes(nodes) | ||
|
||
assert.Equal(t, len(result), 0) | ||
} | ||
|
||
func TestFilterAvailableProcessingNodes_ShouldFilterNodesWithNoScheduleTaint(t *testing.T) { | ||
taint := v1.Taint{ | ||
Effect: v1.TaintEffectNoSchedule, | ||
} | ||
node := v1.Node{ | ||
Spec: v1.NodeSpec{ | ||
Unschedulable: false, | ||
Taints: []v1.Taint{taint}, | ||
}, | ||
} | ||
|
||
nodes := []*v1.Node{&node} | ||
result := filterAvailableProcessingNodes(nodes) | ||
|
||
assert.Equal(t, len(result), 0) | ||
} | ||
|
||
func TestGetAllPodsOnNodes_ShouldExcludePodsNoOnGivenNodes(t *testing.T) { | ||
presentNodeName := "Node1" | ||
podOnNode := v1.Pod{ | ||
Spec: v1.PodSpec{ | ||
NodeName: presentNodeName, | ||
}, | ||
} | ||
podNotOnNode := v1.Pod{ | ||
Spec: v1.PodSpec{ | ||
NodeName: "Node2", | ||
}, | ||
} | ||
|
||
node := v1.Node{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: presentNodeName, | ||
}, | ||
} | ||
pods := []*v1.Pod{&podOnNode, &podNotOnNode} | ||
nodes := []*v1.Node{&node} | ||
|
||
result := getAllPodsOnNodes(pods, nodes) | ||
|
||
assert.Equal(t, len(result), 1) | ||
assert.Equal(t, result[0].Spec.NodeName, presentNodeName) | ||
} | ||
|
||
func TestGetAllPodsOnNodes_ShouldHandleNoNodesProvided(t *testing.T) { | ||
podOnNode := v1.Pod{ | ||
Spec: v1.PodSpec{ | ||
NodeName: "Node1", | ||
}, | ||
} | ||
|
||
pods := []*v1.Pod{&podOnNode} | ||
var nodes []*v1.Node | ||
|
||
result := getAllPodsOnNodes(pods, nodes) | ||
|
||
assert.Equal(t, len(result), 0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.