Просмотр исходного кода

Merge pull request #496 from kubecost/niko/jobs

Capture CronJob name without timestamp
Niko Kovacevic 5 лет назад
Родитель
Сommit
5f02eef707
1 измененных файлов с 9 добавлено и 0 удалено
  1. 9 0
      pkg/costmodel/costmodel.go

+ 9 - 0
pkg/costmodel/costmodel.go

@@ -6,6 +6,7 @@ import (
 	"fmt"
 	"math"
 	"net/http"
+	"regexp"
 	"strconv"
 	"strings"
 	"sync"
@@ -49,6 +50,9 @@ const (
 	epFlags           = apiPrefix + "/status/flags"
 )
 
+// isCron matches a CronJob name and captures the non-timestamp name
+var isCron = regexp.MustCompile(`^(.+)-\d{10}$`)
+
 type CostModel struct {
 	Cache        clustercache.ClusterCache
 	RequestGroup *singleflight.Group
@@ -115,6 +119,11 @@ func (cd *CostData) GetController() (name string, kind string, hasController boo
 		name = cd.Jobs[0]
 		kind = "job"
 		hasController = true
+
+		match := isCron.FindStringSubmatch(name)
+		if match != nil {
+			name = match[1]
+		}
 	}
 
 	return name, kind, hasController