Skip to content

Commit

Permalink
fix nil point error (labring#3606)
Browse files Browse the repository at this point in the history
  • Loading branch information
bxy4543 committed Jul 31, 2023
1 parent 40babea commit 4da39b8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions controllers/account/controllers/account_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,10 @@ func (r *AccountReconciler) syncAccount(ctx context.Context, name, accountNamesp
Namespace: accountNamespace,
},
}
account.Annotations = make(map[string]string)
if _, err := controllerutil.CreateOrUpdate(ctx, r.Client, &account, func() error {
if account.Annotations == nil {
account.Annotations = make(map[string]string)
}
return nil
}); err != nil {
return nil, err
Expand All @@ -249,7 +251,7 @@ func (r *AccountReconciler) syncAccount(ctx context.Context, name, accountNamesp
}

if account.Annotations[AccountAnnotationNewAccount] == "false" {
r.Logger.V(1).Info("account is not a new user ", "account", account)
//r.Logger.V(1).Info("account is not a new user ", "account", account)
return &account, nil
}

Expand All @@ -259,6 +261,9 @@ func (r *AccountReconciler) syncAccount(ctx context.Context, name, accountNamesp
return nil, fmt.Errorf("convert %s to int failed: %v", stringAmount, err)
}
if _, err := controllerutil.CreateOrUpdate(ctx, r.Client, &account, func() error {
if account.Annotations == nil {
account.Annotations = make(map[string]string)
}
account.Annotations[AccountAnnotationNewAccount] = "false"
return nil
}); err != nil {
Expand Down

0 comments on commit 4da39b8

Please sign in to comment.