From a5814fe16a1350797df765df67d18eb32aa8543a Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 7 Jun 2022 01:21:53 +0300 Subject: [PATCH] lib/promscrape/discovery/kubernetes: use unsupportedFieldError() function instead of errContext string This improves code readability and maintainability a bit, since the format string is passed as string literal into fmt.Errorf. --- .../discovery/kubernetes/kubeconfig.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/promscrape/discovery/kubernetes/kubeconfig.go b/lib/promscrape/discovery/kubernetes/kubeconfig.go index e63a1573b..a59c43371 100644 --- a/lib/promscrape/discovery/kubernetes/kubeconfig.go +++ b/lib/promscrape/discovery/kubernetes/kubeconfig.go @@ -66,21 +66,20 @@ type AuthInfo struct { } func (au *AuthInfo) validate() error { - errContext := "field %q is not supported yet; if you feel it is needed please open a feature request at https://github.com/VictoriaMetrics/VictoriaMetrics/issues/new" if au.Exec != nil { - return fmt.Errorf(errContext, "exec") + return unsupportedFieldError("exec") } if len(au.ImpersonateUID) > 0 { - return fmt.Errorf(errContext, "act-as-uid") + return unsupportedFieldError("act-as-uid") } if len(au.Impersonate) > 0 { - return fmt.Errorf(errContext, "act-as") + return unsupportedFieldError("act-as") } if len(au.ImpersonateGroups) > 0 { - return fmt.Errorf(errContext, "act-as-groups") + return unsupportedFieldError("act-as-groups") } if len(au.ImpersonateUserExtra) > 0 { - return fmt.Errorf(errContext, "act-as-user-extra") + return unsupportedFieldError("act-as-user-extra") } if len(au.Password) > 0 && len(au.Username) == 0 { return fmt.Errorf("username cannot be empty, if password defined") @@ -88,6 +87,11 @@ func (au *AuthInfo) validate() error { return nil } +func unsupportedFieldError(fieldName string) error { + return fmt.Errorf("field %q is not supported yet; if you feel it is needed please open a feature request "+ + "at https://github.com/VictoriaMetrics/VictoriaMetrics/issues/new", fieldName) +} + // ExecConfig contains information about os.command, that returns auth token for kubernetes cluster connection type ExecConfig struct { // Command to execute.