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
feat(*): add installation delete options/flags to relevant commands #1189
Merged
carolynvs
merged 11 commits into
getporter:main
from
vdice:feat/the-life-changing-magic-of-tidying-up-installations
Aug 19, 2020
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
30e8fb1
feat(*): add installation delete options/flags to relevant commands
vdice 1e0c21e
Apply suggestions from code review
vdice 222b196
incorporate add'l review feedback
vdice ba43169
add'l review feedback
vdice b77e8c2
refactor the parent/dep uninstall scenarios
vdice 6c64917
update dependencies_test.go
vdice 4b2b647
use BundleAction interface to enable action-specific options when exe…
vdice 353dfd5
ref(tests/dependencies_test.go): set mysql dep namespace param as well
vdice 7f5b60c
fix cmd example spacing
vdice 27f00be
add comments around uninstallOpts when empty
vdice 97a31c4
remove ToActionArgs from BundleAction interface
vdice File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
title: "porter installations delete" | ||
slug: porter_installations_delete | ||
url: /cli/porter_installations_delete/ | ||
--- | ||
## porter installations delete | ||
|
||
Delete an installation | ||
|
||
### Synopsis | ||
|
||
Deletes all records and outputs associated with an installation | ||
|
||
``` | ||
porter installations delete [INSTALLATION] [flags] | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
porter installation delete | ||
porter installation delete wordpress | ||
porter installation delete --force | ||
|
||
``` | ||
|
||
### Options | ||
|
||
``` | ||
--force Force a delete the installation, regardless of last completed action | ||
-h, --help help for delete | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--debug Enable debug logging | ||
--debug-plugins Enable plugin debug logging | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [porter installations](/cli/porter_installations/) - Installation commands | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package porter | ||
|
||
import ( | ||
"fmt" | ||
|
||
"get.porter.sh/porter/pkg/context" | ||
claims "github.com/cnabio/cnab-go/claim" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
const installationDeleteTmpl = "deleting installation records for %s...\n" | ||
|
||
var ( | ||
// ErrUnsafeInstallationDelete warns the user that deletion of an unsuccessfully uninstalled installation is unsafe | ||
ErrUnsafeInstallationDelete = errors.New("it is unsafe to delete an installation when the last action wasn't a successful uninstall") | ||
|
||
// ErrUnsafeInstallationDeleteRetryForce presents the ErrUnsafeInstallationDelete error and provides a retry option of --force | ||
ErrUnsafeInstallationDeleteRetryForce = fmt.Errorf("%s; if you are sure it should be deleted, retry the last command with the --force flag", ErrUnsafeInstallationDelete) | ||
) | ||
|
||
// DeleteOptions represent options for Porter's installation delete command | ||
type DeleteOptions struct { | ||
sharedOptions | ||
Force bool | ||
} | ||
|
||
// Validate prepares for an installation delete action and validates the args/options. | ||
func (o *DeleteOptions) Validate(args []string, cxt *context.Context) error { | ||
// Ensure only one argument exists (installation name) if args length non-zero | ||
err := o.sharedOptions.validateInstallationName(args) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return o.sharedOptions.defaultBundleFiles(cxt) | ||
} | ||
|
||
// DeleteInstallation handles deletion of an installation | ||
func (p *Porter) DeleteInstallation(opts DeleteOptions) error { | ||
err := p.applyDefaultOptions(&opts.sharedOptions) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
installation, err := p.Claims.ReadInstallationStatus(opts.Name) | ||
if err != nil { | ||
return errors.Wrapf(err, "unable to read status for installation %s", opts.Name) | ||
} | ||
|
||
claim, err := installation.GetLastClaim() | ||
if err != nil { | ||
return errors.Wrapf(err, "unable to read most recent record for installation %s", opts.Name) | ||
} | ||
|
||
if (claim.Action != claims.ActionUninstall || installation.GetLastStatus() != claims.StatusSucceeded) && !opts.Force { | ||
return ErrUnsafeInstallationDeleteRetryForce | ||
} | ||
|
||
fmt.Fprintf(p.Out, installationDeleteTmpl, opts.Name) | ||
return p.Claims.DeleteInstallation(opts.Name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package porter | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cnabio/cnab-go/bundle" | ||
"github.com/cnabio/cnab-go/claim" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDeleteInstallation(t *testing.T) { | ||
testcases := []struct { | ||
name string | ||
lastAction string | ||
lastActionStatus string | ||
force bool | ||
installationRemains bool | ||
wantError string | ||
}{ | ||
{ | ||
name: "not yet installed", | ||
wantError: "unable to read status for installation test: Installation does not exist", | ||
}, { | ||
name: "last action not uninstall; no --force", | ||
lastAction: "install", | ||
lastActionStatus: claim.StatusSucceeded, | ||
installationRemains: true, | ||
wantError: ErrUnsafeInstallationDeleteRetryForce.Error(), | ||
}, { | ||
name: "last action failed uninstall; no --force", | ||
lastAction: "uninstall", | ||
lastActionStatus: claim.StatusFailed, | ||
installationRemains: true, | ||
wantError: ErrUnsafeInstallationDeleteRetryForce.Error(), | ||
}, { | ||
name: "last action not uninstall; --force", | ||
lastAction: "install", | ||
lastActionStatus: claim.StatusSucceeded, | ||
force: true, | ||
}, { | ||
name: "last action failed uninstall; --force", | ||
lastAction: "uninstall", | ||
lastActionStatus: claim.StatusFailed, | ||
force: true, | ||
}, | ||
} | ||
|
||
for _, tc := range testcases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
p := NewTestPorter(t) | ||
p.TestConfig.SetupPorterHome() | ||
|
||
var err error | ||
|
||
// Create test claim | ||
if tc.lastAction != "" { | ||
c := p.TestClaims.CreateClaim("test", tc.lastAction, bundle.Bundle{}, nil) | ||
carolynvs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_ = p.TestClaims.CreateResult(c, tc.lastActionStatus) | ||
} | ||
|
||
opts := DeleteOptions{} | ||
opts.Name = "test" | ||
opts.Force = tc.force | ||
|
||
err = p.DeleteInstallation(opts) | ||
if tc.wantError != "" { | ||
require.EqualError(t, err, tc.wantError) | ||
} else { | ||
require.NoError(t, err, "expected DeleteInstallation to succeed") | ||
} | ||
|
||
_, err = p.Claims.ReadInstallation("test") | ||
if tc.installationRemains { | ||
require.NoError(t, err, "expected installation to exist") | ||
} else { | ||
require.EqualError(t, err, "Installation does not exist") | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