This repository has been archived by the owner on Jun 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 396
/
delete.go
90 lines (71 loc) · 1.69 KB
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"errors"
"fmt"
"io"
"github.com/spf13/cobra"
"google.golang.org/grpc"
"k8s.io/helm/pkg/helm"
"github.com/Azure/draft/pkg/draft/local"
)
const deleteDesc = `This command deletes an application from your Kubernetes environment.`
type deleteCmd struct {
appName string
out io.Writer
}
func newDeleteCmd(out io.Writer) *cobra.Command {
dc := &deleteCmd{
out: out,
}
cmd := &cobra.Command{
Use: "delete [app]",
Short: "delete an application",
Long: deleteDesc,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
dc.appName = args[0]
}
return dc.run()
},
}
return cmd
}
func (d *deleteCmd) run() error {
var name string
if d.appName != "" {
name = d.appName
} else {
deployedApp, err := local.DeployedApplication(draftToml, defaultDraftEnvironment())
if err != nil {
return errors.New("Unable to detect app name\nPlease pass in the name of the application")
}
name = deployedApp.Name
}
//TODO: replace with serverside call
if err := Delete(name); err != nil {
return err
}
msg := "app '" + name + "' deleted"
fmt.Fprintln(d.out, msg)
return nil
}
// Delete uses the helm client to delete an app with the given name
//
// Returns an error if the command failed.
func Delete(app string) error {
// set up helm client
client, config, err := getKubeClient(kubeContext)
if err != nil {
return fmt.Errorf("Could not get a kube client: %s", err)
}
helmClient, err := setupHelm(client, config, tillerNamespace)
if err != nil {
return err
}
// delete helm release
_, err = helmClient.DeleteRelease(app, helm.DeletePurge(true))
if err != nil {
return errors.New(grpc.ErrorDesc(err))
}
return nil
}