From 8133268daad07b0ae00887c8360268e3d9b59b4e Mon Sep 17 00:00:00 2001 From: iyuroch Date: Sun, 10 Apr 2022 20:55:02 +0300 Subject: [PATCH] rm nil check --- api/v1beta1/additional.go | 4 +-- controllers/factory/alertmanager/config.go | 36 ++++++++++------------ 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/api/v1beta1/additional.go b/api/v1beta1/additional.go index 87329500..0867755d 100644 --- a/api/v1beta1/additional.go +++ b/api/v1beta1/additional.go @@ -143,12 +143,12 @@ type BasicAuth struct { // for authentication. // It must be at them same namespace as CRD // +optional - Username *v1.SecretKeySelector `json:"username,omitempty"` + Username v1.SecretKeySelector `json:"username,omitempty"` // The secret in the service scrape namespace that contains the password // for authentication. // It must be at them same namespace as CRD // +optional - Password *v1.SecretKeySelector `json:"password,omitempty"` + Password v1.SecretKeySelector `json:"password,omitempty"` // PasswordFile defines path to password file at disk // +optional PasswordFile string `json:"password_file,omitempty"` diff --git a/controllers/factory/alertmanager/config.go b/controllers/factory/alertmanager/config.go index 0aa84f53..7548a915 100644 --- a/controllers/factory/alertmanager/config.go +++ b/controllers/factory/alertmanager/config.go @@ -745,26 +745,22 @@ func (cb *configBuilder) buildHTTPConfig(httpCfg *operatorv1beta1.HTTPConfig) (y func (cb *configBuilder) buildBasicAuth(basicAuth *operatorv1beta1.BasicAuth) (yaml.MapSlice, error) { var r yaml.MapSlice - if basicAuth.Username != nil { - u, err := cb.fetchSecretValue(&basicAuth.Username) - if err != nil { - return nil, err - } - r = append(r, yaml.MapItem{ - Key: "username", - Value: string(u), - }) - } - if basicAuth.Password != nil { - p, err := cb.fetchSecretValue(&basicAuth.Password) - if err != nil { - return nil, err - } - r = append(r, yaml.MapItem{ - Key: "password", - Value: string(p), - }) - } + u, err := cb.fetchSecretValue(&basicAuth.Username) + if err != nil { + return nil, err + } + r = append(r, yaml.MapItem{ + Key: "username", + Value: string(u), + }) + p, err := cb.fetchSecretValue(&basicAuth.Password) + if err != nil { + return nil, err + } + r = append(r, yaml.MapItem{ + Key: "password", + Value: string(p), + }) if len(basicAuth.PasswordFile) > 0 { r = append(r, yaml.MapItem{ Key: "password_file",