@@ -108,7 +108,7 @@ func (t *componentAccountTransformer) Transform(ctx graph.TransformContext, dag
108108
109109func (t * componentAccountTransformer ) createAccount (transCtx * componentTransformContext ,
110110 dag * graph.DAG , graphCli model.GraphClient , account synthesizedSystemAccount ) error {
111- secret , err := t .buildAccountSecret (transCtx , transCtx . SynthesizeComponent , account )
111+ secret , err := t .buildAccountSecret (transCtx , account )
112112 if err != nil {
113113 return err
114114 }
@@ -126,7 +126,7 @@ func (t *componentAccountTransformer) deleteAccount(transCtx *componentTransform
126126
127127func (t * componentAccountTransformer ) updateAccount (transCtx * componentTransformContext ,
128128 dag * graph.DAG , graphCli model.GraphClient , account synthesizedSystemAccount , running * corev1.Secret ) error {
129- secret , err := t .buildAccountSecret (transCtx , transCtx . SynthesizeComponent , account )
129+ secret , err := t .buildAccountSecret (transCtx , account )
130130 if err != nil {
131131 return err
132132 }
@@ -164,34 +164,36 @@ func (t *componentAccountTransformer) buildAccountHash(account synthesizedSystem
164164 return signatureSystemAccountPassword (secret )
165165}
166166
167- func (t * componentAccountTransformer ) buildAccountSecret (ctx * componentTransformContext ,
168- synthesizeComp * component.SynthesizedComponent , account synthesizedSystemAccount ) (* corev1.Secret , error ) {
167+ func (t * componentAccountTransformer ) buildAccountSecret (transCtx * componentTransformContext , account synthesizedSystemAccount ) (* corev1.Secret , error ) {
169168 var password []byte
170169 var err error
171170 switch {
172171 case account .SecretRef != nil :
173- if password , err = t .getPasswordFromSecret (ctx , account ); err != nil {
172+ if password , err = t .getPasswordFromSecret (transCtx , account ); err != nil {
174173 return nil , err
175174 }
176175 default :
177- password , err = t .buildPassword (ctx , account )
176+ password , err = t .buildPassword (transCtx , account )
178177 if err != nil {
179178 return nil , err
180179 }
181180 }
182181 if len (password ) > maximumPasswordLength {
183182 return nil , errPasswordTooLong
184183 }
185- return t .buildAccountSecretWithPassword (ctx , synthesizeComp , account , password )
184+ return t .buildAccountSecretWithPassword (transCtx , account , password )
186185}
187186
188- func (t * componentAccountTransformer ) getPasswordFromSecret (ctx graph. TransformContext , account synthesizedSystemAccount ) ([]byte , error ) {
187+ func (t * componentAccountTransformer ) getPasswordFromSecret (transCtx * componentTransformContext , account synthesizedSystemAccount ) ([]byte , error ) {
189188 secretKey := types.NamespacedName {
190189 Namespace : account .SecretRef .Namespace ,
191190 Name : account .SecretRef .Name ,
192191 }
192+ if len (secretKey .Namespace ) == 0 {
193+ secretKey .Namespace = transCtx .SynthesizeComponent .Namespace
194+ }
193195 secret := & corev1.Secret {}
194- if err := ctx .GetClient ().Get (ctx .GetContext (), secretKey , secret ); err != nil {
196+ if err := transCtx .GetClient ().Get (transCtx .GetContext (), secretKey , secret ); err != nil {
195197 return nil , err
196198 }
197199
@@ -205,17 +207,18 @@ func (t *componentAccountTransformer) getPasswordFromSecret(ctx graph.TransformC
205207 return secret .Data [passwordKey ], nil
206208}
207209
208- func (t * componentAccountTransformer ) buildPassword (ctx * componentTransformContext , account synthesizedSystemAccount ) ([]byte , error ) {
210+ func (t * componentAccountTransformer ) buildPassword (transCtx * componentTransformContext , account synthesizedSystemAccount ) ([]byte , error ) {
211+ synthesizedComp := transCtx .SynthesizeComponent
209212 // get restore password if exists during recovery.
210- password , err := appsutil .GetRestoreSystemAccountPassword (ctx .Context , ctx .Client ,
211- ctx . SynthesizeComponent . Annotations , ctx . SynthesizeComponent .Name , account .Name )
213+ password , err := appsutil .GetRestoreSystemAccountPassword (transCtx .Context , transCtx .Client ,
214+ synthesizedComp . Annotations , synthesizedComp .Name , account .Name )
212215 if err != nil {
213- 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 )
216+ return nil , fmt .Errorf ("failed to restore password for system account %s of component %s from annotation, err: %w" , account .Name , synthesizedComp .Name , err )
214217 }
215218 if account .InitAccount && len (password ) == 0 {
216- // initAccount can also restore from factory.GetRestoreSystemAccountPassword(ctx.SynthesizeComponent , account).
219+ // initAccount can also restore from factory.GetRestoreSystemAccountPassword(synthesizedComp , account).
217220 // This is compatibility processing.
218- password = []byte (factory .GetRestorePassword (ctx . SynthesizeComponent ))
221+ password = []byte (factory .GetRestorePassword (synthesizedComp ))
219222 }
220223 if len (password ) == 0 {
221224 password , err := common .GeneratePasswordByConfig (account .PasswordGenerationPolicy )
@@ -225,16 +228,17 @@ func (t *componentAccountTransformer) buildPassword(ctx *componentTransformConte
225228}
226229
227230func (t * componentAccountTransformer ) buildAccountSecretWithPassword (ctx * componentTransformContext ,
228- synthesizeComp * component.SynthesizedComponent , account synthesizedSystemAccount , password []byte ) (* corev1.Secret , error ) {
229- secretName := constant .GenerateAccountSecretName (synthesizeComp .ClusterName , synthesizeComp .Name , account .Name )
230- secret := builder .NewSecretBuilder (synthesizeComp .Namespace , secretName ).
231+ account synthesizedSystemAccount , password []byte ) (* corev1.Secret , error ) {
232+ synthesizedComp := ctx .SynthesizeComponent
233+ secretName := constant .GenerateAccountSecretName (synthesizedComp .ClusterName , synthesizedComp .Name , account .Name )
234+ secret := builder .NewSecretBuilder (synthesizedComp .Namespace , secretName ).
231235 // Priority: static < dynamic < built-in
232- AddLabelsInMap (synthesizeComp .StaticLabels ).
233- AddLabelsInMap (synthesizeComp .DynamicLabels ).
234- AddLabelsInMap (constant .GetCompLabels (synthesizeComp .ClusterName , synthesizeComp .Name )).
236+ AddLabelsInMap (synthesizedComp .StaticLabels ).
237+ AddLabelsInMap (synthesizedComp .DynamicLabels ).
238+ AddLabelsInMap (constant .GetCompLabels (synthesizedComp .ClusterName , synthesizedComp .Name )).
235239 AddLabels (systemAccountLabel , account .Name ).
236- AddAnnotationsInMap (synthesizeComp .StaticAnnotations ).
237- AddAnnotationsInMap (synthesizeComp .DynamicAnnotations ).
240+ AddAnnotationsInMap (synthesizedComp .StaticAnnotations ).
241+ AddAnnotationsInMap (synthesizedComp .DynamicAnnotations ).
238242 PutData (constant .AccountNameForSecret , []byte (account .Name )).
239243 PutData (constant .AccountPasswdForSecret , password ).
240244 // SetImmutable(true).
0 commit comments