Skip to content

Commit

Permalink
[apache#1629] fix(operator): ShuffleSever cannot be deleted even thou…
Browse files Browse the repository at this point in the history
…gh there are no more application.
  • Loading branch information
zhengchenyu committed Apr 9, 2024
1 parent 3ea3aaa commit e50a023
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
10 changes: 8 additions & 2 deletions deploy/kubernetes/operator/pkg/webhook/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io"
"io/ioutil"
"net/http"
"strconv"
"time"

admissionv1 "k8s.io/api/admission/v1"
Expand Down Expand Up @@ -163,7 +164,7 @@ type MetricItem struct {
Name string `json:"name"`
LabelNames []string `json:"labelNames"`
LabelValues []string `json:"labelValues"`
Value float32 `json:"value"`
Value interface{} `json:"value"`
}

// MetricList records all items of metric information of shuffle servers.
Expand All @@ -180,7 +181,12 @@ func getLastAppNum(body []byte) (int, error) {
}
for i := range resp.Metrics {
if resp.Metrics[i].Name == "app_num_with_node" {
return int(resp.Metrics[i].Value), nil
if value, ok := resp.Metrics[i].Value.(string); ok {
fValue, err := strconv.ParseFloat(value, 64)
return int(fValue), err
} else if value, ok := resp.Metrics[i].Value.(float64); ok {
return int(value), nil
}
}
}
return 0, nil
Expand Down
31 changes: 31 additions & 0 deletions deploy/kubernetes/operator/pkg/webhook/util/util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package util

import (
"testing"
)

func TestGetLastAppNum(t *testing.T) {
jsonString := `
{
"metrics": [{
"name": "app_num_with_node",
"labelNames": ["tags"],
"labelValues": ["ss_v5,GRPC"],
"value": 10.0,
"timestampMs": null
}, {
"name": "total_remove_resource_time",
"labelNames": ["quantile"],
"labelValues": ["0.5"],
"value": "NaN",
"timestampMs": null
}],
"timeStamp": 1712575271639
}
`
if num, err := getLastAppNum([]byte(jsonString)); err != nil {
t.Fatal("getLastAppNum failed, casued by ", err.Error())
} else if num != 10 {
t.Fatal("Get wrong app number: ", num)
}
}

0 comments on commit e50a023

Please sign in to comment.