Skip to content

Commit 3a1a3de

Browse files
committed
Cleanup if envtest controlplane fails to start
Currently if the api server fails to start etcd process will be up the next time ControlPlane.Start() is called, they will both have the same listening address which will make the new etcd instance fail to start. The controlplane object will also be in an incomplete state so calling ControlPlane.Close() will panic.
1 parent f236f03 commit 3a1a3de

File tree

1 file changed

+15
-0
lines changed
  • pkg/internal/testing/controlplane

1 file changed

+15
-0
lines changed

pkg/internal/testing/controlplane/plane.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,20 @@ type ControlPlane struct {
4848

4949
// Start will start your control plane processes. To stop them, call Stop().
5050
func (f *ControlPlane) Start() error {
51+
success := false
5152
if f.Etcd == nil {
5253
f.Etcd = &Etcd{}
5354
}
5455
if err := f.Etcd.Start(); err != nil {
5556
return err
5657
}
5758

59+
defer func() {
60+
if !success {
61+
f.Etcd.Stop()
62+
}
63+
}()
64+
5865
if f.APIServer == nil {
5966
f.APIServer = &APIServer{}
6067
}
@@ -63,6 +70,12 @@ func (f *ControlPlane) Start() error {
6370
return err
6471
}
6572

73+
defer func() {
74+
if !success {
75+
f.APIServer.Stop()
76+
}
77+
}()
78+
6679
// provision the default user -- can be removed when the related
6780
// methods are removed. The default user has admin permissions to
6881
// mimic legacy no-authz setups.
@@ -76,6 +89,8 @@ func (f *ControlPlane) Start() error {
7689
}
7790
f.defaultUserCfg = user.Config()
7891
f.defaultUserKubectl = kubectl
92+
93+
success = true
7994
return nil
8095
}
8196

0 commit comments

Comments
 (0)