@@ -22,6 +22,8 @@ import (
22
22
"context"
23
23
"encoding/json"
24
24
"fmt"
25
+ "slices"
26
+ "time"
25
27
26
28
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
27
29
oras "oras.land/oras-go/v2"
@@ -34,6 +36,10 @@ import (
34
36
compatv1alpha1 "sigs.k8s.io/node-feature-discovery/api/image-compatibility/v1alpha1"
35
37
)
36
38
39
+ const (
40
+ ArtifactCreationTimestampKey = "org.opencontainers.image.created"
41
+ )
42
+
37
43
// ArtifactClient interface contain set of functions to manipulate compatibility artfact.
38
44
type ArtifactClient interface {
39
45
// FetchCompatibilitySpec downloads the compatibility specifcation associated with the image.
@@ -90,6 +96,14 @@ func (c *Client) FetchCompatibilitySpec(ctx context.Context) (*compatv1alpha1.Sp
90
96
} else if len (descs ) < 1 {
91
97
return nil , fmt .Errorf ("compatibility artifact not found" )
92
98
}
99
+
100
+ // Sort the artifacts in desc order.
101
+ // If the artifact does not have creation timestamp it will be moved to the top of the slice.
102
+ slices .SortFunc (descs , func (i , j ocispec.Descriptor ) int {
103
+ it , _ := time .Parse (time .RFC3339 , i .Annotations [ArtifactCreationTimestampKey ])
104
+ jt , _ := time .Parse (time .RFC3339 , j .Annotations [ArtifactCreationTimestampKey ])
105
+ return it .Compare (jt )
106
+ })
93
107
artifactDesc := descs [len (descs )- 1 ]
94
108
95
109
_ , content , err := oras .FetchBytes (ctx , repo .Manifests (), artifactDesc .Digest .String (), oras .DefaultFetchBytesOptions )
0 commit comments