Arnavion / k8s-openapi

Rust definitions of the resource types in the Kubernetes client API
Apache License 2.0
379 stars 41 forks source link

derive Ord for Time #64

Closed clux closed 4 years ago

clux commented 4 years ago

kubectl supports sorting with --sort-by=.metadata.creationTimestamp, which we could easily do in memory if Time derived Ord.

https://github.com/Arnavion/k8s-openapi/blob/35cbddfeb26726bc1a0c882a40584c262fb53726/src/v1_17/apimachinery/pkg/apis/meta/v1/time.rs#L4-L5

This should be fine since chrono::DateTime - the wrapped type - implements Ord.

clux commented 4 years ago

..although, this isn't really a problem once you understand the underlying type and reach into the inner. This works:

podvec.sort_by_key(|p| {
    p.metadata.as_ref().unwrap().creation_timestamp.as_ref().unwrap().0
});