-
Notifications
You must be signed in to change notification settings - Fork 989
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
Provisioner skeleton code #203
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
} |
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 | ||
} |
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) | ||
} |
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be taking a slice of pods as an argument? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call yeah. For now, this is a no-op since we're skipping scheduling. Happy to fix, or we can clean up next time someone touches it. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be we can do this later, but wait for few seconds for a pod to be in pending state.
Let's add a comment for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what the difference is here. If the pod is unschedulable, it means the scheduler failed right? Is there a step I'm missing?