feat(helm): return all errors that occured during uninstall

During the uninstall process all errors that occured will be bundled up into a new error struct `uninstallError` and be returned.
This change only really affects the SDK as the CLI will still only surface the top level error as it currently does.

Closes #12782

Signed-off-by: Travis Leeden <travis.leeden@octopus.com>
pull/12806/head
Travis Leeden 2 years ago
parent c7f318ca4c
commit 30b57140c1

@ -47,6 +47,11 @@ type Uninstall struct {
Description string
}
type uninstallError struct {
error
uninstallErrors []error
}
// NewUninstall creates a new Uninstall object with the given configuration.
func NewUninstall(cfg *Configuration) *Uninstall {
return &Uninstall{
@ -122,7 +127,7 @@ func (u *Uninstall) Run(name string) (*release.UninstallReleaseResponse, error)
deletedResources, kept, errs := u.deleteRelease(rel)
if errs != nil {
u.cfg.Log("uninstall: Failed to delete release: %s", errs)
return nil, errors.Errorf("failed to delete release: %s", name)
return nil, uninstallError{error: errors.Errorf("failed to delete release: %s", name), uninstallErrors: errs}
}
if kept != "" {
@ -160,7 +165,7 @@ func (u *Uninstall) Run(name string) (*release.UninstallReleaseResponse, error)
// Return the errors that occurred while deleting the release, if any
if len(errs) > 0 {
return res, errors.Errorf("uninstallation completed with %d error(s): %s", len(errs), joinErrors(errs))
return res, uninstallError{error: errors.Errorf("uninstallation completed with %d error(s): %s", len(errs), joinErrors(errs)), uninstallErrors: errs}
}
return res, nil
@ -171,7 +176,7 @@ func (u *Uninstall) Run(name string) (*release.UninstallReleaseResponse, error)
}
if len(errs) > 0 {
return res, errors.Errorf("uninstallation completed with %d error(s): %s", len(errs), joinErrors(errs))
return res, uninstallError{error: errors.Errorf("uninstallation completed with %d error(s): %s", len(errs), joinErrors(errs)), uninstallErrors: errs}
}
return res, nil
}

@ -138,3 +138,43 @@ func TestUninstallRelease_Cascade(t *testing.T) {
is.Error(err)
is.Contains(err.Error(), "failed to delete release: come-fail-away")
}
func TestUninstallRelease_ReturnsAllErrors(t *testing.T) {
is := assert.New(t)
unAction := uninstallAction(t)
unAction.DisableHooks = true
unAction.DryRun = false
unAction.Wait = false
unAction.DeletionPropagation = "foreground"
rel := releaseStub()
rel.Name = "come-fail-away"
rel.Manifest = `{
"apiVersion": "v1",
"kind": "Secret",
"metadata": {
"name": "secret"
},
"type": "Opaque",
"data": {
"password": "password"
}
}`
unAction.cfg.Releases.Create(rel)
failer := unAction.cfg.KubeClient.(*kubefake.FailingKubeClient)
failer.DeleteWithPropagationError = fmt.Errorf("uninstall error")
failer.BuildDummy = true
unAction.cfg.KubeClient = failer
_, err := unAction.Run(rel.Name)
is.Error(err)
is.Contains(err.Error(), "failed to delete release: come-fail-away")
uninstallErr, ok := err.(uninstallError)
if !ok {
t.Errorf("Expected returned error to be of type uninstallError: got %v(%T)", err, err)
}
is.Len(uninstallErr.uninstallErrors, 1)
is.Contains(uninstallErr.uninstallErrors[0].Error(), "uninstall error")
}

Loading…
Cancel
Save