@@ -46,11 +46,19 @@ var (
4646 defaultStackMountPrefix = ast .DefaultRootRef .Append (ast .StringTerm ("stacks" ))
4747)
4848
49+ type TenantName struct {
50+ Tenant , Name string
51+ }
52+
53+ func (tn * TenantName ) String () string {
54+ return tn .Tenant + ":" + tn .Name
55+ }
56+
4957type Service struct {
5058 config * config.Root
5159 persistenceDir string
5260 pool * pool.Pool
53- workers map [string ]* BundleWorker
61+ workers map [TenantName ]* BundleWorker
5462 readyMutex sync.Mutex
5563 ready bool
5664 failures map [string ]Status
@@ -111,7 +119,7 @@ type Status struct {
111119func New () * Service {
112120 return & Service {
113121 pool : pool .New (10 ),
114- workers : make (map [string ]* BundleWorker ),
122+ workers : make (map [TenantName ]* BundleWorker ),
115123 failures : make (map [string ]Status ),
116124 noninteractive : true ,
117125 migrateDB : false ,
@@ -129,11 +137,11 @@ func (s *Service) WithConfig(config *config.Root) *Service {
129137 s .config = config
130138 s .database = * s .database .WithConfig (config .Database )
131139 if s .config .Service != nil {
132- if s .config .Service .ReconfigurationInterval != nil {
133- s .reconfigurationInterval = * s .config .Service .ReconfigurationInterval
140+ if s .config .Service .ReconfigurationInterval != 0 {
141+ s .reconfigurationInterval = time . Duration ( s .config .Service .ReconfigurationInterval )
134142 }
135- if s .config .Service .BundleRebuildInterval != nil {
136- s .buildInterval = * s .config .Service .BundleRebuildInterval
143+ if s .config .Service .BundleRebuildInterval != 0 {
144+ s .buildInterval = time . Duration ( s .config .Service .BundleRebuildInterval )
137145 }
138146 }
139147 return s
@@ -220,6 +228,8 @@ shutdown:
220228 for _ , w := range s .workers {
221229 s .report .Bundles [w .bundleConfig .Name ] = w .status
222230 }
231+
232+ // For singleshot, we don't need to worry about tenants:
223233 maps .Copy (s .report .Bundles , s .failures )
224234 }
225235
@@ -230,9 +240,10 @@ func (s *Service) Report() *Report {
230240 return s .report
231241}
232242
233- func (s * Service ) Trigger (ctx context.Context , principal , name string ) error {
243+ func (s * Service ) Trigger (ctx context.Context , principal , tenant , name string ) error {
234244 a := authz.Access {
235245 Principal : principal ,
246+ Tenant : tenant ,
236247 Resource : "bundles" ,
237248 Permission : "bundles.trigger" ,
238249 Name : name ,
@@ -241,7 +252,7 @@ func (s *Service) Trigger(ctx context.Context, principal, name string) error {
241252 return err
242253 }
243254
244- err := s .pool .Trigger (name )
255+ err := s .pool .Trigger (tenant , name )
245256 if err != nil {
246257 s .log .Errorf ("trigger bundle build for %s: %v" , name , err )
247258 } else {
@@ -316,9 +327,9 @@ func (s *Service) launchWorkers(ctx context.Context) {
316327 return
317328 }
318329
319- activeBundles := make (map [string ]struct {})
330+ activeBundles := make (map [TenantName ]struct {})
320331 for _ , b := range bundles {
321- bName := tenant + "_" + b .Name
332+ bName := TenantName { Tenant : tenant , Name : b .Name }
322333 activeBundles [bName ] = struct {}{}
323334 }
324335
@@ -353,7 +364,7 @@ func (s *Service) launchWorkers(ctx context.Context) {
353364 failures := make (map [string ]Status )
354365
355366 for _ , b := range bundles {
356- bName := tenant + "_" + b .Name
367+ bName := TenantName { Tenant : tenant , Name : b .Name }
357368 if w , ok := s .workers [bName ]; ok {
358369 w .UpdateConfig (b , sourceDefs , stacks )
359370 continue
@@ -392,7 +403,7 @@ func (s *Service) launchWorkers(ctx context.Context) {
392403
393404 syncs := []Synchronizer {}
394405 sources := []* builder.Source {& root .Source }
395- bundleDir := join (s .persistenceDir , md5sum (bName ))
406+ bundleDir := join (s .persistenceDir , md5sum (bName . String () ))
396407
397408 for _ , dep := range deps {
398409 // NB(sr): dep.Name could contain a `:` which cause build errors in OPA's bundle build machinery
@@ -421,7 +432,7 @@ func (s *Service) launchWorkers(ctx context.Context) {
421432 WithStorage (storage ).
422433 WithInterval (b .Interval ).
423434 WithSingleShot (s .singleShot )
424- s .pool .Add (b .Name , w .Execute ) // TODO(sr): name not unique
435+ s .pool .Add (tenant , b .Name , w .Execute )
425436
426437 s .workers [bName ] = w
427438 }
0 commit comments