@@ -119,7 +119,7 @@ func (t *componentAccountTransformer) Transform(ctx graph.TransformContext, dag
119119
120120func (t * componentAccountTransformer ) createAccount (transCtx * componentTransformContext ,
121121 dag * graph.DAG , graphCli model.GraphClient , account synthesizedSystemAccount ) error {
122- secret , err := t .buildAccountSecret (transCtx , transCtx . SynthesizeComponent , account )
122+ secret , err := t .buildAccountSecret (transCtx , account )
123123 if err != nil {
124124 return err
125125 }
@@ -137,7 +137,7 @@ func (t *componentAccountTransformer) deleteAccount(transCtx *componentTransform
137137
138138func (t * componentAccountTransformer ) updateAccount (transCtx * componentTransformContext ,
139139 dag * graph.DAG , graphCli model.GraphClient , account synthesizedSystemAccount , running * corev1.Secret ) error {
140- secret , err := t .buildAccountSecret (transCtx , transCtx . SynthesizeComponent , account )
140+ secret , err := t .buildAccountSecret (transCtx , account )
141141 if err != nil {
142142 return err
143143 }
@@ -175,34 +175,36 @@ func (t *componentAccountTransformer) buildAccountHash(account synthesizedSystem
175175 return signatureSystemAccountPassword (secret )
176176}
177177
178- func (t * componentAccountTransformer ) buildAccountSecret (ctx * componentTransformContext ,
179- synthesizeComp * component.SynthesizedComponent , account synthesizedSystemAccount ) (* corev1.Secret , error ) {
178+ func (t * componentAccountTransformer ) buildAccountSecret (transCtx * componentTransformContext , account synthesizedSystemAccount ) (* corev1.Secret , error ) {
180179 var password []byte
181180 var err error
182181 switch {
183182 case account .SecretRef != nil :
184- if password , err = t .getPasswordFromSecret (ctx , account ); err != nil {
183+ if password , err = t .getPasswordFromSecret (transCtx , account ); err != nil {
185184 return nil , err
186185 }
187186 default :
188- password , err = t .buildPassword (ctx , account )
187+ password , err = t .buildPassword (transCtx , account )
189188 if err != nil {
190189 return nil , err
191190 }
192191 }
193192 if len (password ) > maximumPasswordLength {
194193 return nil , errPasswordTooLong
195194 }
196- return t .buildAccountSecretWithPassword (ctx , synthesizeComp , account , password )
195+ return t .buildAccountSecretWithPassword (transCtx , account , password )
197196}
198197
199- func (t * componentAccountTransformer ) getPasswordFromSecret (ctx graph. TransformContext , account synthesizedSystemAccount ) ([]byte , error ) {
198+ func (t * componentAccountTransformer ) getPasswordFromSecret (transCtx * componentTransformContext , account synthesizedSystemAccount ) ([]byte , error ) {
200199 secretKey := types.NamespacedName {
201200 Namespace : account .SecretRef .Namespace ,
202201 Name : account .SecretRef .Name ,
203202 }
203+ if len (secretKey .Namespace ) == 0 {
204+ secretKey .Namespace = transCtx .SynthesizeComponent .Namespace
205+ }
204206 secret := & corev1.Secret {}
205- if err := ctx .GetClient ().Get (ctx .GetContext (), secretKey , secret ); err != nil {
207+ if err := transCtx .GetClient ().Get (transCtx .GetContext (), secretKey , secret ); err != nil {
206208 return nil , err
207209 }
208210
@@ -216,17 +218,18 @@ func (t *componentAccountTransformer) getPasswordFromSecret(ctx graph.TransformC
216218 return secret .Data [passwordKey ], nil
217219}
218220
219- func (t * componentAccountTransformer ) buildPassword (ctx * componentTransformContext , account synthesizedSystemAccount ) ([]byte , error ) {
221+ func (t * componentAccountTransformer ) buildPassword (transCtx * componentTransformContext , account synthesizedSystemAccount ) ([]byte , error ) {
222+ synthesizedComp := transCtx .SynthesizeComponent
220223 // get restore password if exists during recovery.
221- password , err := appsutil .GetRestoreSystemAccountPassword (ctx .Context , ctx .Client ,
222- ctx . SynthesizeComponent . Annotations , ctx . SynthesizeComponent .Name , account .Name )
224+ password , err := appsutil .GetRestoreSystemAccountPassword (transCtx .Context , transCtx .Client ,
225+ synthesizedComp . Annotations , synthesizedComp .Name , account .Name )
223226 if err != nil {
224- return nil , fmt .Errorf ("failed to restore password for system account %s of component %s from annotation, err: %w" , account .Name , ctx . SynthesizeComponent .Name , err )
227+ return nil , fmt .Errorf ("failed to restore password for system account %s of component %s from annotation, err: %w" , account .Name , synthesizedComp .Name , err )
225228 }
226229 if account .InitAccount && len (password ) == 0 {
227- // initAccount can also restore from factory.GetRestoreSystemAccountPassword(ctx.SynthesizeComponent , account).
230+ // initAccount can also restore from factory.GetRestoreSystemAccountPassword(synthesizedComp , account).
228231 // This is compatibility processing.
229- password = []byte (factory .GetRestorePassword (ctx . SynthesizeComponent ))
232+ password = []byte (factory .GetRestorePassword (synthesizedComp ))
230233 }
231234 if len (password ) == 0 {
232235 password , err := common .GeneratePasswordByConfig (account .PasswordGenerationPolicy )
@@ -236,16 +239,17 @@ func (t *componentAccountTransformer) buildPassword(ctx *componentTransformConte
236239}
237240
238241func (t * componentAccountTransformer ) buildAccountSecretWithPassword (ctx * componentTransformContext ,
239- synthesizeComp * component.SynthesizedComponent , account synthesizedSystemAccount , password []byte ) (* corev1.Secret , error ) {
240- secretName := constant .GenerateAccountSecretName (synthesizeComp .ClusterName , synthesizeComp .Name , account .Name )
241- secret := builder .NewSecretBuilder (synthesizeComp .Namespace , secretName ).
242+ account synthesizedSystemAccount , password []byte ) (* corev1.Secret , error ) {
243+ synthesizedComp := ctx .SynthesizeComponent
244+ secretName := constant .GenerateAccountSecretName (synthesizedComp .ClusterName , synthesizedComp .Name , account .Name )
245+ secret := builder .NewSecretBuilder (synthesizedComp .Namespace , secretName ).
242246 // Priority: static < dynamic < built-in
243- AddLabelsInMap (synthesizeComp .StaticLabels ).
244- AddLabelsInMap (synthesizeComp .DynamicLabels ).
245- AddLabelsInMap (constant .GetCompLabels (synthesizeComp .ClusterName , synthesizeComp .Name )).
247+ AddLabelsInMap (synthesizedComp .StaticLabels ).
248+ AddLabelsInMap (synthesizedComp .DynamicLabels ).
249+ AddLabelsInMap (constant .GetCompLabels (synthesizedComp .ClusterName , synthesizedComp .Name )).
246250 AddLabels (systemAccountLabel , account .Name ).
247- AddAnnotationsInMap (synthesizeComp .StaticAnnotations ).
248- AddAnnotationsInMap (synthesizeComp .DynamicAnnotations ).
251+ AddAnnotationsInMap (synthesizedComp .StaticAnnotations ).
252+ AddAnnotationsInMap (synthesizedComp .DynamicAnnotations ).
249253 PutData (constant .AccountNameForSecret , []byte (account .Name )).
250254 PutData (constant .AccountPasswdForSecret , password ).
251255 // SetImmutable(true).
0 commit comments