Skip to content

Commit e52a8b1

Browse files
authored
Merge pull request #1750 from ficoos/clean-failed-start
🐛 Cleanup if envtest controlplane fails to start
2 parents 46179a0 + 6690783 commit e52a8b1

File tree

1 file changed

+12
-1
lines changed
  • pkg/internal/testing/controlplane

1 file changed

+12
-1
lines changed

pkg/internal/testing/controlplane/plane.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,18 @@ type ControlPlane struct {
4747
}
4848

4949
// Start will start your control plane processes. To stop them, call Stop().
50-
func (f *ControlPlane) Start() error {
50+
func (f *ControlPlane) Start() (retErr error) {
5151
if f.Etcd == nil {
5252
f.Etcd = &Etcd{}
5353
}
5454
if err := f.Etcd.Start(); err != nil {
5555
return err
5656
}
57+
defer func() {
58+
if retErr != nil {
59+
_ = f.Etcd.Stop()
60+
}
61+
}()
5762

5863
if f.APIServer == nil {
5964
f.APIServer = &APIServer{}
@@ -62,6 +67,11 @@ func (f *ControlPlane) Start() error {
6267
if err := f.APIServer.Start(); err != nil {
6368
return err
6469
}
70+
defer func() {
71+
if retErr != nil {
72+
_ = f.APIServer.Stop()
73+
}
74+
}()
6575

6676
// provision the default user -- can be removed when the related
6777
// methods are removed. The default user has admin permissions to
@@ -88,6 +98,7 @@ func (f *ControlPlane) Stop() error {
8898
errList = append(errList, err)
8999
}
90100
}
101+
91102
if f.Etcd != nil {
92103
if err := f.Etcd.Stop(); err != nil {
93104
errList = append(errList, err)

0 commit comments

Comments
 (0)