Kubelet code move: volume / util

This commit is contained in:
Paul Morie
2016-08-22 16:38:36 -04:00
parent 45e557e237
commit b91ad76066
8 changed files with 243 additions and 208 deletions

View File

@@ -16,6 +16,11 @@ limitations under the License.
package sliceutils
import (
"k8s.io/kubernetes/pkg/api"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
)
func StringInSlice(s string, list []string) bool {
for _, v := range list {
if v == s {
@@ -25,3 +30,29 @@ func StringInSlice(s string, list []string) bool {
return false
}
// PodsByCreationTime makes an array of pods sortable by their creation
// timestamps in ascending order.
type PodsByCreationTime []*api.Pod
func (s PodsByCreationTime) Len() int {
return len(s)
}
func (s PodsByCreationTime) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s PodsByCreationTime) Less(i, j int) bool {
return s[i].CreationTimestamp.Before(s[j].CreationTimestamp)
}
// ByImageSize makes an array of images sortable by their size in descending
// order.
type ByImageSize []kubecontainer.Image
func (a ByImageSize) Less(i, j int) bool {
return a[i].Size > a[j].Size
}
func (a ByImageSize) Len() int { return len(a) }
func (a ByImageSize) Swap(i, j int) { a[i], a[j] = a[j], a[i] }