diff --git a/pkg/internal/testing/controlplane/plane.go b/pkg/internal/testing/controlplane/plane.go index 36fd3c6306..733ea11b54 100644 --- a/pkg/internal/testing/controlplane/plane.go +++ b/pkg/internal/testing/controlplane/plane.go @@ -48,6 +48,7 @@ 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{} } @@ -55,6 +56,12 @@ func (f *ControlPlane) Start() error { return err } + defer func() { + if !success { + f.Etcd.Stop() + } + }() + if f.APIServer == nil { f.APIServer = &APIServer{} } @@ -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. @@ -76,6 +89,8 @@ func (f *ControlPlane) Start() error { } f.defaultUserCfg = user.Config() f.defaultUserKubectl = kubectl + + success = true return nil }