-
Notifications
You must be signed in to change notification settings - Fork 88
/
admin-console-upgrade.go
90 lines (77 loc) · 3.1 KB
/
admin-console-upgrade.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 cli
import (
"fmt"
"os"
"strings"
"github.com/manifoldco/promptui"
"github.com/pkg/errors"
"github.com/replicatedhq/kots/pkg/kotsadm"
kotsadmtypes "github.com/replicatedhq/kots/pkg/kotsadm/types"
"github.com/replicatedhq/kots/pkg/logger"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func AdminConsoleUpgradeCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "upgrade",
Short: "Upgrade the admin console to the latest version",
Long: "Upgrade the admin console to the latest version",
SilenceUsage: true,
SilenceErrors: false,
PreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlags(cmd.Flags())
},
RunE: func(cmd *cobra.Command, args []string) error {
v := viper.GetViper()
if v.GetBool("force-upgrade-kurl") {
prompt := promptui.Prompt{
Label: fmt.Sprintf("Upgrading a kotsadm instance created by kURL can result in data loss. Do you want to continue"),
IsConfirm: true,
}
for {
resp, err := prompt.Run()
if err == promptui.ErrInterrupt {
os.Exit(-1)
}
if strings.ToLower(resp) == "n" {
os.Exit(-1)
}
if strings.ToLower(resp) == "y" {
break
}
}
}
upgradeOptions := kotsadmtypes.UpgradeOptions{
Namespace: v.GetString("namespace"),
KubernetesConfigFlags: kubernetesConfigFlags,
ForceUpgradeKurl: v.GetBool("force-upgrade-kurl"),
}
kotsadm.OverrideVersion = v.GetString("kotsadm-tag")
kotsadm.OverrideRegistry = v.GetString("kotsadm-registry")
kotsadm.OverrideNamespace = v.GetString("kotsadm-namespace")
log := logger.NewLogger()
if upgradeOptions.Namespace != "default" {
log.ActionWithoutSpinner("Upgrading Admin Console")
} else {
log.ActionWithoutSpinner("Upgrading Admin Console in the default namespace")
}
if err := kotsadm.Upgrade(upgradeOptions); err != nil {
return errors.Wrap(err, "failed to upgrade")
}
log.ActionWithoutSpinner("")
log.ActionWithoutSpinner("The Admin Console is running the latest version")
log.ActionWithoutSpinner("To access the Admin Console, run kubectl kots admin-console --namespace %s", v.GetString("namespace"))
log.ActionWithoutSpinner("")
return nil
},
}
cmd.Flags().Bool("force-upgrade-kurl", false, "set to force upgrade even if this is a kurl cluster")
cmd.Flags().String("kotsadm-tag", "", "set to override the tag of kotsadm. this may create an incompatible deployment because the version of kots and kotsadm are designed to work together")
cmd.Flags().String("kotsadm-registry", "", "set to override the registry of kotsadm image. this may create an incompatible deployment because the version of kots and kotsadm are designed to work together")
cmd.Flags().String("kotsadm-namespace", "", "set to override the namespace of kotsadm image. this may create an incompatible deployment because the version of kots and kotsadm are designed to work together")
cmd.Flags().MarkHidden("force-upgrade-kurl")
cmd.Flags().MarkHidden("kotsadm-tag")
cmd.Flags().MarkHidden("kotsadm-registry")
cmd.Flags().MarkHidden("kotsadm-namespace")
return cmd
}