From 66e04159c8e7be7993cc5b74a51923dd2fc94c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iago=20L=C3=B3pez=20Galeiras?= Date: Mon, 18 Sep 2017 15:52:55 +0200 Subject: [PATCH 1/2] api: add CreatedAt to v1.Pod It might happen that the pod is created but we can't get its start time (e.g. we can't find the CNI network corresponding to `--net=NETWORK`). This means StartedAt will not be set and the kubelet will error out and ignore the pod, so it won't try to start it again. Let's introduce CreatedAt to express the time when the pod was created (even if it doesn't start) to handle this. This works because this time is available after pod preparation. We'll need to change rktlet to use CreatedAt instead of StartedAt when getting a pod sandbox status. --- api/v1/json.go | 2 ++ lib/pod.go | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/api/v1/json.go b/api/v1/json.go index 534c46f673..b793c70874 100644 --- a/api/v1/json.go +++ b/api/v1/json.go @@ -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. diff --git a/lib/pod.go b/lib/pod.go index 5be69a3910..8a50597080 100644 --- a/lib/pod.go +++ b/lib/pod.go @@ -15,6 +15,8 @@ package rkt import ( + "errors" + "github.com/rkt/rkt/api/v1" pkgPod "github.com/rkt/rkt/pkg/pod" ) @@ -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 } From bc2d91279f6217d6120f8f96bf72de9dc2df62ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iago=20L=C3=B3pez=20Galeiras?= Date: Wed, 20 Sep 2017 14:52:22 +0200 Subject: [PATCH 2/2] tests: check output validity for when parsing pod info --- tests/rkt_tests.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/rkt_tests.go b/tests/rkt_tests.go index 5747c12f80..172236dd53 100644 --- a/tests/rkt_tests.go +++ b/tests/rkt_tests.go @@ -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 {