Skip to content

Commit

Permalink
Cleanup if envtest controlplane fails to start
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ficoos committed Dec 16, 2021
1 parent f236f03 commit a17412b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/internal/testing/controlplane/plane.go
Expand Up @@ -47,13 +47,18 @@ type ControlPlane struct {
}

// Start will start your control plane processes. To stop them, call Stop().
func (f *ControlPlane) Start() error {
func (f *ControlPlane) Start() (retErr error) {
if f.Etcd == nil {
f.Etcd = &Etcd{}
}
if err := f.Etcd.Start(); err != nil {
return err
}
defer func() {
if retErr != nil {
f.Etcd.Stop()
}
}()

if f.APIServer == nil {
f.APIServer = &APIServer{}
Expand All @@ -62,6 +67,11 @@ func (f *ControlPlane) Start() error {
if err := f.APIServer.Start(); err != nil {
return err
}
defer func() {
if retErr != nil {
f.APIServer.Stop()
}
}()

// provision the default user -- can be removed when the related
// methods are removed. The default user has admin permissions to
Expand Down

0 comments on commit a17412b

Please sign in to comment.