Commit bef60b86 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

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
parents ae1c9a2b 1b8f4e0b
...@@ -806,12 +806,13 @@ func HasNames(args []string) (bool, error) { ...@@ -806,12 +806,13 @@ func HasNames(args []string) (bool, error) {
// MultipleTypesRequested returns true if the provided args contain multiple resource kinds // MultipleTypesRequested returns true if the provided args contain multiple resource kinds
func MultipleTypesRequested(args []string) bool { func MultipleTypesRequested(args []string) bool {
if len(args) == 1 && args[0] == "all" {
return true
}
args = normalizeMultipleResourcesArgs(args) args = normalizeMultipleResourcesArgs(args)
rKinds := sets.NewString() rKinds := sets.NewString()
for _, arg := range args { for _, arg := range args {
if arg == "all" {
return true
}
rTuple, found, err := splitResourceTypeName(arg) rTuple, found, err := splitResourceTypeName(arg)
if err != nil { if err != nil {
continue continue
......
...@@ -1256,6 +1256,14 @@ func TestMultipleTypesRequested(t *testing.T) { ...@@ -1256,6 +1256,14 @@ func TestMultipleTypesRequested(t *testing.T) {
expectedMultipleTypes: false, expectedMultipleTypes: false,
}, },
{ {
args: []string{"pod,all"},
expectedMultipleTypes: true,
},
{
args: []string{"all,rc,pod"},
expectedMultipleTypes: true,
},
{
args: []string{"rc,pod,svc"}, args: []string{"rc,pod,svc"},
expectedMultipleTypes: true, expectedMultipleTypes: true,
}, },
...@@ -1287,7 +1295,7 @@ func TestMultipleTypesRequested(t *testing.T) { ...@@ -1287,7 +1295,7 @@ func TestMultipleTypesRequested(t *testing.T) {
for _, test := range tests { for _, test := range tests {
hasMultipleTypes := MultipleTypesRequested(test.args) hasMultipleTypes := MultipleTypesRequested(test.args)
if hasMultipleTypes != test.expectedMultipleTypes { 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)
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment