Skip to content

Commit

Permalink
feat(tracejob): be more defensive in listing jobs and configmaps
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenzo Fontana <[email protected]>
  • Loading branch information
fntlnz committed Nov 26, 2018
1 parent 32ce5e4 commit 70140b3
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions pkg/tracejob/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type TraceJobFilter struct {
ID *types.UID
}

func (t *TraceJobClient) findJobsWithFilter(nf TraceJobFilter) ([]batchv1.Job, error) {
func (nf TraceJobFilter) selectorOptions() metav1.ListOptions {
selectorOptions := metav1.ListOptions{}

if nf.Name != nil {
Expand All @@ -57,6 +57,22 @@ func (t *TraceJobClient) findJobsWithFilter(nf TraceJobFilter) ([]batchv1.Job, e
}
}

if nf.Name == nil && nf.ID == nil {
selectorOptions = metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s", meta.TraceIDLabelKey),
}
}

return selectorOptions
}

func (t *TraceJobClient) findJobsWithFilter(nf TraceJobFilter) ([]batchv1.Job, error) {

selectorOptions := nf.selectorOptions()
if len(selectorOptions.LabelSelector) == 0 {
return []batchv1.Job{}, nil
}

jl, err := t.JobClient.List(selectorOptions)

if err != nil {
Expand All @@ -66,18 +82,9 @@ func (t *TraceJobClient) findJobsWithFilter(nf TraceJobFilter) ([]batchv1.Job, e
}

func (t *TraceJobClient) findConfigMapsWithFilter(nf TraceJobFilter) ([]apiv1.ConfigMap, error) {
selectorOptions := metav1.ListOptions{}

if nf.Name != nil {
selectorOptions = metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s=%s", meta.TraceLabelKey, *nf.Name),
}
}

if nf.ID != nil {
selectorOptions = metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s=%s", meta.TraceIDLabelKey, *nf.ID),
}
selectorOptions := nf.selectorOptions()
if len(selectorOptions.LabelSelector) == 0 {
return []apiv1.ConfigMap{}, nil
}

cm, err := t.ConfigClient.List(selectorOptions)
Expand Down

0 comments on commit 70140b3

Please sign in to comment.