adding a default value for the AGE field (#2320)
* adding a default value for the AGE field * use NAValue as a fallback valuemine
parent
d0ec55737a
commit
f6dfc3721a
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue