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.
This commit is contained in:
Aliaksandr Valialkin 2022-06-07 01:21:53 +03:00
parent 68b6ddfb14
commit b6e3c12811
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -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.