github.com/amy/helm@v2.7.2+incompatible/cmd/helm/delete.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors All rights reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package main 18 19 import ( 20 "errors" 21 "fmt" 22 "io" 23 24 "github.com/spf13/cobra" 25 26 "k8s.io/helm/pkg/helm" 27 ) 28 29 const deleteDesc = ` 30 This command takes a release name, and then deletes the release from Kubernetes. 31 It removes all of the resources associated with the last release of the chart. 32 33 Use the '--dry-run' flag to see which releases will be deleted without actually 34 deleting them. 35 ` 36 37 type deleteCmd struct { 38 name string 39 dryRun bool 40 disableHooks bool 41 purge bool 42 timeout int64 43 44 out io.Writer 45 client helm.Interface 46 } 47 48 func newDeleteCmd(c helm.Interface, out io.Writer) *cobra.Command { 49 del := &deleteCmd{ 50 out: out, 51 client: c, 52 } 53 54 cmd := &cobra.Command{ 55 Use: "delete [flags] RELEASE_NAME [...]", 56 Aliases: []string{"del"}, 57 SuggestFor: []string{"remove", "rm"}, 58 Short: "given a release name, delete the release from Kubernetes", 59 Long: deleteDesc, 60 PreRunE: setupConnection, 61 RunE: func(cmd *cobra.Command, args []string) error { 62 if len(args) == 0 { 63 return errors.New("command 'delete' requires a release name") 64 } 65 del.client = ensureHelmClient(del.client) 66 67 for i := 0; i < len(args); i++ { 68 del.name = args[i] 69 if err := del.run(); err != nil { 70 return err 71 } 72 73 fmt.Fprintf(out, "release \"%s\" deleted\n", del.name) 74 } 75 return nil 76 }, 77 } 78 79 f := cmd.Flags() 80 f.BoolVar(&del.dryRun, "dry-run", false, "simulate a delete") 81 f.BoolVar(&del.disableHooks, "no-hooks", false, "prevent hooks from running during deletion") 82 f.BoolVar(&del.purge, "purge", false, "remove the release from the store and make its name free for later use") 83 f.Int64Var(&del.timeout, "timeout", 300, "time in seconds to wait for any individual Kubernetes operation (like Jobs for hooks)") 84 85 return cmd 86 } 87 88 func (d *deleteCmd) run() error { 89 opts := []helm.DeleteOption{ 90 helm.DeleteDryRun(d.dryRun), 91 helm.DeleteDisableHooks(d.disableHooks), 92 helm.DeletePurge(d.purge), 93 helm.DeleteTimeout(d.timeout), 94 } 95 res, err := d.client.DeleteRelease(d.name, opts...) 96 if res != nil && res.Info != "" { 97 fmt.Fprintln(d.out, res.Info) 98 } 99 100 return prettyError(err) 101 }