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

api: add CreatedAt to v1.Pod #3797

Merged
merged 2 commits into from Sep 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/v1/json.go
Expand Up @@ -77,6 +77,8 @@ type (
AppNames []string `json:"app_names,omitempty"`
// Apps holds current information about each app.
Apps []*App `json:"apps,omitempty"`
// The creation time of the pod.
CreatedAt *int64 `json:"created_at,omitempty"`
// The start time of the pod.
StartedAt *int64 `json:"started_at,omitempty"`
// UserAnnotations are the pod user annotations.
Expand Down
13 changes: 13 additions & 0 deletions lib/pod.go
Expand Up @@ -15,6 +15,8 @@
package rkt

import (
"errors"

"github.com/rkt/rkt/api/v1"
pkgPod "github.com/rkt/rkt/pkg/pod"
)
Expand All @@ -37,6 +39,17 @@ func NewPodFromInternalPod(p *pkgPod.Pod) (*v1.Pod, error) {
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() {
return pod, nil
}
Expand Down
8 changes: 8 additions & 0 deletions tests/rkt_tests.go
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 {
Expand Down