Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Cleanup if envtest controlplane fails to start #1750

Merged
merged 1 commit into from Jan 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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