adding a default value for the AGE field (#2320)

* adding a default value for the AGE field

* use NAValue as a fallback value
mine
Jayson Wang 2023-12-09 11:07:28 +08:00 committed by GitHub
parent d0ec55737a
commit f6dfc3721a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import (
"strings"
"github.com/derailed/k9s/internal/client"
"github.com/rs/zerolog/log"
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
)
@ -98,6 +99,9 @@ func (g *Generic) Render(o interface{}, ns string, r *Row) error {
}
if d, ok := duration.(string); ok {
r.Fields = append(r.Fields, d)
} else if g.ageIndex > 0 {
log.Warn().Msgf("No Duration detected on age field")
r.Fields = append(r.Fields, NAValue)
}
return nil

View File

@ -4,6 +4,7 @@
package render
import (
"math"
"sort"
"strconv"
"strings"
@ -48,6 +49,9 @@ func durationToSeconds(duration string) int64 {
if len(duration) == 0 {
return 0
}
if duration == NAValue {
return math.MaxInt64
}
num := make([]rune, 0, 5)
var n, m int64

View File

@ -4,6 +4,7 @@
package render
import (
"math"
"testing"
"time"
@ -69,6 +70,7 @@ func TestDurationToSecond(t *testing.T) {
"day_hour_minute_seconds": {s: "2d22h3m50s", e: 252230},
"year": {s: "3y", e: 94608000},
"year_day": {s: "1y2d", e: 31708800},
"n/a": {s: NAValue, e: math.MaxInt64},
}
for k := range uu {