Unverified Commit 88cfcb45 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #55856 from miaoyq/replace-for-with-sets

Automatic merge from submit-queue (batch tested with PRs 53689, 56880, 55856, 59289, 60249). 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>. Use `sets` instead of `for` statement in "IsValidAuthorizationMode" **What this PR does / why we need it**: Use `sets` instead of `for` statement in "IsValidAuthorizationMode", that will make the code more clearly and concisely. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: **Release note**: ```release-note none ```
parents f45f4a4e 96e2610a
...@@ -16,6 +16,7 @@ go_library( ...@@ -16,6 +16,7 @@ go_library(
name = "go_default_library", name = "go_default_library",
srcs = ["modes.go"], srcs = ["modes.go"],
importpath = "k8s.io/kubernetes/pkg/kubeapiserver/authorizer/modes", importpath = "k8s.io/kubernetes/pkg/kubeapiserver/authorizer/modes",
deps = ["//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library"],
) )
filegroup( filegroup(
......
...@@ -16,6 +16,8 @@ limitations under the License. ...@@ -16,6 +16,8 @@ limitations under the License.
package modes package modes
import "k8s.io/apimachinery/pkg/util/sets"
const ( const (
ModeAlwaysAllow string = "AlwaysAllow" ModeAlwaysAllow string = "AlwaysAllow"
ModeAlwaysDeny string = "AlwaysDeny" ModeAlwaysDeny string = "AlwaysDeny"
...@@ -29,10 +31,5 @@ var AuthorizationModeChoices = []string{ModeAlwaysAllow, ModeAlwaysDeny, ModeABA ...@@ -29,10 +31,5 @@ var AuthorizationModeChoices = []string{ModeAlwaysAllow, ModeAlwaysDeny, ModeABA
// IsValidAuthorizationMode returns true if the given authorization mode is a valid one for the apiserver // IsValidAuthorizationMode returns true if the given authorization mode is a valid one for the apiserver
func IsValidAuthorizationMode(authzMode string) bool { func IsValidAuthorizationMode(authzMode string) bool {
for _, validMode := range AuthorizationModeChoices { return sets.NewString(AuthorizationModeChoices...).Has(authzMode)
if authzMode == validMode {
return true
}
}
return false
} }
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