Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Commit

Permalink
rm nil check
Browse files Browse the repository at this point in the history
  • Loading branch information
iyuroch committed Apr 10, 2022
1 parent 820f283 commit 8133268
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
4 changes: 2 additions & 2 deletions api/v1beta1/additional.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
36 changes: 16 additions & 20 deletions controllers/factory/alertmanager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 8133268

Please sign in to comment.