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

Added option to delete all profiles #4780

Merged
merged 80 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
db6b0a5
Added --delete-all flag
mschwrz Jul 12, 2019
08b6edc
Added function to get all profiles
mschwrz Jul 13, 2019
6887128
Merge remote-tracking branch 'main/master' into DELETE_ALL_PROFILES
mschwrz Jul 13, 2019
6f2390b
Added function to check if profile-config is valid
mschwrz Jul 13, 2019
6c4749b
Bugfix: Imported wrong configname
mschwrz Jul 13, 2019
f9e8490
Removed debug code
mschwrz Jul 13, 2019
13f40f4
Check if machineConfig and kubernetesConfig is not empty
mschwrz Jul 14, 2019
dd9afd1
Ensure usage of --delete-all without -p flag
mschwrz Jul 14, 2019
1d2ead5
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Jul 14, 2019
72a9493
Renamed delte-all flag to all
mschwrz Jul 15, 2019
925e803
Added deleteProfile function
mschwrz Jul 16, 2019
3c4b1b1
Renamed minikubeConfig to mkConfig
mschwrz Jul 16, 2019
f0e707c
Merge remote-tracking branch 'marekschwarz/DELETE_ALL_PROFILES' into …
mschwrz Jul 16, 2019
d0e749b
Implemented deleteAllProfiles
mschwrz Jul 16, 2019
019ee1f
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Jul 17, 2019
9e73f6e
Refactor review findings
mschwrz Jul 18, 2019
09d8143
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Jul 18, 2019
42a5850
Fixed lint errors
mschwrz Jul 18, 2019
af57143
Fixed translation errors
mschwrz Jul 18, 2019
4c6af02
Fixed goimports lint error
mschwrz Jul 18, 2019
70f4cb9
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Jul 20, 2019
48bd69c
Integrated ListProfiles()
mschwrz Jul 20, 2019
e237a13
Fixed merge error
mschwrz Jul 20, 2019
45161fa
Keep deleting when profiles when the deletion of one profile fails
mschwrz Jul 22, 2019
cb58974
Added testdata for unit tests
mschwrz Jul 23, 2019
6d9ae13
Fixed Test
mschwrz Jul 23, 2019
6dcb45a
Refactor
mschwrz Jul 23, 2019
1ef11bf
Fix test
mschwrz Jul 23, 2019
96ef740
Improved logging
mschwrz Jul 24, 2019
d4d8cc4
Refactor error init
mschwrz Jul 24, 2019
6f81089
Fixed review findings
mschwrz Jul 24, 2019
a4fd885
Added valid configs for delete_test
mschwrz Jul 25, 2019
d7d05b7
Added more testdata
mschwrz Jul 25, 2019
1d9a61f
Changed username
mschwrz Jul 25, 2019
59eb974
Fixed testdata
mschwrz Jul 25, 2019
fa0cdbf
Fixed testdata
mschwrz Jul 25, 2019
342584a
Fixed testdata
mschwrz Jul 25, 2019
a1d73a7
Added method to delete invalid profiles
mschwrz Jul 29, 2019
50329ed
Added machine.go to Load and Validate machines
mschwrz Aug 7, 2019
6ed4262
Resolved import cycle
mschwrz Aug 8, 2019
f0dd5a7
Added unit test for deletion of all profiles
mschwrz Aug 8, 2019
229c9b7
Fixed lint errors
mschwrz Aug 8, 2019
4835945
Bugfix
mschwrz Aug 18, 2019
d5bfa87
Added delete --all to proxy_test
mschwrz Aug 18, 2019
ba67c85
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Aug 19, 2019
da1f935
Readded Shutdown and Teardown
mschwrz Aug 19, 2019
5289e1f
Fixed lint errors
mschwrz Aug 19, 2019
b3741bd
Readded init
mschwrz Aug 20, 2019
2c6f659
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Aug 21, 2019
808477a
Moved GetMachinePath to machine.go and renamed it to MachinePath
mschwrz Aug 23, 2019
ea20ba3
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Aug 23, 2019
0dc7f8d
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Aug 26, 2019
24d4eda
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Aug 27, 2019
5b1528b
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Sep 4, 2019
71a6cb5
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Sep 19, 2019
01dd044
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Sep 21, 2019
79e8250
Use localpath
mschwrz Sep 21, 2019
02bea60
Readded testdata
mschwrz Sep 21, 2019
42c017f
Readded testdata
mschwrz Sep 21, 2019
5cabb01
Removed certs
mschwrz Sep 21, 2019
d52730a
Fixed test errors
mschwrz Sep 21, 2019
3ec82dd
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Sep 25, 2019
47ec8d3
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Sep 25, 2019
c8c4491
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Sep 26, 2019
e8c997d
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Sep 26, 2019
4551a17
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Sep 27, 2019
3396f5b
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Sep 28, 2019
1efdf11
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Oct 3, 2019
280e118
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Oct 3, 2019
8a4b3b9
Added more debug code
mschwrz Oct 3, 2019
ae6f47d
Appended "/.minikube" to testMinikubeDir for machine_test
mschwrz Oct 3, 2019
ee97b87
Added debug code
mschwrz Oct 3, 2019
b8abe56
Added more debug code
mschwrz Oct 3, 2019
0c9cd49
Replaced driver "hyperkit" by "virtualbox" in testfiles
mschwrz Oct 3, 2019
5610849
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Oct 4, 2019
c4107ae
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Oct 6, 2019
a0c844e
Refactor
mschwrz Oct 10, 2019
ae731d4
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Oct 10, 2019
09ce93f
Added delete --all to common.sh
mschwrz Oct 10, 2019
d13f58f
Merge branch 'master' into DELETE_ALL_PROFILES
mschwrz Oct 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 50 additions & 7 deletions cmd/minikube/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import (
pkgutil "k8s.io/minikube/pkg/util"
)

