@@ -231,37 +231,7 @@ func (self *Bootstrapper) bootstrapTeam(ctx context.Context) error {
231231 }
232232 if teamCount > 0 {
233233 // Bootstrap registry secrets if needed
234- registries , err := self .repos .Ent ().Registry .Query ().All (ctx )
235- if err != nil {
236- return fmt .Errorf ("failed to query registries: %w" , err )
237- }
238- teams , err := self .repos .Ent ().Team .Query ().All (ctx )
239- if err != nil {
240- return fmt .Errorf ("failed to query teams: %w" , err )
241- }
242- for _ , reg := range registries {
243- for _ , team := range teams {
244- if reg .KubernetesSecret != "" {
245- // Check existence
246- secretName := reg .KubernetesSecret
247- _ , err := self .kubeClient .GetSecret (ctx , secretName , team .Namespace , self .kubeClient .GetInternalClient ())
248- if err != nil {
249- if ! errors .IsNotFound (err ) {
250- return fmt .Errorf ("failed to get secret %s in team namespace %s: %w" , secretName , team .Namespace , err )
251- }
252- }
253- if errors .IsNotFound (err ) {
254- // Copy
255- _ , err = self .kubeClient .CopySecret (ctx , secretName , self .cfg .SystemNamespace , team .Namespace , self .kubeClient .GetInternalClient ())
256- if err != nil {
257- log .Warnf ("Failed to copy registry secret %s to team namespace %s: %v" , secretName , team .Namespace , err )
258- }
259- }
260- }
261- }
262- }
263-
264- return nil
234+ return self .syncRegistrySecretsToTeams (ctx )
265235 }
266236
267237 // Create a team
@@ -349,6 +319,44 @@ func (self *Bootstrapper) bootstrapTeam(ctx context.Context) error {
349319 return err
350320 }
351321
322+ // Sync registry secrets to the newly created team
323+ return self .syncRegistrySecretsToTeams (ctx )
324+ }
325+
326+ // * Registry Team Sync
327+ func (self * Bootstrapper ) syncRegistrySecretsToTeams (ctx context.Context ) error {
328+ log .Infof ("Syncing registry secrets to teams" )
329+
330+ registries , err := self .repos .Ent ().Registry .Query ().All (ctx )
331+ if err != nil {
332+ return fmt .Errorf ("failed to query registries: %w" , err )
333+ }
334+ teams , err := self .repos .Ent ().Team .Query ().All (ctx )
335+ if err != nil {
336+ return fmt .Errorf ("failed to query teams: %w" , err )
337+ }
338+ for _ , reg := range registries {
339+ for _ , team := range teams {
340+ if reg .KubernetesSecret != "" {
341+ // Check existence
342+ secretName := reg .KubernetesSecret
343+ _ , err := self .kubeClient .GetSecret (ctx , secretName , team .Namespace , self .kubeClient .GetInternalClient ())
344+ if err != nil {
345+ if ! errors .IsNotFound (err ) {
346+ return fmt .Errorf ("failed to get secret %s in team namespace %s: %w" , secretName , team .Namespace , err )
347+ }
348+ }
349+ if errors .IsNotFound (err ) {
350+ // Copy
351+ _ , err = self .kubeClient .CopySecret (ctx , secretName , self .cfg .SystemNamespace , team .Namespace , self .kubeClient .GetInternalClient ())
352+ if err != nil {
353+ log .Warnf ("Failed to copy registry secret %s to team namespace %s: %v" , secretName , team .Namespace , err )
354+ }
355+ }
356+ }
357+ }
358+ }
359+
352360 return nil
353361}
354362
0 commit comments