Skip to content

Commit

Permalink
add a nil check for Watch Selector field (#164)
Browse files Browse the repository at this point in the history
* add a nil check for Watch Selector field

Signed-off-by: Bryce Palmer <bpalmer@redhat.com>

* update watches_test

Signed-off-by: Bryce Palmer <bpalmer@redhat.com>
  • Loading branch information
everettraven committed May 17, 2022
1 parent 7a3e61f commit d1e2f41
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/watches/watches.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func LoadReader(reader io.Reader) ([]Watch, error) {
w.WatchDependentResources = &trueVal
}

if w.Selector == nil {
w.Selector = &metav1.LabelSelector{}
}

w.OverrideValues, err = expandOverrideValues(w.OverrideValues)
if err != nil {
return nil, fmt.Errorf("failed to expand override values")
Expand Down
6 changes: 5 additions & 1 deletion pkg/watches/watches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,11 @@ func verifyEqualWatches(expectedWatch, obtainedWatch []Watch) {
Expect(expectedWatch[i].OverrideValues).To(BeEquivalentTo(obtainedWatch[i].OverrideValues))
Expect(expectedWatch[i].MaxConcurrentReconciles).To(BeEquivalentTo(obtainedWatch[i].MaxConcurrentReconciles))
Expect(expectedWatch[i].ReconcilePeriod).To(BeEquivalentTo(obtainedWatch[i].ReconcilePeriod))
Expect(expectedWatch[i].Selector).To(BeEquivalentTo(obtainedWatch[i].Selector))
if expectedWatch[i].Selector == nil {
Expect(&v1.LabelSelector{}).To(BeEquivalentTo(obtainedWatch[i].Selector))
} else {
Expect(expectedWatch[i].Selector).To(BeEquivalentTo(obtainedWatch[i].Selector))
}
}
}

Expand Down

0 comments on commit d1e2f41

Please sign in to comment.