Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

Commit

Permalink
Merge pull request #3797 from kinvolk/iaguis/created-at
Browse files Browse the repository at this point in the history
api: add CreatedAt to v1.Pod
  • Loading branch information
iaguis committed Sep 20, 2017
2 parents 5e83d91 + bc2d912 commit 0051bc1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/v1/json.go
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ type (
AppNames []string `json:"app_names,omitempty"` AppNames []string `json:"app_names,omitempty"`
// Apps holds current information about each app. // Apps holds current information about each app.
Apps []*App `json:"apps,omitempty"` Apps []*App `json:"apps,omitempty"`
// The creation time of the pod.
CreatedAt *int64 `json:"created_at,omitempty"`
// The start time of the pod. // The start time of the pod.
StartedAt *int64 `json:"started_at,omitempty"` StartedAt *int64 `json:"started_at,omitempty"`
// UserAnnotations are the pod user annotations. // UserAnnotations are the pod user annotations.
Expand Down
13 changes: 13 additions & 0 deletions lib/pod.go
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package rkt package rkt


import ( import (
"errors"

"github.com/rkt/rkt/api/v1" "github.com/rkt/rkt/api/v1"
pkgPod "github.com/rkt/rkt/pkg/pod" pkgPod "github.com/rkt/rkt/pkg/pod"
) )
Expand All @@ -37,6 +39,17 @@ func NewPodFromInternalPod(p *pkgPod.Pod) (*v1.Pod, error) {
pod.StartedAt = &startedAt pod.StartedAt = &startedAt
} }


creationTime, err := p.CreationTime()
if err != nil {
return nil, err
}

createdAt := creationTime.Unix()
if creationTime.IsZero() || createdAt <= 0 {
return nil, errors.New("invalid creation time")
}
pod.CreatedAt = &createdAt

if !p.PodManifestAvailable() { if !p.PodManifestAvailable() {
return pod, nil return pod, nil
} }
Expand Down
8 changes: 8 additions & 0 deletions tests/rkt_tests.go
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -673,6 +673,14 @@ func parsePodInfoOutput(t *testing.T, result string, p *podInfo) {
} }
} }
} }

if p.state == "" {
t.Fatalf("Unexpected empty state for pod")
}

if p.createdAt <= 0 {
t.Fatalf("Unexpected createdAt <= 0 for pod")
}
} }


func getPodDir(t *testing.T, ctx *testutils.RktRunCtx, podID string) string { func getPodDir(t *testing.T, ctx *testutils.RktRunCtx, podID string) string {
Expand Down

0 comments on commit 0051bc1

Please sign in to comment.