Merge pull request #40046 from juanvallejo/jvallejo/update-multiple-types-requested-check

Automatic merge from submit-queue (batch tested with PRs 40046, 40073, 40547, 40534, 40249)

update check for "all" resources

This patch updates the check for `all` resources to handle cases where a resource's name is "all". Rather than cycling through all given args until `all` is found, this patch makes sure that only a single argument `all` was specified at all.

**Release note**:
```release-note
release-note-none
```

@fabianofranz @pwittrock
This commit is contained in:
Kubernetes Submit Queue 2017-01-26 16:10:34 -08:00 committed by GitHub
commit bef60b8602
2 changed files with 13 additions and 4 deletions

View File

@ -806,12 +806,13 @@ func HasNames(args []string) (bool, error) {
// MultipleTypesRequested returns true if the provided args contain multiple resource kinds
func MultipleTypesRequested(args []string) bool {
if len(args) == 1 && args[0] == "all" {
return true
}
args = normalizeMultipleResourcesArgs(args)
rKinds := sets.NewString()
for _, arg := range args {
if arg == "all" {
return true
}
rTuple, found, err := splitResourceTypeName(arg)
if err != nil {
continue

View File

@ -1255,6 +1255,14 @@ func TestMultipleTypesRequested(t *testing.T) {
args: []string{"rc"},
expectedMultipleTypes: false,
},
{
args: []string{"pod,all"},
expectedMultipleTypes: true,
},
{
args: []string{"all,rc,pod"},
expectedMultipleTypes: true,
},
{
args: []string{"rc,pod,svc"},
expectedMultipleTypes: true,
@ -1287,7 +1295,7 @@ func TestMultipleTypesRequested(t *testing.T) {
for _, test := range tests {
hasMultipleTypes := MultipleTypesRequested(test.args)
if hasMultipleTypes != test.expectedMultipleTypes {
t.Errorf("expected HasName to return %v for %s", test.expectedMultipleTypes, test.args)
t.Errorf("expected MultipleTypesRequested to return %v for %s", test.expectedMultipleTypes, test.args)
}
}
}