mirror of
https://github.com/zalando-incubator/kube-metrics-adapter.git
synced 2025-10-03 11:42:24 +00:00
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:
@@ -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
|
||||
|
@@ -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},
|
||||
|
Reference in New Issue
Block a user