Skip to content

Commit

Permalink
feat: added status time
Browse files Browse the repository at this point in the history
  • Loading branch information
shanduur committed Sep 29, 2023
1 parent b56299d commit e4d2b03
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
4 changes: 4 additions & 0 deletions internal/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/pkg/apis/apps"
appsv1 "k8s.io/kubernetes/pkg/apis/apps/v1"
"k8s.io/kubernetes/pkg/apis/batch"
batchv1 "k8s.io/kubernetes/pkg/apis/batch/v1"
"k8s.io/kubernetes/pkg/apis/core"
corev1 "k8s.io/kubernetes/pkg/apis/core/v1"
"k8s.io/kubernetes/pkg/apis/storage"
Expand Down Expand Up @@ -196,6 +198,8 @@ func initConversionScheme() *runtime.Scheme {

apps.AddToScheme(scheme)
appsv1.AddToScheme(scheme)
batch.AddToScheme(scheme)
batchv1.AddToScheme(scheme)
core.AddToScheme(scheme)
corev1.AddToScheme(scheme)
storage.AddToScheme(scheme)
Expand Down
25 changes: 16 additions & 9 deletions internal/adapter/converter/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,31 @@ func (converter *DockerAPIConverter) UpdateJobFromContainerInfo(job *batch.Job,

containerState := container.State

startTime, _ := time.Parse(time.RFC3339Nano, json.State.StartedAt)

metaStartTime := &metav1.Time{
Time: startTime,
}

job.Status.StartTime = metaStartTime

job.Status.Active = 0

if containerState == "running" {
job.Status.Active = 1
} else {
// TODO: handle completion status?
if json.State.ExitCode == 0 {
job.Status.Succeeded = 1

completionTime, _ := time.Parse(time.RFC3339Nano, json.State.FinishedAt)

metaCompletionTime := &metav1.Time{
Time: completionTime,
}

job.Status.CompletionTime = metaCompletionTime
} else {
job.Status.Failed = 1
}

}

// TODO: handle duration?
// /containers/<container ID>/json ? This will allow getting:
// - State.ExitCode
// - State.StartedAt
// - State.FinishedAt
job.Status.CompletionTime.Time, _ = time.Parse("", json.State.FinishedAt)
}

0 comments on commit e4d2b03

Please sign in to comment.