make error message more clear
parent
4a5057c1e9
commit
5c46b3a555
|
@ -35,7 +35,10 @@ var addonsDisableCmd = &cobra.Command{
|
|||
if len(args) != 1 {
|
||||
exit.Message(reason.Usage, "usage: minikube addons disable ADDON_NAME")
|
||||
}
|
||||
|
||||
err := addons.CheckPaused(ClusterFlagValue(), false)
|
||||
if err != nil {
|
||||
exit.Error(reason.InternalAddonDisablePaused, "disable failed", err)
|
||||
}
|
||||
addon := args[0]
|
||||
if addon == "heapster" {
|
||||
exit.Message(reason.AddonUnsupported, "The heapster addon is depreciated. please try to disable metrics-server instead")
|
||||
|
@ -46,7 +49,7 @@ var addonsDisableCmd = &cobra.Command{
|
|||
exit.Message(reason.AddonUnsupported, `"'{{.minikube_addon}}' is not a valid minikube addon`, out.V{"minikube_addon": addon})
|
||||
}
|
||||
if validAddon.IsEnabled(cc) {
|
||||
err := addons.SetAndSave(ClusterFlagValue(), addon, "false")
|
||||
err = addons.SetAndSave(ClusterFlagValue(), addon, "false")
|
||||
if err != nil {
|
||||
exit.Error(reason.InternalAddonDisable, "disable failed", err)
|
||||
}
|
||||
|
|
|
@ -48,6 +48,10 @@ var addonsEnableCmd = &cobra.Command{
|
|||
exit.Message(reason.Usage, "You cannot enable addons on a cluster without Kubernetes, to enable Kubernetes on your cluster, run: minikube start --kubernetes-version=stable")
|
||||
}
|
||||
|
||||
err = addons.CheckPaused(ClusterFlagValue(), true)
|
||||
if err != nil {
|
||||
exit.Error(reason.InternalAddonEnablePaused, "enabled failed", err)
|
||||
}
|
||||
addon := args[0]
|
||||
isDeprecated, replacement, msg := addons.Deprecations(addon)
|
||||
if isDeprecated && replacement == "" {
|
||||
|
|
|
@ -282,24 +282,6 @@ func EnableOrDisableAddon(cc *config.ClusterConfig, name string, val string) err
|
|||
return errors.Wrap(err, "command runner")
|
||||
}
|
||||
|
||||
crName := cc.KubernetesConfig.ContainerRuntime
|
||||
cr, err := cruntime.New(cruntime.Config{Type: crName, Runner: runner})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "container runtime")
|
||||
}
|
||||
runtimePaused, err := cluster.CheckIfPaused(cr, []string{"kube-system"})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "check paused")
|
||||
}
|
||||
if runtimePaused {
|
||||
action := "disable"
|
||||
if enable {
|
||||
action = "enable"
|
||||
}
|
||||
msg := fmt.Sprintf("can't %s addon on a paused cluster, please unpause the cluster firstly.", action)
|
||||
out.Styled(style.Shrug, msg)
|
||||
return errors.New(msg)
|
||||
}
|
||||
bail, err := addonSpecificChecks(cc, name, enable, runner)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -605,3 +587,54 @@ func UpdateConfigToDisable(cc *config.ClusterConfig) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CheckPaused checks whether the cluster is paused before enable/disable an addon.
|
||||
func CheckPaused(profile string, enable bool) error {
|
||||
klog.Info("checking whether the cluster is paused")
|
||||
|
||||
cc, err := config.Load(profile)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "loading profile")
|
||||
}
|
||||
|
||||
api, err := machine.NewAPIClient()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "machine client")
|
||||
}
|
||||
defer api.Close()
|
||||
|
||||
cp, err := config.PrimaryControlPlane(cc)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "control plane")
|
||||
}
|
||||
|
||||
host, err := machine.LoadHost(api, config.MachineName(*cc, cp))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get host")
|
||||
}
|
||||
|
||||
runner, err := machine.CommandRunner(host)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "command runner")
|
||||
}
|
||||
|
||||
crName := cc.KubernetesConfig.ContainerRuntime
|
||||
cr, err := cruntime.New(cruntime.Config{Type: crName, Runner: runner})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "container runtime")
|
||||
}
|
||||
runtimePaused, err := cluster.CheckIfPaused(cr, []string{"kube-system"})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "check paused")
|
||||
}
|
||||
if runtimePaused {
|
||||
action := "disable"
|
||||
if enable {
|
||||
action = "enable"
|
||||
}
|
||||
msg := fmt.Sprintf("can't %s addon on a paused cluster, please unpause the cluster firstly.", action)
|
||||
out.Styled(style.Shrug, msg)
|
||||
return errors.New(msg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -85,6 +85,11 @@ var (
|
|||
InternalAddonDisable = Kind{ID: "MK_ADDON_DISABLE", ExitCode: ExProgramError}
|
||||
// minikube could not enable an addon, e.g. dashboard addon
|
||||
InternalAddonEnable = Kind{ID: "MK_ADDON_ENABLE", ExitCode: ExProgramError}
|
||||
// minikube could not enable an addon on a paused cluster
|
||||
InternalAddonEnablePaused = Kind{ID: "MK_ADDON_ENABLE_PAUSED", ExitCode: ExProgramConflict}
|
||||
// minikube could not disable an addon on a paused cluster
|
||||
InternalAddonDisablePaused = Kind{ID: "MK_ADDON_DISABLE_PAUSED", ExitCode: ExProgramConflict}
|
||||
|
||||
// minikube failed to update internal configuration, such as the cached images config map
|
||||
InternalAddConfig = Kind{ID: "MK_ADD_CONFIG", ExitCode: ExProgramError}
|
||||
// minikube failed to create a cluster bootstrapper
|
||||
|
|
Loading…
Reference in New Issue