Skip to content

Commit aa6a135

Browse files
authored
Merge branch 'master' into translation-chinese
2 parents 910a69e + 7a7689b commit aa6a135

File tree

80 files changed

+2707
-466
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+2707
-466
lines changed

Makefile

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# Bump these on release - and please check ISO_VERSION for correctness.
1616
VERSION_MAJOR ?= 1
1717
VERSION_MINOR ?= 4
18-
VERSION_BUILD ?= 0
18+
VERSION_BUILD ?= 1
1919
RAW_VERSION=$(VERSION_MAJOR).$(VERSION_MINOR).${VERSION_BUILD}
2020
VERSION ?= v$(RAW_VERSION)
2121

@@ -29,7 +29,7 @@ RPM_VERSION ?= $(DEB_VERSION)
2929
GO_VERSION ?= 1.12.9
3030

3131
INSTALL_SIZE ?= $(shell du out/minikube-windows-amd64.exe | cut -f1)
32-
BUILDROOT_BRANCH ?= 2018.05.3
32+
BUILDROOT_BRANCH ?= 2019.02.6
3333
REGISTRY?=gcr.io/k8s-minikube
3434

3535
# Get git commit id
@@ -49,17 +49,17 @@ MINIKUBE_BUCKET ?= minikube/releases
4949
MINIKUBE_UPLOAD_LOCATION := gs://${MINIKUBE_BUCKET}
5050
MINIKUBE_RELEASES_URL=https://github.com/kubernetes/minikube/releases/download
5151

52-
KERNEL_VERSION ?= 4.15
52+
KERNEL_VERSION ?= 4.19.76
5353
# latest from https://github.com/golangci/golangci-lint/releases
54-
GOLINT_VERSION ?= v1.18.0
54+
GOLINT_VERSION ?= v1.20.0
5555
# Limit number of default jobs, to avoid the CI builds running out of memory
5656
GOLINT_JOBS ?= 4
5757
# see https://github.com/golangci/golangci-lint#memory-usage-of-golangci-lint
58-
GOLINT_GOGC ?= 8
58+
GOLINT_GOGC ?= 100
5959
# options for lint (golangci-lint)
60-
GOLINT_OPTIONS = --deadline 4m \
60+
GOLINT_OPTIONS = --timeout 4m \
6161
--build-tags "${MINIKUBE_INTEGRATION_BUILD_TAGS}" \
62-
--enable goimports,gocritic,golint,gocyclo,interfacer,misspell,nakedret,stylecheck,unconvert,unparam \
62+
--enable goimports,gocritic,golint,gocyclo,misspell,nakedret,stylecheck,unconvert,unparam \
6363
--exclude 'variable on range scope.*in function literal|ifElseChain'
6464

6565

