move helper funcs to util/deployment.go from util.go

This commit is contained in:
mqliang
2016-02-11 14:19:31 +08:00
parent b1dedc0900
commit d96cdb93c4
3 changed files with 27 additions and 31 deletions

View File

@@ -18,35 +18,11 @@ package util
import (
"fmt"
"math"
"os"
"reflect"
"regexp"
"strconv"
"strings"
"k8s.io/kubernetes/pkg/util/intstr"
)
func GetIntOrPercentValue(intOrStr *intstr.IntOrString) (int, bool, error) {
switch intOrStr.Type {
case intstr.Int:
return intOrStr.IntValue(), false, nil
case intstr.String:
s := strings.Replace(intOrStr.StrVal, "%", "", -1)
v, err := strconv.Atoi(s)
if err != nil {
return 0, false, fmt.Errorf("invalid value %q: %v", intOrStr.StrVal, err)
}
return int(v), true, nil
}
return 0, false, fmt.Errorf("invalid value: neither int nor percentage")
}
func GetValueFromPercent(percent int, value int) int {
return int(math.Ceil(float64(percent) * (float64(value)) / 100))
}
// Takes a list of strings and compiles them into a list of regular expressions
func CompileRegexps(regexpStrings []string) ([]*regexp.Regexp, error) {
regexps := []*regexp.Regexp{}