forked from joeholley/supergloo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall.go
77 lines (67 loc) · 2.38 KB
/
uninstall.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
package uninstall
import (
"github.com/solo-io/go-utils/errors"
skclients "github.com/solo-io/solo-kit/pkg/api/v1/clients"
"github.com/solo-io/supergloo/cli/pkg/flagutils"
"github.com/solo-io/supergloo/cli/pkg/helpers"
"github.com/solo-io/supergloo/cli/pkg/helpers/clients"
"github.com/solo-io/supergloo/cli/pkg/options"
"github.com/solo-io/supergloo/cli/pkg/surveyutils"
v1 "github.com/solo-io/supergloo/pkg/api/v1"
"github.com/spf13/cobra"
)
func Cmd(opts *options.Options) *cobra.Command {
cmd := &cobra.Command{
Use: "uninstall",
Aliases: []string{"u"},
Short: "uninstall a service mesh using Supergloo",
Long: `Disables an Install resource which the Supergloo controller
will use to uninstall an installed service mesh.
This only works for meshes that Supergloo installed.
Installs represent a desired installation of a supported mesh.
Supergloo watches for installs and synchronizes the managed installations
with the desired configuration in the install object. When an install is
disabled, Supergloo will remove corresponding installed components from the cluster.
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if opts.Interactive {
if err := surveyutils.SurveyUninstall(opts); err != nil {
return err
}
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
return disableInstall(opts)
},
}
flagutils.AddMetadataFlags(cmd.PersistentFlags(), &opts.Uninstall.Metadata)
flagutils.AddOutputFlag(cmd.PersistentFlags(), &opts.OutputType)
flagutils.AddInteractiveFlag(cmd.PersistentFlags(), &opts.Interactive)
return cmd
}
func disableInstall(opts *options.Options) error {
in, err := disableInstallFromOpts(opts)
if err != nil {
return err
}
in, err = clients.MustInstallClient().Write(in, skclients.WriteOpts{Ctx: opts.Ctx, OverwriteExisting: true})
if err != nil {
return err
}
helpers.PrintInstalls(v1.InstallList{in}, opts.OutputType)
return nil
}
func disableInstallFromOpts(opts *options.Options) (*v1.Install, error) {
installToDisable, err := clients.MustInstallClient().Read(opts.Uninstall.Metadata.Namespace,
opts.Uninstall.Metadata.Name,
skclients.ReadOpts{Ctx: opts.Ctx})
if err != nil {
return nil, err
}
if installToDisable.Disabled {
return nil, errors.Errorf("install %v is already disabled", opts.Uninstall.Metadata)
}
installToDisable.Disabled = true
return installToDisable, nil
}