var deleteAll bool

// deleteCmd represents the delete command
var deleteCmd = &cobra.Command{
Use: "delete",
Expand All @@ -46,10 +48,43 @@ associated files.`,

// runDelete handles the executes the flow of "minikube delete"
func runDelete(cmd *cobra.Command, args []string) {
if len(args) > 0 {
exit.UsageT("usage: minikube delete")
profileFlag, err := cmd.Flags().GetString("profile")
if err != nil {
exit.WithError("Could not get profile flag", err)
}
profile := viper.GetString(pkg_config.MachineProfile)

if deleteAll {
if profileFlag != constants.DefaultMachineName {
exit.UsageT("usage: minikube delete --all")
}

validProfiles, invalidProfiles, err := pkg_config.ListProfiles()
profilesToDelete := append(validProfiles, invalidProfiles...)

if err != nil {
exit.WithError("Error getting profiles to delete", err)
}

deleteAllProfiles(profilesToDelete)
} else {
if len(args) > 0 {
exit.UsageT("usage: minikube delete")
}

profileName := viper.GetString(pkg_config.MachineProfile)
profile, err := pkg_config.LoadProfile(profileName)

if err != nil {
exit.WithError("Could not load profile", err)
}
deleteProfile(profile)
}
}

//TODO Return errors and handle in runDelete?
func deleteProfile(profile *pkg_config.Profile) {
mschwrz marked this conversation as resolved.
Show resolved Hide resolved
viper.Set(pkg_config.MachineProfile, profile.Name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reason to set the profile ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to set it because cluster.DeleteHost relies on cfg.GetMachineName(), which uses viper.GetString(MachineProfile).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I don't set it, the fallback machinename "minikube" is used.


api, err := machine.NewAPIClient()
if err != nil {
exit.WithError("Error getting client", err)
Expand All @@ -58,7 +93,7 @@ func runDelete(cmd *cobra.Command, args []string) {

cc, err := pkg_config.Load()
if err != nil && !os.IsNotExist(err) {
out.ErrT(out.Sad, "Error loading profile config: {{.error}}", out.V{"name": profile})
out.ErrT(out.Sad, "Error loading profile config: {{.error}}", out.V{"name": profile.Name})
}

// In the case of "none", we want to uninstall Kubernetes as there is no VM to delete
Expand All @@ -69,7 +104,7 @@ func runDelete(cmd *cobra.Command, args []string) {
if err = cluster.DeleteHost(api); err != nil {
switch err := errors.Cause(err).(type) {
case mcnerror.ErrHostDoesNotExist:
out.T(out.Meh, `"{{.name}}" cluster does not exist`, out.V{"name": profile})
out.T(out.Meh, `"{{.name}}" cluster does not exist`, out.V{"name": profile.Name})
default:
exit.WithError("Failed to delete cluster", err)
}
Expand All @@ -81,19 +116,26 @@ func runDelete(cmd *cobra.Command, args []string) {

if err := os.RemoveAll(constants.GetProfilePath(viper.GetString(pkg_config.MachineProfile))); err != nil {
if os.IsNotExist(err) {
out.T(out.Meh, `"{{.profile_name}}" profile does not exist`, out.V{"profile_name": profile})
out.T(out.Meh, `"{{.profile_name}}" profile does not exist`, out.V{"profile_name": profile.Name})
os.Exit(0)
}
exit.WithError("Failed to remove profile", err)
}
out.T(out.Crushed, `The "{{.cluster_name}}" cluster has been deleted.`, out.V{"cluster_name": profile})
out.T(out.Crushed, `The "{{.cluster_name}}" cluster has been deleted.`, out.V{"cluster_name": profile.Name})

machineName := pkg_config.GetMachineName()
if err := pkgutil.DeleteKubeConfigContext(constants.KubeconfigPath, machineName); err != nil {
exit.WithError("update config", err)
}
}

func deleteAllProfiles(profiles []*pkg_config.Profile) {
for _, profile := range profiles {
deleteProfile(profile)
}
}

//TODO Return errors and handle in deleteProfile?
func uninstallKubernetes(api libmachine.API, kc pkg_config.KubernetesConfig, bsName string) {
out.T(out.Resetting, "Uninstalling Kubernetes {{.kubernetes_version}} using {{.bootstrapper_name}} ...", out.V{"kubernetes_version": kc.KubernetesVersion, "bootstrapper_name": bsName})
clusterBootstrapper, err := getClusterBootstrapper(api, bsName)
Expand All @@ -105,5 +147,6 @@ func uninstallKubernetes(api libmachine.API, kc pkg_config.KubernetesConfig, bsN
}

func init() {
deleteCmd.Flags().BoolVar(&deleteAll, "all", false, "Set flag to delete all profiles")
RootCmd.AddCommand(deleteCmd)
}
4 changes: 2 additions & 2 deletions pkg/minikube/config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func ListProfiles(miniHome ...string) (validPs []*Profile, inValidPs []*Profile,
return nil, nil, err
}
for _, n := range pDirs {
p, err := loadProfile(n, miniHome...)
p, err := LoadProfile(n, miniHome...)
if err != nil {
inValidPs = append(inValidPs, p)
continue
Expand All @@ -58,7 +58,7 @@ func ListProfiles(miniHome ...string) (validPs []*Profile, inValidPs []*Profile,
}

// loadProfile loads type Profile based on its name
func loadProfile(name string, miniHome ...string) (*Profile, error) {
func LoadProfile(name string, miniHome ...string) (*Profile, error) {
cfg, err := DefaultLoader.LoadConfigFromFile(name, miniHome...)
p := &Profile{
Name: name,
Expand Down
3 changes: 3 additions & 0 deletions translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"Configure an external network switch following the official documentation, then add `--hyperv-virtual-switch=\u003cswitch-name\u003e` to `minikube start`": "",
"Configuring environment for Kubernetes {{.k8sVersion}} on {{.runtime}} {{.runtimeVersion}}": "Configurant l'environment pour Kubernetes {{.k8sVersion}} sur {{.runtime}} {{.runtimeVersion}}",
"Configuring local host environment ...": "",
"Could not get profile flag": "",
"Creating %s VM (CPUs=%d, Memory=%dMB, Disk=%dMB) ...": "Créant un VM %s (CPUs=%d, Mémoire=%dMB, Disque=%dMB)",
"Creating mount {{.name}} ...": "",
"Creating {{.driver_name}} VM (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...": "",
Expand Down Expand Up @@ -57,6 +58,7 @@
"Error getting host status": "",
"Error getting machine logs": "",
"Error getting machine status": "",
"Error getting profiles to delete": "",
"Error getting service status": "",
"Error getting service with namespace: {{.namespace}} and labels {{.labelName}}:{{.addonName}}: {{.error}}": "",
"Error getting the host IP address to use from within the VM": "",
Expand Down Expand Up @@ -285,6 +287,7 @@
"usage: minikube config set PROPERTY_NAME PROPERTY_VALUE": "",
"usage: minikube config unset PROPERTY_NAME": "",
"usage: minikube delete": "",
"usage: minikube delete --all": "",
"usage: minikube profile [MINIKUBE_PROFILE_NAME]": "",
"zsh completion failed": "",
"{{.addonName}} was successfully enabled": "",
Expand Down
3 changes: 3 additions & 0 deletions translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"Configure an external network switch following the official documentation, then add `--hyperv-virtual-switch=\u003cswitch-name\u003e` to `minikube start`": "",
"Configuring environment for Kubernetes {{.k8sVersion}} on {{.runtime}} {{.runtimeVersion}}": "开始为Kubernetes {{.k8sVersion}},{{.runtime}} {{.runtimeVersion}} 配置环境变量",
"Configuring local host environment ...": "",
"Could not get profile flag": "",
"Creating %s VM (CPUs=%d, Memory=%dMB, Disk=%dMB) ...": "正在创建%s虚拟机(CPU=%d,内存=%dMB,磁盘=%dMB)...",
"Creating mount {{.name}} ...": "",
"Creating {{.driver_name}} VM (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...": "",
Expand Down Expand Up @@ -57,6 +58,7 @@
"Error getting host status": "",
"Error getting machine logs": "",
"Error getting machine status": "",
"Error getting profiles to delete": "",
"Error getting service status": "",
"Error getting service with namespace: {{.namespace}} and labels {{.labelName}}:{{.addonName}}: {{.error}}": "",
"Error getting the host IP address to use from within the VM": "",
Expand Down Expand Up @@ -285,6 +287,7 @@
"usage: minikube config set PROPERTY_NAME PROPERTY_VALUE": "",
"usage: minikube config unset PROPERTY_NAME": "",
"usage: minikube delete": "",
"usage: minikube delete --all": "",
"usage: minikube profile [MINIKUBE_PROFILE_NAME]": "",
"zsh completion failed": "",
"{{.addonName}} was successfully enabled": "",
Expand Down