44 "context"
55 "github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
66 devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
7+ "github.com/loft-sh/devspace/pkg/devspace/context/values"
78 "github.com/loft-sh/devspace/pkg/devspace/deploy"
89 "github.com/loft-sh/devspace/pkg/devspace/services/podreplace"
910 "github.com/loft-sh/devspace/pkg/util/lockfactory"
@@ -41,9 +42,6 @@ type Manager interface {
4142 // Close will close the manager and wait for all dev pods to stop
4243 Close ()
4344
44- // Context returns the context of the DevManager
45- Context () context.Context
46-
4745 // Wait will wait until all DevPods are stopped
4846 Wait () error
4947}
@@ -52,15 +50,12 @@ type devPodManager struct {
5250 lockFactory lockfactory.LockFactory
5351
5452 m sync.Mutex
55- ctx context.Context
5653 cancels []context.CancelFunc
5754 devPods map [string ]* devPod
5855}
5956
60- func NewManager (ctx context.Context ) Manager {
61- ctx , cancel := context .WithCancel (ctx )
57+ func NewManager (cancel context.CancelFunc ) Manager {
6258 return & devPodManager {
63- ctx : ctx ,
6459 cancels : []context.CancelFunc {cancel },
6560 lockFactory : lockfactory .NewDefaultLockFactory (),
6661 devPods : map [string ]* devPod {},
@@ -86,21 +81,18 @@ func (d *devPodManager) Close() {
8681 }
8782 d .cancels = []context.CancelFunc {}
8883 d .m .Unlock ()
89- d .Wait ()
90- }
91-
92- func (d * devPodManager ) Context () context.Context {
93- return d .ctx
84+ _ = d .Wait ()
9485}
9586
9687func (d * devPodManager ) StartMultiple (ctx * devspacecontext.Context , devPods []string , options Options ) error {
88+ devCtx , _ := values .DevContextFrom (ctx .Context )
9789 select {
98- case <- d . ctx .Done ():
99- return d . ctx .Err ()
90+ case <- devCtx .Done ():
91+ return devCtx .Err ()
10092 default :
10193 }
10294
103- cancelCtx , cancel := context .WithCancel (d . ctx )
95+ cancelCtx , cancel := context .WithCancel (devCtx )
10496 d .m .Lock ()
10597 d .cancels = append (d .cancels , cancel )
10698 d .m .Unlock ()
@@ -174,16 +166,17 @@ func (d *devPodManager) Start(originalContext *devspacecontext.Context, devPodCo
174166 var dp * devPod
175167 d .m .Lock ()
176168 dp = d .devPods [devPodConfig .Name ]
177- d .m .Unlock ()
178-
179- // check if already running
180169 if dp != nil {
181- return nil , DevPodAlreadyExists {}
170+ select {
171+ case <- dp .Done ():
172+ default :
173+ d .m .Unlock ()
174+ return nil , DevPodAlreadyExists {}
175+ }
182176 }
183177
184178 // create a new dev pod
185179 dp = newDevPod ()
186- d .m .Lock ()
187180 d .devPods [devPodConfig .Name ] = dp
188181 d .m .Unlock ()
189182
0 commit comments