Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

status: Add experimental cluster JSON status with state transition support #8868

Merged
merged 10 commits into from
Jul 29, 2020
11 changes: 11 additions & 0 deletions cmd/minikube/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/out/register"
tstromberg marked this conversation as resolved.
Show resolved Hide resolved
)

var deleteAll bool
Expand Down Expand Up @@ -125,6 +126,8 @@ func runDelete(cmd *cobra.Command, args []string) {
if len(args) > 0 {
exit.UsageT("Usage: minikube delete")
}
register.SetEventLogPath(localpath.EventLog(ClusterFlagValue()))
register.Reg.SetStep(register.Deleting)

validProfiles, invalidProfiles, err := config.ListProfiles()
if err != nil {
Expand All @@ -146,6 +149,8 @@ func runDelete(cmd *cobra.Command, args []string) {
deleteContainersAndVolumes(oci.Podman)

errs := DeleteProfiles(profilesToDelete)
register.Reg.SetStep(register.Done)

if len(errs) > 0 {
HandleDeletionErrors(errs)
} else {
Expand All @@ -166,6 +171,8 @@ func runDelete(cmd *cobra.Command, args []string) {
}

errs := DeleteProfiles([]*config.Profile{profile})
register.Reg.SetStep(register.Done)

if len(errs) > 0 {
HandleDeletionErrors(errs)
}
Expand Down Expand Up @@ -264,6 +271,8 @@ func deletePossibleKicLeftOver(cname string, driverName string) {

func deleteProfile(profile *config.Profile) error {
glog.Infof("Deleting %s", profile.Name)
register.Reg.SetStep(register.Deleting)

viper.Set(config.ProfileName, profile.Name)
if profile.Config != nil {
glog.Infof("%s configuration: %+v", profile.Name, profile.Config)
Expand Down Expand Up @@ -326,6 +335,8 @@ func deleteProfile(profile *config.Profile) error {
}

func deleteHosts(api libmachine.API, cc *config.ClusterConfig) {
register.Reg.SetStep(register.Deleting)

if cc != nil {
for _, n := range cc.Nodes {
machineName := driver.MachineName(*cc, n)
Expand Down
42 changes: 29 additions & 13 deletions cmd/minikube/cmd/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ import (
"k8s.io/minikube/pkg/minikube/cruntime"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/mustload"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/out/register"
)

var (
Expand All @@ -47,8 +49,27 @@ var pauseCmd = &cobra.Command{

func runPause(cmd *cobra.Command, args []string) {
co := mustload.Running(ClusterFlagValue())
register.SetEventLogPath(localpath.EventLog(ClusterFlagValue()))
register.Reg.SetStep(register.Pausing)

glog.Infof("namespaces: %v keys: %v", namespaces, viper.AllSettings())
if allNamespaces {
namespaces = nil //all
} else if len(namespaces) == 0 {
exit.WithCodeT(exit.BadUsage, "Use -A to specify all namespaces")
}

ids := []string{}

for _, n := range co.Config.Nodes {
// Use node-name if available, falling back to cluster name
name := n.Name
if n.Name == "" {
name = co.Config.Name
}

out.T(out.Pause, "Pausing node {{.name}} ... ", out.V{"name": name})

host, err := machine.LoadHost(co.API, driver.MachineName(*co.Config, n))
if err != nil {
exit.WithError("Error getting host", err)
Expand All @@ -64,23 +85,18 @@ func runPause(cmd *cobra.Command, args []string) {
exit.WithError("Failed runtime", err)
}

glog.Infof("namespaces: %v keys: %v", namespaces, viper.AllSettings())
if allNamespaces {
namespaces = nil //all
} else if len(namespaces) == 0 {
exit.WithCodeT(exit.BadUsage, "Use -A to specify all namespaces")
}

ids, err := cluster.Pause(cr, r, namespaces)
uids, err := cluster.Pause(cr, r, namespaces)
if err != nil {
exit.WithError("Pause", err)
}
ids = append(ids, uids...)
}

if namespaces == nil {
out.T(out.Unpause, "Paused kubelet and {{.count}} containers", out.V{"count": len(ids)})
} else {
out.T(out.Unpause, "Paused kubelet and {{.count}} containers in: {{.namespaces}}", out.V{"count": len(ids), "namespaces": strings.Join(namespaces, ", ")})
}
register.Reg.SetStep(register.Done)
if namespaces == nil {
out.T(out.Unpause, "Paused {{.count}} containers", out.V{"count": len(ids)})
} else {
out.T(out.Unpause, "Paused {{.count}} containers in: {{.namespaces}}", out.V{"count": len(ids), "namespaces": strings.Join(namespaces, ", ")})
}
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ func platform() string {

// runStart handles the executes the flow of "minikube start"
func runStart(cmd *cobra.Command, args []string) {
register.SetEventLogPath(localpath.EventLog(ClusterFlagValue()))

out.SetJSON(viper.GetString(startOutput) == "json")
displayVersion(version.GetVersion())

Expand Down
Loading