cmd/minikube/cmd/config/profile.go

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ var ProfileCmd = &cobra.Command{
4747
profile := args[0]
4848
if profile == "default" {
4949
profile = "minikube"
50+
} else {
51+
// not validating when it is default profile
52+
errProfile, ok := ValidateProfile(profile)
53+
if !ok && errProfile != nil {
54+
out.FailureT(errProfile.Msg)
55+
}
5056
}
5157

5258
if !pkgConfig.ProfileExists(profile) {

cmd/minikube/cmd/config/util.go

+39
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,42 @@ func EnableOrDisableStorageClasses(name, val string) error {
232232

233233
return EnableOrDisableAddon(name, val)
234234
}
235+
236+
// ErrValidateProfile Error to validate profile
237+
type ErrValidateProfile struct {
238+
Name string
239+
Msg string
240+
}
241+
242+
func (e ErrValidateProfile) Error() string {
243+
return e.Msg
244+
}
245+
246+
// ValidateProfile checks if the profile user is trying to switch exists, else throws error
247+
func ValidateProfile(profile string) (*ErrValidateProfile, bool) {
248+
249+
validProfiles, invalidProfiles, err := config.ListProfiles()
250+
if err != nil {
251+
out.FailureT(err.Error())
252+
}
253+
254+
// handling invalid profiles
255+
for _, invalidProf := range invalidProfiles {
256+
if profile == invalidProf.Name {
257+
return &ErrValidateProfile{Name: profile, Msg: fmt.Sprintf("%q is an invalid profile", profile)}, false
258+
}
259+
}
260+
261+
profileFound := false
262+
// valid profiles if found, setting profileFound to trueexpectedMsg
263+
for _, prof := range validProfiles {
264+
if prof.Name == profile {
265+
profileFound = true
266+
break
267+
}
268+
}
269+
if !profileFound {
270+
return &ErrValidateProfile{Name: profile, Msg: fmt.Sprintf("profile %q not found", profile)}, false
271+
}
272+
return nil, true
273+
}

cmd/minikube/cmd/config/util_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package config
1818

1919
import (
20+
"fmt"
2021
"testing"
2122

2223
"k8s.io/minikube/pkg/minikube/assets"
@@ -111,3 +112,26 @@ func TestIsAddonAlreadySet(t *testing.T) {
111112
}
112113
}
113114
}
115+
116+
func TestValidateProfile(t *testing.T) {
117+
testCases := []struct {
118+
profileName string
119+
}{
120+
{
121+
profileName: "82374328742_2974224498",
122+
},
123+
{
124+
profileName: "minikube",
125+
},
126+
}
127+
128+
for _, test := range testCases {
129+
profileNam := test.profileName
130+
expectedMsg := fmt.Sprintf("profile %q not found", test.profileName)
131+
132+
err, ok := ValidateProfile(profileNam)
133+
if !ok && err.Error() != expectedMsg {
134+
t.Errorf("Didnt receive expected message")
135+
}
136+
}
137+
}

cmd/minikube/cmd/delete.go

+189-15
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ import (
4242
"k8s.io/minikube/pkg/minikube/out"
4343
)
4444

45+
var deleteAll bool
46+
4547
// deleteCmd represents the delete command
4648
var deleteCmd = &cobra.Command{
4749
Use: "delete",
@@ -51,26 +53,121 @@ associated files.`,
5153
Run: runDelete,
5254
}
5355

56+
type typeOfError int
57+
58+
const (
59+
Fatal typeOfError = 0
60+
MissingProfile typeOfError = 1
61+
MissingCluster typeOfError = 2
62+
)
63+
64+
type DeletionError struct {
65+
Err error
66+
Errtype typeOfError
67+
}
68+
69+
func (error DeletionError) Error() string {
70+
return error.Err.Error()
71+
}
72+
5473
// runDelete handles the executes the flow of "minikube delete"
5574
func runDelete(cmd *cobra.Command, args []string) {
5675
if len(args) > 0 {
5776
exit.UsageT("Usage: minikube delete")
5877
}
59-
profile := viper.GetString(pkg_config.MachineProfile)
78+
profileFlag, err := cmd.Flags().GetString("profile")
79+
if err != nil {
80+
exit.WithError("Could not get profile flag", err)
81+
}
82+
83+
if deleteAll {
84+
if profileFlag != constants.DefaultMachineName {
85+
exit.UsageT("usage: minikube delete --all")
86+
}
87+
88+
validProfiles, invalidProfiles, err := pkg_config.ListProfiles()
89+
profilesToDelete := append(validProfiles, invalidProfiles...)
90+
91+
if err != nil {
92+
exit.WithError("Error getting profiles to delete", err)
93+
}
94+
95+
errs := DeleteProfiles(profilesToDelete)
96+
if len(errs) > 0 {
97+
HandleDeletionErrors(errs)
98+
} else {
99+
out.T(out.DeletingHost, "Successfully deleted all profiles")
100+
}
101+
} else {
102+
if len(args) > 0 {
103+
exit.UsageT("usage: minikube delete")
104+
}
105+
106+
profileName := viper.GetString(pkg_config.MachineProfile)
107+
profile, err := pkg_config.LoadProfile(profileName)
108+
if err != nil {
109+
out.ErrT(out.Meh, `"{{.name}}" profile does not exist`, out.V{"name": profileName})
110+
}
111+
112+
errs := DeleteProfiles([]*pkg_config.Profile{profile})
113+
if len(errs) > 0 {
114+
HandleDeletionErrors(errs)
115+
} else {
116+
out.T(out.DeletingHost, "Successfully deleted profile \"{{.name}}\"", out.V{"name": profileName})
117+
}
118+
}
119+
}
120+
121+
// Deletes one or more profiles
122+
func DeleteProfiles(profiles []*pkg_config.Profile) []error {
123+
var errs []error
124+
for _, profile := range profiles {
125+
err := deleteProfile(profile)
126+
127+
if err != nil {
128+
mm, loadErr := cluster.LoadMachine(profile.Name)
129+
130+
if !profile.IsValid() || (loadErr != nil || !mm.IsValid()) {
131+
invalidProfileDeletionErrs := deleteInvalidProfile(profile)
132+
if len(invalidProfileDeletionErrs) > 0 {
133+
errs = append(errs, invalidProfileDeletionErrs...)
134+
}
135+
} else {
136+
errs = append(errs, err)
137+
}
138+
}
139+
}
140+
return errs
141+
}
142+
143+
func deleteProfile(profile *pkg_config.Profile) error {
144+
viper.Set(pkg_config.MachineProfile, profile.Name)
145+
60146
api, err := machine.NewAPIClient()
61147
if err != nil {
62-
exit.WithError("Error getting client", err)
148+
delErr := profileDeletionErr(profile.Name, fmt.Sprintf("error getting client %v", err))
149+
return DeletionError{Err: delErr, Errtype: Fatal}
63150
}
64151
defer api.Close()
65152

66153
cc, err := pkg_config.Load()
67154
if err != nil && !os.IsNotExist(err) {
68155
out.ErrT(out.Sad, "Error loading profile {{.name}}: {{.error}}", out.V{"name": profile, "error": err})
156+
delErr := profileDeletionErr(profile.Name, fmt.Sprintf("error loading profile config: %v", err))
157+
return DeletionError{Err: delErr, Errtype: MissingProfile}
69158
}
70159

71160
// In the case of "none", we want to uninstall Kubernetes as there is no VM to delete
72161
if err == nil && cc.MachineConfig.VMDriver == constants.DriverNone {
73-
uninstallKubernetes(api, cc.KubernetesConfig, viper.GetString(cmdcfg.Bootstrapper))
162+
if err := uninstallKubernetes(api, cc.KubernetesConfig, viper.GetString(cmdcfg.Bootstrapper)); err != nil {
163+
deletionError, ok := err.(DeletionError)
164+
if ok {
165+
delErr := profileDeletionErr(profile.Name, fmt.Sprintf("%v", err))
166+
deletionError.Err = delErr
167+
return deletionError
168+
}
169+
return err
170+
}
74171
}
75172

76173
if err := killMountProcess(); err != nil {
@@ -83,39 +180,111 @@ func runDelete(cmd *cobra.Command, args []string) {
83180
out.T(out.Meh, `"{{.name}}" cluster does not exist. Proceeding ahead with cleanup.`, out.V{"name": profile})
84181
default:
85182
out.T(out.FailureType, "Failed to delete cluster: {{.error}}", out.V{"error": err})
86-
out.T(out.Notice, `You may need to manually remove the "{{.name}}" VM from your hypervisor`, out.V{"name": profile})
183+
out.T(out.Notice, `You may need to manually remove the "{{.name}}" VM from your hypervisor`, out.V{"name": profile.Name})
87184
}
88185
}
89186

90187
// In case DeleteHost didn't complete the job.
91-
deleteProfileDirectory(profile)
188+
deleteProfileDirectory(profile.Name)
92189

93-
if err := pkg_config.DeleteProfile(profile); err != nil {
190+
if err := pkg_config.DeleteProfile(profile.Name); err != nil {
94191
if os.IsNotExist(err) {
95-
out.T(out.Meh, `"{{.name}}" profile does not exist`, out.V{"name": profile})
96-
os.Exit(0)
192+
delErr := profileDeletionErr(profile.Name, fmt.Sprintf("\"%s\" profile does not exist", profile.Name))
193+
return DeletionError{Err: delErr, Errtype: MissingProfile}
97194
}
98-
exit.WithError("Failed to remove profile", err)
195+
delErr := profileDeletionErr(profile.Name, fmt.Sprintf("failed to remove profile %v", err))
196+
return DeletionError{Err: delErr, Errtype: Fatal}
99197
}
100-
out.T(out.Crushed, `The "{{.name}}" cluster has been deleted.`, out.V{"name": profile})
198+
199+
out.T(out.Crushed, `The "{{.name}}" cluster has been deleted.`, out.V{"name": profile.Name})
101200

102201
machineName := pkg_config.GetMachineName()
103202
if err := kubeconfig.DeleteContext(constants.KubeconfigPath, machineName); err != nil {
104-
exit.WithError("update config", err)
203+
return DeletionError{Err: fmt.Errorf("update config: %v", err), Errtype: Fatal}
105204
}
106205

107206
if err := cmdcfg.Unset(pkg_config.MachineProfile); err != nil {
108-
exit.WithError("unset minikube profile", err)
207+
return DeletionError{Err: fmt.Errorf("unset minikube profile: %v", err), Errtype: Fatal}
109208
}
209+
return nil
110210
}
111211

112-
func uninstallKubernetes(api libmachine.API, kc pkg_config.KubernetesConfig, bsName string) {
212+
func deleteInvalidProfile(profile *pkg_config.Profile) []error {
213+
out.T(out.DeletingHost, "Trying to delete invalid profile {{.profile}}", out.V{"profile": profile.Name})
214+
215+
var errs []error
216+
pathToProfile := pkg_config.ProfileFolderPath(profile.Name, localpath.MiniPath())
217+
if _, err := os.Stat(pathToProfile); !os.IsNotExist(err) {
218+
err := os.RemoveAll(pathToProfile)
219+
if err != nil {
220+
errs = append(errs, DeletionError{err, Fatal})
221+
}
222+
}
223+
224+
pathToMachine := cluster.MachinePath(profile.Name, localpath.MiniPath())
225+
if _, err := os.Stat(pathToMachine); !os.IsNotExist(err) {
226+
err := os.RemoveAll(pathToMachine)
227+
if err != nil {
228+
errs = append(errs, DeletionError{err, Fatal})
229+
}
230+
}
231+
return errs
232+
}
233+
234+
func profileDeletionErr(profileName string, additionalInfo string) error {
235+
return fmt.Errorf("error deleting profile \"%s\": %s", profileName, additionalInfo)
236+
}
237+
238+
func uninstallKubernetes(api libmachine.API, kc pkg_config.KubernetesConfig, bsName string) error {
113239
out.T(out.Resetting, "Uninstalling Kubernetes {{.kubernetes_version}} using {{.bootstrapper_name}} ...", out.V{"kubernetes_version": kc.KubernetesVersion, "bootstrapper_name": bsName})
114240
clusterBootstrapper, err := getClusterBootstrapper(api, bsName)
115241
if err != nil {
116-
out.ErrT(out.Empty, "Unable to get bootstrapper: {{.error}}", out.V{"error": err})
242+
return DeletionError{Err: fmt.Errorf("unable to get bootstrapper: %v", err), Errtype: Fatal}
117243
} else if err = clusterBootstrapper.DeleteCluster(kc); err != nil {
118-
out.ErrT(out.Empty, "Failed to delete cluster: {{.error}}", out.V{"error": err})
244+
return DeletionError{Err: fmt.Errorf("failed to delete cluster: %v", err), Errtype: Fatal}
245+
}
246+
return nil
247+
}
248+
249+
// Handles deletion error from DeleteProfiles
250+
func HandleDeletionErrors(errors []error) {
251+
if len(errors) == 1 {
252+
handleSingleDeletionError(errors[0])
253+
} else {
254+
handleMultipleDeletionErrors(errors)
255+
}
256+
}
257+
258+
func handleSingleDeletionError(err error) {
259+
deletionError, ok := err.(DeletionError)
260+
261+
if ok {
262+
switch deletionError.Errtype {
263+
case Fatal:
264+
out.FatalT(deletionError.Error())
265+
case MissingProfile:
266+
out.ErrT(out.Sad, deletionError.Error())
267+
case MissingCluster:
268+
out.ErrT(out.Meh, deletionError.Error())
269+
default:
270+
out.FatalT(deletionError.Error())
271+
}
272+
} else {
273+
exit.WithError("Could not process error from failed deletion", err)
274+
}
275+
}
276+
277+
func handleMultipleDeletionErrors(errors []error) {
278+
out.ErrT(out.Sad, "Multiple errors deleting profiles")
279+
280+
for _, err := range errors {
281+
deletionError, ok := err.(DeletionError)
282+
283+
if ok {
284+
glog.Errorln(deletionError.Error())
285+
} else {
286+
exit.WithError("Could not process errors from failed deletion", err)
287+
}
119288
}
120289
}
121290

@@ -177,3 +346,8 @@ func killMountProcess() error {
177346
}
178347
return nil
179348
}
349+
350+
func init() {
351+
deleteCmd.Flags().BoolVar(&deleteAll, "all", false, "Set flag to delete all profiles")
352+
RootCmd.AddCommand(deleteCmd)
353+
}

0 commit comments

Comments
 (0)