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 14, 2021
1 parent f236f03 commit 3a1a3de
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/internal/testing/controlplane/plane.go
Expand Up @@ -48,13 +48,20 @@ type ControlPlane struct {

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

defer func() {
if !success {
f.Etcd.Stop()
}
}()

if f.APIServer == nil {
f.APIServer = &APIServer{}
}
Expand All @@ -63,6 +70,12 @@ func (f *ControlPlane) Start() error {
return err
}

defer func() {
if !success {
f.APIServer.Stop()
}
}()

// provision the default user -- can be removed when the related
// methods are removed. The default user has admin permissions to
// mimic legacy no-authz setups.
Expand All @@ -76,6 +89,8 @@ func (f *ControlPlane) Start() error {
}
f.defaultUserCfg = user.Config()
f.defaultUserKubectl = kubectl

success = true
return nil
}

Expand Down

0 comments on commit 3a1a3de

Please sign in to comment.