Skip to content

Commit

Permalink
Merge pull request #1750 from ficoos/clean-failed-start
Browse files Browse the repository at this point in the history
🐛 Cleanup if envtest controlplane fails to start
  • Loading branch information
k8s-ci-robot committed Jan 4, 2022
2 parents 46179a0 + 6690783 commit e52a8b1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 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 All @@ -88,6 +98,7 @@ func (f *ControlPlane) Stop() error {
errList = append(errList, err)
}
}

if f.Etcd != nil {
if err := f.Etcd.Stop(); err != nil {
errList = append(errList, err)
Expand Down

0 comments on commit e52a8b1

Please sign in to comment.