Commit 89e96910 authored by nikhiljindal's avatar nikhiljindal

Adding scale up/down code to DeploymentController

parent 9e5ed1dc
...@@ -22,6 +22,7 @@ import ( ...@@ -22,6 +22,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"math"
"net" "net"
"net/http" "net/http"
"os" "os"
...@@ -191,6 +192,25 @@ func (intstr *IntOrString) Fuzz(c fuzz.Continue) { ...@@ -191,6 +192,25 @@ func (intstr *IntOrString) Fuzz(c fuzz.Continue) {
} }
} }
func GetIntOrPercentValue(intStr *IntOrString) (int, bool, error) {
switch intStr.Kind {
case IntstrInt:
return intStr.IntVal, false, nil
case IntstrString:
s := strings.Replace(intStr.StrVal, "%", "", -1)
v, err := strconv.Atoi(s)
if err != nil {
return 0, false, fmt.Errorf("invalid value %q: %v", intStr.StrVal, err)
}
return 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 // Takes a list of strings and compiles them into a list of regular expressions
func CompileRegexps(regexpStrings []string) ([]*regexp.Regexp, error) { func CompileRegexps(regexpStrings []string) ([]*regexp.Regexp, error) {
regexps := []*regexp.Regexp{} regexps := []*regexp.Regexp{}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment