Skip to content

Commit

Permalink
Merge pull request #57050 from juanvallejo/jvallejo/check-empty-label…
Browse files Browse the repository at this point in the history
…-resource-builder

Automatic merge from submit-queue (batch tested with PRs 56676, 57050, 54881, 56822, 57113). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

check for empty label before assigning

Prevents an empty label from being assigned to the resource builder when calling its `LabelSelectorParam` parameter. Currently, we assign the address of the provided selector string, even if the string is empty - this has the potential of returning erroneous failures since we check to see [if a selector was provided here](https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/resource/builder.go#L470), for example, by doing a nil check. Storing the pointer to [an empty string value](https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/resource/builder.go#L344) would break this check as the pointer is no longer nil

**Release note**:
```release-note
NONE
```

cc @deads2k @smarterclayton
  • Loading branch information
Kubernetes Submit Queue committed Dec 17, 2017
2 parents ce4acf3 + 80bc560 commit 9826925
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/kubectl/resource/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ func (b *Builder) LabelSelectorParam(s string) *Builder {
// LabelSelector accepts a selector directly and will filter the resulting list by that object.
// Use LabelSelectorParam instead for user input.
func (b *Builder) LabelSelector(selector string) *Builder {
if len(selector) == 0 {
return b
}

b.labelSelector = &selector
return b
}
Expand Down

0 comments on commit 9826925

Please sign in to comment.