Skip to content

Commit

Permalink
Use flexvolume information to populate job listing (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
LilliJane committed Mar 29, 2018
1 parent 6f10046 commit 25da935
Showing 1 changed file with 9 additions and 33 deletions.
42 changes: 9 additions & 33 deletions svc/kube_list_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@ func (k *Kube) ListJobs(ctx context.Context, in *ListJobsInput) (out *ListJobsOu
return nil, err
}

//List Datasets
datasets := &datasets{}
err = k.visor.ListResources(ctx, kubevisor.ResourceTypeDatasets, datasets, nil, nil)
if err != nil {
return nil, err
}

//Get Events
events := &events{}
err = k.visor.ListResources(ctx, kubevisor.ResourceTypeEvents, events, nil, []string{"involvedObject.kind=Job,reason=FailedCreate"})
Expand All @@ -113,9 +106,6 @@ func (k *Kube) ListJobs(ctx context.Context, in *ListJobsInput) (out *ListJobsOu
return nil, err
}

//map datasets
inputs, outputs := mapDatasets(datasets)

//get jobs and investigate
out = &ListJobsOutput{}
mapping := map[types.UID]*ListJobItem{}
Expand Down Expand Up @@ -145,14 +135,15 @@ func (k *Kube) ListJobs(ctx context.Context, in *ListJobsInput) (out *ListJobsOu
item.ActiveAt = job.Status.StartTime.Local()
}

d, ok := inputs[job.Name]
if ok {
item.Input = d
}

d, ok = outputs[job.Name]
if ok {
item.Output = d
for _, dataset := range job.Spec.Template.Spec.Volumes {
if dataset.FlexVolume != nil {
if dataset.FlexVolume.Options["input/dataset"] != "" {
item.Input = append(item.Input, dataset.FlexVolume.Options["input/dataset"])
}
if dataset.FlexVolume.Options["output/dataset"] != "" {
item.Output = append(item.Output, dataset.FlexVolume.Options["output/dataset"])
}
}
}

for _, cond := range job.Status.Conditions {
Expand Down Expand Up @@ -264,21 +255,6 @@ func (k *Kube) ListJobs(ctx context.Context, in *ListJobsInput) (out *ListJobsOu
return out, nil
}

func mapDatasets(datasets *datasets) (map[string][]string, map[string][]string) {
inputs := map[string][]string{}
outputs := map[string][]string{}

for _, d := range datasets.Items {
for _, inputForJob := range d.Spec.InputFor {
inputs[inputForJob] = append(inputs[inputForJob], d.Name)
}
for _, outputOfJob := range d.Spec.OutputFrom {
outputs[outputOfJob] = append(outputs[outputOfJob], d.Name)
}
}
return inputs, outputs
}

//jobs implements the list transformer interface to allow the kubevisor the manage names for us
type jobs struct{ *batchv1.JobList }

Expand Down

0 comments on commit 25da935

Please sign in to comment.