9
9
"log"
10
10
"os"
11
11
"path/filepath"
12
+ "sync"
12
13
13
14
"github.com/jumppad-labs/hclconfig"
14
15
hclerrors "github.com/jumppad-labs/hclconfig/errors"
@@ -43,18 +44,20 @@ type Engine interface {
43
44
44
45
// EngineImpl is responsible for creating and destroying resources
45
46
type EngineImpl struct {
46
- providers config.Providers
47
- log logger.Logger
48
- config * hclconfig.Config
49
- ctx context.Context
50
- force bool
47
+ providers config.Providers
48
+ log logger.Logger
49
+ config * hclconfig.Config
50
+ ctx context.Context
51
+ force bool
52
+ cacheMutex sync.Mutex
51
53
}
52
54
53
55
// New creates a new Jumppad engine
54
56
func New (p config.Providers , l logger.Logger ) (Engine , error ) {
55
57
e := & EngineImpl {}
56
58
e .log = l
57
59
e .providers = p
60
+ e .cacheMutex = sync.Mutex {}
58
61
59
62
// Set the standard writer to our logger as the DAG uses the standard library log.
60
63
log .SetOutput (l .StandardWriter ())
@@ -534,6 +537,7 @@ func (e *EngineImpl) createCallback(r types.Resource) error {
534
537
// to the network and set the dependency
535
538
if r .Metadata ().Type == network .TypeNetwork && r .Metadata ().Properties [constants .PropertyStatus ] == constants .StatusCreated {
536
539
// get the image cache
540
+ e .cacheMutex .Lock ()
537
541
ic , err := e .config .FindResource ("resource.image_cache.default" )
538
542
if err == nil {
539
543
e .log .Debug ("Attaching image cache to network" , "network" , ic .Metadata ().ID )
@@ -545,10 +549,12 @@ func (e *EngineImpl) createCallback(r types.Resource) error {
545
549
} else {
546
550
e .log .Error ("Unable to find Image Cache" , "error" , err )
547
551
}
552
+ e .cacheMutex .Unlock ()
548
553
}
549
554
550
555
if r .Metadata ().Type == cache .TypeRegistry && r .Metadata ().Properties [constants .PropertyStatus ] == constants .StatusCreated {
551
556
// get the image cache
557
+ e .cacheMutex .Lock ()
552
558
ic , err := e .config .FindResource ("resource.image_cache.default" )
553
559
if err == nil {
554
560
// append the registry if not all ready present and not in the default list
@@ -570,11 +576,13 @@ func (e *EngineImpl) createCallback(r types.Resource) error {
570
576
ic .(* cache.ImageCache ).Registries = append (ic .(* cache.ImageCache ).Registries , * r .(* cache.Registry ))
571
577
}
572
578
573
- e .log .Debug ("Adding registy to image cache" , "registry" , r .(* cache.Registry ).Hostname )
579
+ e .log .Debug ("Adding registry to image cache" , "registry" , r .(* cache.Registry ).Hostname )
574
580
575
581
// we now need to stop and restart the container to pick up the new registry changes
576
582
np := e .providers .GetProvider (ic )
577
583
584
+ e .cacheMutex .Unlock ()
585
+
578
586
err := np .Destroy (e .ctx , e .force )
579
587
if err != nil {
580
588
e .log .Error ("Unable to destroy Image Cache" , "error" , err )
0 commit comments