Reputation: 121
I'm trying to add a custom function In Go template for parsing the time in PodStatus and getting the absolute time for it.
Example for the custom function:
PodScheduled, _ := time.Parse(time.RFC3339, "2021-12- 23T20:20:36Z")
Ready, _ := time.Parse(time.RFC3339, "2021-12-31T07:36:11Z")
difference := Ready.Sub(PodScheduled)
fmt.Printf("difference = %v\n", difference)
I can use the built-in functions.
How I can use a custom function with the kubectl?
For example this lib: https://github.com/Masterminds/sprig
Thanks :)
Upvotes: 1
Views: 5311
Reputation: 40296
IIUC you have (at least) 3 options:
kubectl
) that provides the functionality;kubectl get pods --output=json
) by piping the result through:
jq
that would do this (and much more!)kubectl
supports output formatting (--output=jsonpath...
); although JSONPath
may be insufficient for this need;See jq's documentation for Dates
Upvotes: 2