-
Notifications
You must be signed in to change notification settings - Fork 274
Add kn revision delete command #207
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5977d83
Adds kn revision delete command
navidshaikh 2b70903
Adds unit tests for revision delete command
navidshaikh c2d9b96
Adds integration tests for revision delete command
navidshaikh 9805bb3
Removes extra line and renames an import alias
navidshaikh 2debc55
Adds 10 seconds sleep between service create and revision delete
navidshaikh 8c8703e
Clean up imports
navidshaikh ac84611
Removes the pause after service create
navidshaikh 74d8c06
Updates testing output strings in unit and e2e
navidshaikh adc2704
Updates post goimports on hack and test dirs
navidshaikh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,38 @@ | ||
| ## kn revision delete | ||
|
|
||
| Delete a revision. | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Delete a revision. | ||
|
|
||
| ``` | ||
| kn revision delete NAME [flags] | ||
| ``` | ||
|
|
||
| ### Examples | ||
|
|
||
| ``` | ||
|
|
||
| # Delete a revision 'svc1-abcde' in default namespace | ||
| kn revision delete svc1-abcde | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help help for delete | ||
| -n, --namespace string List the requested object(s) in given namespace. | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| --config string config file (default is $HOME/.kn/config.yaml) | ||
| --kubeconfig string kubectl config file (default is $HOME/.kube/config) | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [kn revision](kn_revision.md) - Revision command group | ||
|
|
This file contains hidden or 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 hidden or 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,59 @@ | ||
| // Copyright © 2019 The Knative Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package revision | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/knative/client/pkg/kn/commands" | ||
| "github.com/spf13/cobra" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| // NewRevisionDeleteCommand represent 'revision delete' command | ||
| func NewRevisionDeleteCommand(p *commands.KnParams) *cobra.Command { | ||
| RevisionDeleteCommand := &cobra.Command{ | ||
| Use: "delete NAME", | ||
| Short: "Delete a revision.", | ||
| Example: ` | ||
| # Delete a revision 'svc1-abcde' in default namespace | ||
| kn revision delete svc1-abcde`, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if len(args) != 1 { | ||
| return errors.New("'revision delete' requires the revision name given as single argument") | ||
| } | ||
| client, err := p.ServingFactory() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| namespace, err := p.GetNamespace(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| err = client.Revisions(namespace).Delete( | ||
| args[0], | ||
| &metav1.DeleteOptions{}, | ||
| ) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| fmt.Fprintf(cmd.OutOrStdout(), "Revision '%s' successfully deleted in namespace '%s'.\n", args[0], namespace) | ||
|
navidshaikh marked this conversation as resolved.
|
||
| return nil | ||
| }, | ||
| } | ||
| commands.AddNamespaceFlags(RevisionDeleteCommand.Flags(), false) | ||
| return RevisionDeleteCommand | ||
| } | ||
This file contains hidden or 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,59 @@ | ||
| // Copyright © 2019 The Knative Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package revision | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/knative/client/pkg/kn/commands" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| client_testing "k8s.io/client-go/testing" | ||
| ) | ||
|
|
||
| func fakeRevisionDelete(args []string) (action client_testing.Action, name string, output string, err error) { | ||
| knParams := &commands.KnParams{} | ||
| cmd, fakeServing, buf := commands.CreateTestKnCommand(NewRevisionCommand(knParams), knParams) | ||
| fakeServing.AddReactor("delete", "revisions", | ||
| func(a client_testing.Action) (bool, runtime.Object, error) { | ||
| deleteAction, _ := a.(client_testing.DeleteAction) | ||
| action = deleteAction | ||
| name = deleteAction.GetName() | ||
| return true, nil, nil | ||
| }) | ||
| cmd.SetArgs(args) | ||
| err = cmd.Execute() | ||
| if err != nil { | ||
| return | ||
| } | ||
| output = buf.String() | ||
| return | ||
| } | ||
|
|
||
| func TestRevisionDelete(t *testing.T) { | ||
| revName := "foo-12345" | ||
| action, name, output, err := fakeRevisionDelete([]string{"revision", "delete", revName}) | ||
| if err != nil { | ||
| t.Error(err) | ||
| return | ||
| } | ||
| if action == nil { | ||
| t.Errorf("No action") | ||
| } else if !action.Matches("delete", "revisions") { | ||
| t.Errorf("Bad action %v", action) | ||
| } else if name != revName { | ||
|
navidshaikh marked this conversation as resolved.
|
||
| t.Errorf("Bad revision name returned after delete.") | ||
| } | ||
| commands.TestContains(t, output, []string{"Revision", revName, "deleted", "namespace", commands.FakeNamespace}, "word in output") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice 👍 |
||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ package commands | |
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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,48 @@ | ||
| // Copyright 2019 The Knative Authors | ||
|
|
||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
|
|
||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or im | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // +build e2e | ||
|
|
||
| package e2e | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/knative/client/pkg/kn/commands" | ||
| ) | ||
|
|
||
| func TestRevisionWorkflow(t *testing.T) { | ||
| teardown := Setup(t) | ||
| defer teardown(t) | ||
|
|
||
| testServiceCreate(t, k, "hello") | ||
| testDeleteRevision(t, k, "hello") | ||
| testServiceDelete(t, k, "hello") | ||
| } | ||
|
|
||
| func testDeleteRevision(t *testing.T, k kn, serviceName string) { | ||
| revName, err := k.RunWithOpts([]string{"revision", "list", "-o=jsonpath={.items[0].metadata.name}"}, runOpts{}) | ||
| if err != nil { | ||
| t.Errorf("Error executing 'revision list -o' command. Error: %s", err.Error()) | ||
| } | ||
| if strings.Contains(revName, "No resources found.") { | ||
| t.Errorf("Could not find revision name.") | ||
| } | ||
| out, err := k.RunWithOpts([]string{"revision", "delete", revName}, runOpts{}) | ||
| if err != nil { | ||
| t.Errorf("Error executing 'revision delete %s' command. Error: %s", revName, err.Error()) | ||
| } | ||
| commands.TestContains(t, out, []string{"Revision", revName, "deleted", "namespace", k.namespace}, "word in output") | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.