This repository was archived by the owner on Apr 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Cluster-autoscaler: Utils + more scale up flow #820
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,107 @@ | ||
| /* | ||
| Copyright 2016 The Kubernetes Authors All rights reserved. | ||
|
|
||
| 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 main | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| kube_api "k8s.io/kubernetes/pkg/api" | ||
| "k8s.io/kubernetes/pkg/client/cache" | ||
| kube_client "k8s.io/kubernetes/pkg/client/unversioned" | ||
| "k8s.io/kubernetes/pkg/fields" | ||
| "k8s.io/kubernetes/pkg/labels" | ||
| ) | ||
|
|
||
| // UnscheduledPodLister list unscheduled pods | ||
| type UnscheduledPodLister struct { | ||
| podLister *cache.StoreToPodLister | ||
| } | ||
|
|
||
| // List returns all unscheduled pods. | ||
| func (unscheduledPodLister *UnscheduledPodLister) List() ([]*kube_api.Pod, error) { | ||
| //TODO: Extra filter based on pod condition. | ||
| return unscheduledPodLister.podLister.List(labels.Everything()) | ||
| } | ||
|
|
||
| // NewUnscheduledPodLister returns a lister providing pods that failed to be scheduled. | ||
| func NewUnscheduledPodLister(kubeClient *kube_client.Client) *UnscheduledPodLister { | ||
| // watch unscheduled pods | ||
| selector := fields.ParseSelectorOrDie("spec.nodeName==" + "" + ",status.phase!=" + | ||
| string(kube_api.PodSucceeded) + ",status.phase!=" + string(kube_api.PodFailed)) | ||
| podListWatch := cache.NewListWatchFromClient(kubeClient, "pods", kube_api.NamespaceAll, selector) | ||
| podLister := &cache.StoreToPodLister{Store: cache.NewStore(cache.MetaNamespaceKeyFunc)} | ||
| podReflector := cache.NewReflector(podListWatch, &kube_api.Pod{}, podLister.Store, time.Hour) | ||
| podReflector.Run() | ||
|
|
||
| return &UnscheduledPodLister{ | ||
| podLister: podLister, | ||
| } | ||
| } | ||
|
|
||
| // ReadyNodeLister lists ready nodes. | ||
| type ReadyNodeLister struct { | ||
| nodeLister *cache.StoreToNodeLister | ||
| } | ||
|
|
||
| // List returns ready nodes. | ||
| func (readyNodeLister *ReadyNodeLister) List() ([]kube_api.Node, error) { | ||
| nodes, err := readyNodeLister.nodeLister.List() | ||
| if err != nil { | ||
| return []kube_api.Node{}, err | ||
| } | ||
| readyNodes := make([]kube_api.Node, 0, len(nodes.Items)) | ||
| for _, node := range nodes.Items { | ||
| for _, condition := range node.Status.Conditions { | ||
| if condition.Type == kube_api.NodeReady && condition.Status == kube_api.ConditionTrue { | ||
| readyNodes = append(readyNodes, node) | ||
| break | ||
| } | ||
| } | ||
| } | ||
| return readyNodes, nil | ||
| } | ||
|
|
||
| // NewNodeLister builds a node lister. | ||
| func NewNodeLister(kubeClient *kube_client.Client) *ReadyNodeLister { | ||
| listWatcher := cache.NewListWatchFromClient(kubeClient, "nodes", kube_api.NamespaceAll, fields.Everything()) | ||
| nodeLister := &cache.StoreToNodeLister{Store: cache.NewStore(cache.MetaNamespaceKeyFunc)} | ||
| reflector := cache.NewReflector(listWatcher, &kube_api.Node{}, nodeLister.Store, time.Hour) | ||
| reflector.Run() | ||
| return &ReadyNodeLister{ | ||
| nodeLister: nodeLister, | ||
| } | ||
| } | ||
|
|
||
| // GetNewestNode returns the newest node from the given list. | ||
| func GetNewestNode(nodes []kube_api.Node) *kube_api.Node { | ||
| var result *kube_api.Node | ||
| for i, node := range nodes { | ||
| if result == nil || node.CreationTimestamp.After(result.CreationTimestamp.Time) { | ||
| result = &(nodes[i]) | ||
| } | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| // GetOldestFailedSchedulingTrail returns the oldest time when a pod from the given list failed to | ||
| // be scheduled. | ||
| func GetOldestFailedSchedulingTrail(pods []*kube_api.Pod) *time.Time { | ||
| // Dummy implementation. | ||
| //TODO: Implement once pod condition is there. | ||
| now := time.Now() | ||
| return &now | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think it's enough to list pods in phase
PendingThere 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.
This is how k8s scheduler does 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.
As discussed offline I believe we don't need to have the same options here, but I won't insist.