Skip to content

Commit

Permalink
feat: add topology spread on game rooms
Browse files Browse the repository at this point in the history
Add to Game Room pod spec the topology spread constraint with a
maxSkew based on zone. If not match, we schedule anyway.
  • Loading branch information
hspedro committed Sep 18, 2024
1 parent b2ca233 commit b65f7c0
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/adapters/runtime/kubernetes/game_room_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ func convertGameRoomSpec(scheduler entities.Scheduler, gameRoomName string, game
Containers: []v1.Container{},
Tolerations: convertSpecTolerations(gameRoomSpec),
Affinity: convertSpecAffinity(gameRoomSpec),
TopologySpreadConstraints: []v1.TopologySpreadConstraint{
{
MaxSkew: 1,
TopologyKey: "topology.kubernetes.io/zone",
WhenUnsatisfiable: v1.ScheduleAnyway,
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
schedulerLabelKey: scheduler.Name,
},
},
},
},
},
}
for _, container := range gameRoomSpec.Containers {
Expand Down
86 changes: 86 additions & 0 deletions internal/adapters/runtime/kubernetes/game_room_convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,20 @@ func TestConvertGameSpec(t *testing.T) {
safeToEvictAnnotation: safeToEvictValue,
},
},
Spec: v1.PodSpec{
TopologySpreadConstraints: []v1.TopologySpreadConstraint{
{
MaxSkew: 1,
TopologyKey: "topology.kubernetes.io/zone",
WhenUnsatisfiable: v1.ScheduleAnyway,
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
schedulerLabelKey: "sample",
},
},
},
},
},
},
},
"with containers": {
Expand Down Expand Up @@ -432,6 +446,18 @@ func TestConvertGameSpec(t *testing.T) {
{},
{},
},
TopologySpreadConstraints: []v1.TopologySpreadConstraint{
{
MaxSkew: 1,
TopologyKey: "topology.kubernetes.io/zone",
WhenUnsatisfiable: v1.ScheduleAnyway,
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
schedulerLabelKey: "sample",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -461,6 +487,18 @@ func TestConvertGameSpec(t *testing.T) {
Tolerations: []v1.Toleration{
{},
},
TopologySpreadConstraints: []v1.TopologySpreadConstraint{
{
MaxSkew: 1,
TopologyKey: "topology.kubernetes.io/zone",
WhenUnsatisfiable: v1.ScheduleAnyway,
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
schedulerLabelKey: "sample",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -488,6 +526,18 @@ func TestConvertGameSpec(t *testing.T) {
},
Spec: v1.PodSpec{
Affinity: &v1.Affinity{},
TopologySpreadConstraints: []v1.TopologySpreadConstraint{
{
MaxSkew: 1,
TopologyKey: "topology.kubernetes.io/zone",
WhenUnsatisfiable: v1.ScheduleAnyway,
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
schedulerLabelKey: "sample",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -519,6 +569,18 @@ func TestConvertGameSpec(t *testing.T) {
},
Spec: v1.PodSpec{
Affinity: &v1.Affinity{},
TopologySpreadConstraints: []v1.TopologySpreadConstraint{
{
MaxSkew: 1,
TopologyKey: "topology.kubernetes.io/zone",
WhenUnsatisfiable: v1.ScheduleAnyway,
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
schedulerLabelKey: "sample",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -550,6 +612,18 @@ func TestConvertGameSpec(t *testing.T) {
},
Spec: v1.PodSpec{
Affinity: &v1.Affinity{},
TopologySpreadConstraints: []v1.TopologySpreadConstraint{
{
MaxSkew: 1,
TopologyKey: "topology.kubernetes.io/zone",
WhenUnsatisfiable: v1.ScheduleAnyway,
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
schedulerLabelKey: "sample",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -577,6 +651,18 @@ func TestConvertGameSpec(t *testing.T) {
},
Spec: v1.PodSpec{
TerminationGracePeriodSeconds: int64Pointer(10),
TopologySpreadConstraints: []v1.TopologySpreadConstraint{
{
MaxSkew: 1,
TopologyKey: "topology.kubernetes.io/zone",
WhenUnsatisfiable: v1.ScheduleAnyway,
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
schedulerLabelKey: "sample",
},
},
},
},
},
},
},
Expand Down

0 comments on commit b65f7c0

Please sign in to comment.