Optimize some codes

This commit is contained in:
xiongzhongliang
2021-02-28 01:00:09 +08:00
parent bd190762fb
commit 4a24a08f93
5 changed files with 12 additions and 22 deletions

View File

@@ -84,7 +84,7 @@ func (a *AdmissionOptions) Validate() []error {
if a == nil {
return nil
}
errs := []error{}
var errs []error
if a.PluginNames != nil &&
(a.GenericAdmission.EnablePlugins != nil || a.GenericAdmission.DisablePlugins != nil) {
errs = append(errs, fmt.Errorf("admission-control and enable-admission-plugins/disable-admission-plugins flags are mutually exclusive"))

View File

@@ -185,7 +185,7 @@ func (o *BuiltInAuthenticationOptions) WithWebHook() *BuiltInAuthenticationOptio
// Validate checks invalid config combination
func (o *BuiltInAuthenticationOptions) Validate() []error {
allErrors := []error{}
var allErrors []error
if o.OIDC != nil && (len(o.OIDC.IssuerURL) > 0) != (len(o.OIDC.ClientID) > 0) {
allErrors = append(allErrors, fmt.Errorf("oidc-issuer-url and oidc-client-id should be specified together"))
@@ -219,7 +219,7 @@ func (o *BuiltInAuthenticationOptions) Validate() []error {
if o.WebHook != nil {
retryBackoff := o.WebHook.RetryBackoff
if retryBackoff != nil && retryBackoff.Steps <= 0 {
allErrors = append(allErrors, fmt.Errorf("number of webhook retry attempts must be greater than 1, but is: %d", retryBackoff.Steps))
allErrors = append(allErrors, fmt.Errorf("number of webhook retry attempts must be greater than 0, but is: %d", retryBackoff.Steps))
}
}

View File

@@ -61,7 +61,7 @@ func (o *BuiltInAuthorizationOptions) Validate() []error {
if o == nil {
return nil
}
allErrors := []error{}
var allErrors []error
if len(o.Modes) == 0 {
allErrors = append(allErrors, fmt.Errorf("at least one authorization-mode must be passed"))
@@ -72,15 +72,11 @@ func (o *BuiltInAuthorizationOptions) Validate() []error {
if !authzmodes.IsValidAuthorizationMode(mode) {
allErrors = append(allErrors, fmt.Errorf("authorization-mode %q is not a valid mode", mode))
}
if mode == authzmodes.ModeABAC {
if o.PolicyFile == "" {
allErrors = append(allErrors, fmt.Errorf("authorization-mode ABAC's authorization policy file not passed"))
}
if mode == authzmodes.ModeABAC && o.PolicyFile == "" {
allErrors = append(allErrors, fmt.Errorf("authorization-mode ABAC's authorization policy file not passed"))
}
if mode == authzmodes.ModeWebhook {
if o.WebhookConfigFile == "" {
allErrors = append(allErrors, fmt.Errorf("authorization-mode Webhook's authorization config file not passed"))
}
if mode == authzmodes.ModeWebhook && o.WebhookConfigFile == "" {
allErrors = append(allErrors, fmt.Errorf("authorization-mode Webhook's authorization config file not passed"))
}
}
@@ -97,7 +93,7 @@ func (o *BuiltInAuthorizationOptions) Validate() []error {
}
if o.WebhookRetryBackoff != nil && o.WebhookRetryBackoff.Steps <= 0 {
allErrors = append(allErrors, fmt.Errorf("number of webhook retry attempts must be greater than 1, but is: %d", o.WebhookRetryBackoff.Steps))
allErrors = append(allErrors, fmt.Errorf("number of webhook retry attempts must be greater than 0, but is: %d", o.WebhookRetryBackoff.Steps))
}
return allErrors