From 1c80b9c6f9774260c40e663d24882e21d3078da9 Mon Sep 17 00:00:00 2001 From: xuriwuyun Date: Wed, 26 Jun 2024 10:36:28 +0800 Subject: [PATCH] fix: add a user check before creating (#7632) --- controllers/apps/component_controller_test.go | 1 + controllers/apps/transformer_component_account_provision.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/controllers/apps/component_controller_test.go b/controllers/apps/component_controller_test.go index 4848a38710d..12f0bce7b03 100644 --- a/controllers/apps/component_controller_test.go +++ b/controllers/apps/component_controller_test.go @@ -92,6 +92,7 @@ var mockLorryClient = func(mock func(*lorry.MockClientMockRecorder)) { var mockLorryClientDefault = func() { mockLorryClient(func(recorder *lorry.MockClientMockRecorder) { recorder.CreateUser(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() + recorder.DescribeUser(gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() recorder.GrantUserRole(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() }) } diff --git a/controllers/apps/transformer_component_account_provision.go b/controllers/apps/transformer_component_account_provision.go index 2cbf62ecf41..fe6648b3029 100644 --- a/controllers/apps/transformer_component_account_provision.go +++ b/controllers/apps/transformer_component_account_provision.go @@ -222,6 +222,10 @@ func (t *componentAccountProvisionTransformer) provisionAccount(transCtx *compon return nil } + userInfo, err := lorryCli.DescribeUser(transCtx, string(username)) + if err == nil && len(userInfo) != 0 { + return nil + } // TODO: re-define the role return lorryCli.CreateUser(transCtx.Context, string(username), string(password), string(lorryModel.SuperUserRole)) }