@@ -12,14 +12,13 @@ import (
12
12
)
13
13
14
14
type VM struct {
15
- ident string
16
- env map [string ]string
17
- resourceModifier * resourcemodifier.Modifier
18
- backgroundCtxWithSpan context.Context
19
- runningVMCtx context.Context
20
- runningVMCtxCancel context.CancelFunc
21
- wg sync.WaitGroup
22
- errChan chan error
15
+ ident string
16
+ env map [string ]string
17
+ resourceModifier * resourcemodifier.Modifier
18
+ runningVMCtx context.Context
19
+ runningVMCtxCancel context.CancelFunc
20
+ wg sync.WaitGroup
21
+ errChan chan error
23
22
}
24
23
25
24
func NewVMClonedFrom (
@@ -31,18 +30,17 @@ func NewVMClonedFrom(
31
30
resourceModifier * resourcemodifier.Modifier ,
32
31
logger * echelon.Logger ,
33
32
) (* VM , error ) {
34
- backgroundCtxWithSpan := trace . ContextWithSpan ( context .Background (), trace . SpanFromContext ( ctx ))
35
-
36
- runningVMCtx , runningVMCtxCancel := context . WithCancel ( backgroundCtxWithSpan )
33
+ runningVMCtx , runningVMCtxCancel := context .WithCancel (
34
+ trace . ContextWithSpan ( context . Background (), trace . SpanFromContext ( ctx )),
35
+ )
37
36
38
37
vm := & VM {
39
- ident : to ,
40
- env : env ,
41
- resourceModifier : resourceModifier ,
42
- backgroundCtxWithSpan : backgroundCtxWithSpan ,
43
- runningVMCtx : runningVMCtx ,
44
- runningVMCtxCancel : runningVMCtxCancel ,
45
- errChan : make (chan error , 1 ),
38
+ ident : to ,
39
+ env : env ,
40
+ resourceModifier : resourceModifier ,
41
+ runningVMCtx : runningVMCtx ,
42
+ runningVMCtxCancel : runningVMCtxCancel ,
43
+ errChan : make (chan error , 1 ),
46
44
}
47
45
48
46
pullLogger := logger .Scoped ("pull virtual machine" )
@@ -175,14 +173,16 @@ func (vm *VM) RetrieveIP(ctx context.Context) (string, error) {
175
173
}
176
174
177
175
func (vm * VM ) Close () error {
176
+ ctx := trace .ContextWithSpan (context .Background (), trace .SpanFromContext (vm .runningVMCtx ))
177
+
178
178
// Try to gracefully terminate the VM
179
179
//nolint:dogsled // not interested in the output for now
180
- _ , _ , _ = Cmd (vm . backgroundCtxWithSpan , vm .env , "stop" , "--timeout" , "5" , vm .ident )
180
+ _ , _ , _ = Cmd (ctx , vm .env , "stop" , "--timeout" , "5" , vm .ident )
181
181
182
182
vm .runningVMCtxCancel ()
183
183
vm .wg .Wait ()
184
184
185
- _ , _ , err := Cmd (vm . backgroundCtxWithSpan , vm .env , "delete" , vm .ident )
185
+ _ , _ , err := Cmd (ctx , vm .env , "delete" , vm .ident )
186
186
187
187
return err
188
188
}
0 commit comments