1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-24 21:08:03 +00:00

Fix parsing of metadata.fields when age is already a duration (#700)

* Fix parsing of metadata.fields when age is already a duration

* Fix frozen "now"

* Use ParseTimestampOrHumanReadableDuration instead
This commit is contained in:
Alejandro Ruiz
2025-07-01 18:53:51 +02:00
committed by GitHub
parent c782fea615
commit 61173104af
3 changed files with 21 additions and 12 deletions

View File

@@ -262,14 +262,17 @@ func convertMetadataTimestampFields(request *types.APIRequest, gvk schema2.Group
return
}
millis, err := strconv.ParseInt(timeValue, 10, 64)
if err != nil {
logrus.Warnf("convert timestamp value: %s failed with error: %s", timeValue, err.Error())
return
}
dur, ok := isDuration(timeValue)
if !ok {
millis, err := strconv.ParseInt(timeValue, 10, 64)
if err != nil {
logrus.Warnf("convert timestamp value: %s failed with error: %s", timeValue, err.Error())
return
}
timestamp := time.Unix(0, millis*int64(time.Millisecond))
dur := time.Since(timestamp)
timestamp := time.Unix(0, millis*int64(time.Millisecond))
dur = time.Since(timestamp)
}
humanDuration := duration.HumanDuration(dur)
if humanDuration == "<invalid>" {
@@ -287,6 +290,11 @@ func convertMetadataTimestampFields(request *types.APIRequest, gvk schema2.Group
}
}
func isDuration(value string) (time.Duration, bool) {
d, err := ParseTimestampOrHumanReadableDuration(value)
return d, err == nil
}
func excludeValues(request *types.APIRequest, unstr *unstructured.Unstructured) {
if values, ok := request.Query["excludeValues"]; ok {
for _, f := range values {