Moved GetMachinePath to machine.go and renamed it to MachinePath
Added comments to public functionspull/4780/head
parent
2c6f659725
commit
808477ae1e
|
@ -113,6 +113,7 @@ func runDelete(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
}
|
||||
|
||||
// Deletes one or more profiles
|
||||
func DeleteProfiles(profiles []*pkg_config.Profile) []error {
|
||||
var errs []error
|
||||
for _, profile := range profiles {
|
||||
|
@ -223,7 +224,7 @@ func deleteInvalidProfile(profile *pkg_config.Profile) []error {
|
|||
}
|
||||
}
|
||||
|
||||
pathToMachine := constants.GetMachinePath(profile.Name, constants.GetMinipath())
|
||||
pathToMachine := cluster.MachinePath(profile.Name, constants.GetMinipath())
|
||||
if _, err := os.Stat(pathToMachine); !os.IsNotExist(err) {
|
||||
err := os.RemoveAll(pathToMachine)
|
||||
if err != nil {
|
||||
|
@ -248,6 +249,7 @@ func uninstallKubernetes(api libmachine.API, kc pkg_config.KubernetesConfig, bsN
|
|||
return nil
|
||||
}
|
||||
|
||||
// Handles deletion error from DeleteProfiles
|
||||
func HandleDeletionErrors(errors []error) {
|
||||
if len(errors) == 1 {
|
||||
handleSingleDeletionError(errors[0])
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"k8s.io/minikube/pkg/minikube/cluster"
|
||||
"k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
)
|
||||
|
@ -60,7 +61,7 @@ func TestDeleteProfileWithValidConfig(t *testing.T) {
|
|||
t.Fatalf("Profile folder of profile \"%s\" was not deleted", profile.Name)
|
||||
}
|
||||
|
||||
pathToMachine := constants.GetMachinePath(profile.Name, constants.GetMinipath())
|
||||
pathToMachine := cluster.MachinePath(profile.Name, constants.GetMinipath())
|
||||
if _, err := os.Stat(pathToMachine); !os.IsNotExist(err) {
|
||||
t.Fatalf("Profile folder of profile \"%s\" was not deleted", profile.Name)
|
||||
}
|
||||
|
@ -108,7 +109,7 @@ func TestDeleteProfileWithEmptyProfileConfig(t *testing.T) {
|
|||
t.Fatalf("Profile folder of profile \"%s\" was not deleted", profile.Name)
|
||||
}
|
||||
|
||||
pathToMachine := constants.GetMachinePath(profile.Name, constants.GetMinipath())
|
||||
pathToMachine := cluster.MachinePath(profile.Name, constants.GetMinipath())
|
||||
if _, err := os.Stat(pathToMachine); !os.IsNotExist(err) {
|
||||
t.Fatalf("Profile folder of profile \"%s\" was not deleted", profile.Name)
|
||||
}
|
||||
|
@ -156,7 +157,7 @@ func TestDeleteProfileWithInvalidProfileConfig(t *testing.T) {
|
|||
t.Fatalf("Profile folder of profile \"%s\" was not deleted", profile.Name)
|
||||
}
|
||||
|
||||
pathToMachine := constants.GetMachinePath(profile.Name, constants.GetMinipath())
|
||||
pathToMachine := cluster.MachinePath(profile.Name, constants.GetMinipath())
|
||||
if _, err := os.Stat(pathToMachine); !os.IsNotExist(err) {
|
||||
t.Fatalf("Profile folder of profile \"%s\" was not deleted", profile.Name)
|
||||
}
|
||||
|
@ -204,7 +205,7 @@ func TestDeleteProfileWithPartialProfileConfig(t *testing.T) {
|
|||
t.Fatalf("Profile folder of profile \"%s\" was not deleted", profile.Name)
|
||||
}
|
||||
|
||||
pathToMachine := constants.GetMachinePath(profile.Name, constants.GetMinipath())
|
||||
pathToMachine := cluster.MachinePath(profile.Name, constants.GetMinipath())
|
||||
if _, err := os.Stat(pathToMachine); !os.IsNotExist(err) {
|
||||
t.Fatalf("Profile folder of profile \"%s\" was not deleted", profile.Name)
|
||||
}
|
||||
|
@ -252,7 +253,7 @@ func TestDeleteProfileWithMissingMachineConfig(t *testing.T) {
|
|||
t.Fatalf("Profile folder of profile \"%s\" was not deleted", profile.Name)
|
||||
}
|
||||
|
||||
pathToMachine := constants.GetMachinePath(profile.Name, constants.GetMinipath())
|
||||
pathToMachine := cluster.MachinePath(profile.Name, constants.GetMinipath())
|
||||
if _, err := os.Stat(pathToMachine); !os.IsNotExist(err) {
|
||||
t.Fatalf("Profile folder of profile \"%s\" was not deleted", profile.Name)
|
||||
}
|
||||
|
@ -300,7 +301,7 @@ func TestDeleteProfileWithEmptyMachineConfig(t *testing.T) {
|
|||
t.Fatalf("Profile folder of profile \"%s\" was not deleted", profile.Name)
|
||||
}
|
||||
|
||||
pathToMachine := constants.GetMachinePath(profile.Name, constants.GetMinipath())
|
||||
pathToMachine := cluster.MachinePath(profile.Name, constants.GetMinipath())
|
||||
if _, err := os.Stat(pathToMachine); !os.IsNotExist(err) {
|
||||
t.Fatalf("Profile folder of profile \"%s\" was not deleted", profile.Name)
|
||||
}
|
||||
|
@ -348,7 +349,7 @@ func TestDeleteProfileWithInvalidMachineConfig(t *testing.T) {
|
|||
t.Fatalf("Profile folder of profile \"%s\" was not deleted", profile.Name)
|
||||
}
|
||||
|
||||
pathToMachine := constants.GetMachinePath(profile.Name, constants.GetMinipath())
|
||||
pathToMachine := cluster.MachinePath(profile.Name, constants.GetMinipath())
|
||||
if _, err := os.Stat(pathToMachine); !os.IsNotExist(err) {
|
||||
t.Fatalf("Profile folder of profile \"%s\" was not deleted", profile.Name)
|
||||
}
|
||||
|
@ -396,7 +397,7 @@ func TestDeleteProfileWithPartialMachineConfig(t *testing.T) {
|
|||
t.Fatalf("Profile folder of profile \"%s\" was not deleted", profile.Name)
|
||||
}
|
||||
|
||||
pathToMachine := constants.GetMachinePath(profile.Name, constants.GetMinipath())
|
||||
pathToMachine := cluster.MachinePath(profile.Name, constants.GetMinipath())
|
||||
if _, err := os.Stat(pathToMachine); !os.IsNotExist(err) {
|
||||
t.Fatalf("Profile folder of profile \"%s\" was not deleted", profile.Name)
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ type Machine struct {
|
|||
*host.Host
|
||||
}
|
||||
|
||||
// IsValid checks if the machine has the essential info needed for a machine
|
||||
func (h *Machine) IsValid() bool {
|
||||
if h == nil {
|
||||
return false
|
||||
|
@ -57,6 +58,8 @@ func (h *Machine) IsValid() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// ListsMachines return all valid and invalid machines
|
||||
// If a machine is valid or invalid is determined by the cluster.IsValid function
|
||||
func ListMachines(miniHome ...string) (validMachines []*Machine, inValidMachines []*Machine, err error) {
|
||||
pDirs, err := machineDirs(miniHome...)
|
||||
if err != nil {
|
||||
|
@ -77,6 +80,7 @@ func ListMachines(miniHome ...string) (validMachines []*Machine, inValidMachines
|
|||
return validMachines, inValidMachines, nil
|
||||
}
|
||||
|
||||
// Loads a machine or throws an error if the machine could not be loadedG
|
||||
func LoadMachine(name string) (*Machine, error) {
|
||||
api, err := machine.NewAPIClient()
|
||||
if err != nil {
|
||||
|
@ -112,3 +116,12 @@ func machineDirs(miniHome ...string) (dirs []string, err error) {
|
|||
}
|
||||
return dirs, err
|
||||
}
|
||||
|
||||
// MachinePath returns the Minikube machine path of a machine
|
||||
func MachinePath(machine string, miniHome ...string) string {
|
||||
miniPath := constants.GetMinipath()
|
||||
if len(miniHome) > 0 {
|
||||
miniPath = miniHome[0]
|
||||
}
|
||||
return filepath.Join(miniPath, "machines", machine)
|
||||
}
|
||||
|
|
|
@ -210,15 +210,6 @@ func GetProfilePath(profile string, miniHome ...string) string {
|
|||
return filepath.Join(miniPath, "profiles", profile)
|
||||
}
|
||||
|
||||
// GetMachinePath returns the Minikube machine path of a machine
|
||||
func GetMachinePath(machine string, miniHome ...string) string {
|
||||
miniPath := GetMinipath()
|
||||
if len(miniHome) > 0 {
|
||||
miniPath = miniHome[0]
|
||||
}
|
||||
return filepath.Join(miniPath, "machines", machine)
|
||||
}
|
||||
|
||||
// AddonsPath is the default path of the addons configuration
|
||||
const AddonsPath = "/etc/kubernetes/addons"
|
||||
|
||||
|
|
Loading…
Reference in New Issue