forked from aws/karpenter-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
194 additions
and
41 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
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
69 changes: 69 additions & 0 deletions
69
pkg/controllers/provisioner/v1alpha1/allocation/greedyallocator.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,69 @@ | ||
/* | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package allocation | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/awslabs/karpenter/pkg/cloudprovider" | ||
v1 "k8s.io/api/core/v1" | ||
) | ||
|
||
var _ Allocator = &GreedyAllocator{} | ||
|
||
// GreedyAllocator iteratively assigns pods to scheduling groups and then creates capacity for each group. | ||
type GreedyAllocator struct { | ||
Capacity cloudprovider.Capacity | ||
} | ||
|
||
// | ||
func (a *GreedyAllocator) Allocate(pods []*v1.Pod) error { | ||
// 1. Separate pods into scheduling groups | ||
groups := a.getSchedulingGroups(pods) | ||
|
||
// 2. Group pods into equally schedulable constraint group | ||
for _, group := range groups { | ||
if err := a.Capacity.Create(context.TODO(), group.Constraints); err != nil { | ||
return fmt.Errorf("while creating capacity with constraints %v, %w", group.Constraints, err) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
type SchedulingGroup struct { | ||
Pods []*v1.Pod | ||
Constraints cloudprovider.CapacityConstraints | ||
} | ||
|
||
func (a *GreedyAllocator) getSchedulingGroups(pods []*v1.Pod) []SchedulingGroup { | ||
groups := []SchedulingGroup{} | ||
|
||
for _, pod := range pods { | ||
for _, group := range groups { | ||
if a.matchesGroup(pod, group) { | ||
group.Pods = append(group.Pods, pod) | ||
break | ||
} | ||
} | ||
} | ||
|
||
return groups | ||
} | ||
|
||
// TODO | ||
func (a *GreedyAllocator) matchesGroup(pod *v1.Pod, group SchedulingGroup) bool { | ||
return true | ||
} |
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,22 @@ | ||
/* | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package allocation | ||
|
||
import v1 "k8s.io/api/core/v1" | ||
|
||
// Allocator allocates new capacity for a set of pods | ||
type Allocator interface { | ||
Allocate([]*v1.Pod) error | ||
} |
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
25 changes: 25 additions & 0 deletions
25
pkg/controllers/provisioner/v1alpha1/reallocation/types.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,25 @@ | ||
/* | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package reallocation | ||
|
||
import v1 "k8s.io/api/core/v1" | ||
|
||
// Reallocator evicts scheduled pods in favor of incoming pods. | ||
type Reallocator interface { | ||
// Reallocate takes a set of incoming pods and identifies existing pods that | ||
// could be replaced by incoming pods. Returns incoming pods that did not | ||
// result in a better fit. | ||
Reallocate([]*v1.Pod) ([]*v1.Pod, error) | ||
} |
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,23 @@ | ||
/* | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package scheduling | ||
|
||
import v1 "k8s.io/api/core/v1" | ||
|
||
// Scheduler assigns incoming pods to existing nodes. | ||
type Scheduler interface { | ||
// Schedule a set of pods on existing nodes. | ||
Schedule() ([]*v1.Pod, error) | ||
} |