Added logic and test case for weight of backend is 0 (#29)

Signed-off-by: Arjun Naik <arjun.rn@gmail.com>
This commit is contained in:
Arjun
2019-01-18 17:39:01 +01:00
committed by GitHub
parent 75633d3082
commit 248acf0311
2 changed files with 14 additions and 2 deletions

View File

@@ -94,7 +94,7 @@ func getAnnotationWeight(backendWeights string, backend string) float64 {
}
func getWeights(ingressAnnotations map[string]string, backendAnnotations []string, backend string) float64 {
var maxWeight float64 = 0
var maxWeight float64 = -1
for _, anno := range backendAnnotations {
if weightsMap, ok := ingressAnnotations[anno]; ok {
weight := getAnnotationWeight(weightsMap, backend)
@@ -103,7 +103,7 @@ func getWeights(ingressAnnotations map[string]string, backendAnnotations []strin
}
}
}
if maxWeight > 0 {
if maxWeight >= 0 {
return maxWeight
}
return 1.0

View File

@@ -147,6 +147,18 @@ func TestSkipperCollector(t *testing.T) {
readyReplicas: 5,
backendAnnotations: []string{testBackendWeightsAnnotation},
},
{
msg: "test zero weight backends",
metrics: []int{100, 1500, 700},
ingressName: "dummy-ingress",
collectedMetric: 0,
namespace: "default",
backend: "backend1",
backendWeights: map[string]map[string]int{testBackendWeightsAnnotation: {"backend2": 100, "backend1": 0}},
replicas: 5,
readyReplicas: 5,
backendAnnotations: []string{testBackendWeightsAnnotation},
},
{
msg: "test multiple backend annotation",
metrics: []int{100, 1500, 700},