Merge pull request #31 from zalando-incubator/fix/no-backend

Fix case when backend is not set
This commit is contained in:
Mikkel Oscar Lyderik Larsen 2019-01-23 11:44:54 +01:00 committed by GitHub
commit 7258cb7800
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -85,12 +85,12 @@ func getAnnotationWeight(backendWeights string, backend string) float64 {
var weightsMap map[string]int
err := json.Unmarshal([]byte(backendWeights), &weightsMap)
if err != nil {
return 0
return 1
}
if weight, ok := weightsMap[backend]; ok {
return float64(weight) / 100
}
return 0
return 1
}
func getWeights(ingressAnnotations map[string]string, backendAnnotations []string, backend string) float64 {

View File

@ -174,6 +174,18 @@ func TestSkipperCollector(t *testing.T) {
readyReplicas: 5,
backendAnnotations: []string{testBackendWeightsAnnotation, testStacksetWeightsAnnotation},
},
{
msg: "test backend is not set",
metrics: []int{100, 1500, 700},
ingressName: "dummy-ingress",
collectedMetric: 1500,
namespace: "default",
backend: "",
backendWeights: map[string]map[string]int{testBackendWeightsAnnotation: {"backend2": 100, "backend1": 0}},
replicas: 1,
readyReplicas: 1,
backendAnnotations: []string{testBackendWeightsAnnotation},
},
} {
t.Run(tc.msg, func(tt *testing.T) {
client := fake.NewSimpleClientset()