diff --git a/Makefile b/Makefile index a4ac1844cd..42bfe174ee 100755 --- a/Makefile +++ b/Makefile @@ -51,13 +51,13 @@ MINIKUBE_RELEASES_URL=https://github.com/kubernetes/minikube/releases/download KERNEL_VERSION ?= 4.15 # latest from https://github.com/golangci/golangci-lint/releases -GOLINT_VERSION ?= v1.18.0 +GOLINT_VERSION ?= v1.20.0 # Limit number of default jobs, to avoid the CI builds running out of memory GOLINT_JOBS ?= 4 # see https://github.com/golangci/golangci-lint#memory-usage-of-golangci-lint -GOLINT_GOGC ?= 8 +GOLINT_GOGC ?= 100 # options for lint (golangci-lint) -GOLINT_OPTIONS = --deadline 4m \ +GOLINT_OPTIONS = --timeout 4m \ --build-tags "${MINIKUBE_INTEGRATION_BUILD_TAGS}" \ --enable goimports,gocritic,golint,gocyclo,misspell,nakedret,stylecheck,unconvert,unparam \ --exclude 'variable on range scope.*in function literal|ifElseChain' diff --git a/cmd/minikube/cmd/config/profile.go b/cmd/minikube/cmd/config/profile.go index 8c59829840..cbf6f1fe6d 100644 --- a/cmd/minikube/cmd/config/profile.go +++ b/cmd/minikube/cmd/config/profile.go @@ -47,6 +47,12 @@ var ProfileCmd = &cobra.Command{ profile := args[0] if profile == "default" { profile = "minikube" + } else { + // not validating when it is default profile + errProfile, ok := ValidateProfile(profile) + if !ok && errProfile != nil { + out.FailureT(errProfile.Msg) + } } if !pkgConfig.ProfileExists(profile) { diff --git a/cmd/minikube/cmd/config/util.go b/cmd/minikube/cmd/config/util.go index d103ba36ea..10be06c4f5 100644 --- a/cmd/minikube/cmd/config/util.go +++ b/cmd/minikube/cmd/config/util.go @@ -232,3 +232,42 @@ func EnableOrDisableStorageClasses(name, val string) error { return EnableOrDisableAddon(name, val) } + +// ErrValidateProfile Error to validate profile +type ErrValidateProfile struct { + Name string + Msg string +} + +func (e ErrValidateProfile) Error() string { + return e.Msg +} + +// ValidateProfile checks if the profile user is trying to switch exists, else throws error +func ValidateProfile(profile string) (*ErrValidateProfile, bool) { + + validProfiles, invalidProfiles, err := config.ListProfiles() + if err != nil { + out.FailureT(err.Error()) + } + + // handling invalid profiles + for _, invalidProf := range invalidProfiles { + if profile == invalidProf.Name { + return &ErrValidateProfile{Name: profile, Msg: fmt.Sprintf("%q is an invalid profile", profile)}, false + } + } + + profileFound := false + // valid profiles if found, setting profileFound to trueexpectedMsg + for _, prof := range validProfiles { + if prof.Name == profile { + profileFound = true + break + } + } + if !profileFound { + return &ErrValidateProfile{Name: profile, Msg: fmt.Sprintf("profile %q not found", profile)}, false + } + return nil, true +} diff --git a/cmd/minikube/cmd/config/util_test.go b/cmd/minikube/cmd/config/util_test.go index 3cbab76a38..11845ba6c4 100644 --- a/cmd/minikube/cmd/config/util_test.go +++ b/cmd/minikube/cmd/config/util_test.go @@ -17,6 +17,7 @@ limitations under the License. package config import ( + "fmt" "testing" "k8s.io/minikube/pkg/minikube/assets" @@ -111,3 +112,26 @@ func TestIsAddonAlreadySet(t *testing.T) { } } } + +func TestValidateProfile(t *testing.T) { + testCases := []struct { + profileName string + }{ + { + profileName: "82374328742_2974224498", + }, + { + profileName: "minikube", + }, + } + + for _, test := range testCases { + profileNam := test.profileName + expectedMsg := fmt.Sprintf("profile %q not found", test.profileName) + + err, ok := ValidateProfile(profileNam) + if !ok && err.Error() != expectedMsg { + t.Errorf("Didnt receive expected message") + } + } +} diff --git a/pkg/minikube/bootstrapper/kubeadm/kubeadm_test.go b/pkg/minikube/bootstrapper/kubeadm/kubeadm_test.go index 8a880dc49a..f6d696816d 100644 --- a/pkg/minikube/bootstrapper/kubeadm/kubeadm_test.go +++ b/pkg/minikube/bootstrapper/kubeadm/kubeadm_test.go @@ -66,7 +66,7 @@ Wants=crio.service [Service] ExecStart= -ExecStart=/var/lib/minikube/binaries/v1.16.0/kubelet --authorization-mode=Webhook --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --cgroup-driver=cgroupfs --client-ca-file=/var/lib/minikube/certs/ca.crt --cluster-dns=10.96.0.10 --cluster-domain=cluster.local --container-runtime=remote --container-runtime-endpoint=/var/run/crio/crio.sock --fail-swap-on=false --hostname-override=minikube --image-service-endpoint=/var/run/crio/crio.sock --kubeconfig=/etc/kubernetes/kubelet.conf --node-ip=192.168.1.100 --pod-manifest-path=/etc/kubernetes/manifests --runtime-request-timeout=15m +ExecStart=/var/lib/minikube/binaries/v1.16.1/kubelet --authorization-mode=Webhook --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --cgroup-driver=cgroupfs --client-ca-file=/var/lib/minikube/certs/ca.crt --cluster-dns=10.96.0.10 --cluster-domain=cluster.local --container-runtime=remote --container-runtime-endpoint=/var/run/crio/crio.sock --fail-swap-on=false --hostname-override=minikube --image-service-endpoint=/var/run/crio/crio.sock --kubeconfig=/etc/kubernetes/kubelet.conf --node-ip=192.168.1.100 --pod-manifest-path=/etc/kubernetes/manifests --runtime-request-timeout=15m [Install] `, @@ -84,7 +84,7 @@ Wants=containerd.service [Service] ExecStart= -ExecStart=/var/lib/minikube/binaries/v1.16.0/kubelet --authorization-mode=Webhook --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --cgroup-driver=cgroupfs --client-ca-file=/var/lib/minikube/certs/ca.crt --cluster-dns=10.96.0.10 --cluster-domain=cluster.local --container-runtime=remote --container-runtime-endpoint=unix:///run/containerd/containerd.sock --fail-swap-on=false --hostname-override=minikube --image-service-endpoint=unix:///run/containerd/containerd.sock --kubeconfig=/etc/kubernetes/kubelet.conf --node-ip=192.168.1.100 --pod-manifest-path=/etc/kubernetes/manifests --runtime-request-timeout=15m +ExecStart=/var/lib/minikube/binaries/v1.16.1/kubelet --authorization-mode=Webhook --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --cgroup-driver=cgroupfs --client-ca-file=/var/lib/minikube/certs/ca.crt --cluster-dns=10.96.0.10 --cluster-domain=cluster.local --container-runtime=remote --container-runtime-endpoint=unix:///run/containerd/containerd.sock --fail-swap-on=false --hostname-override=minikube --image-service-endpoint=unix:///run/containerd/containerd.sock --kubeconfig=/etc/kubernetes/kubelet.conf --node-ip=192.168.1.100 --pod-manifest-path=/etc/kubernetes/manifests --runtime-request-timeout=15m [Install] `, @@ -109,7 +109,7 @@ Wants=containerd.service [Service] ExecStart= -ExecStart=/var/lib/minikube/binaries/v1.16.0/kubelet --authorization-mode=Webhook --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --cgroup-driver=cgroupfs --client-ca-file=/var/lib/minikube/certs/ca.crt --cluster-dns=10.96.0.10 --cluster-domain=cluster.local --container-runtime=remote --container-runtime-endpoint=unix:///run/containerd/containerd.sock --fail-swap-on=false --hostname-override=minikube --image-service-endpoint=unix:///run/containerd/containerd.sock --kubeconfig=/etc/kubernetes/kubelet.conf --node-ip=192.168.1.200 --pod-manifest-path=/etc/kubernetes/manifests --runtime-request-timeout=15m +ExecStart=/var/lib/minikube/binaries/v1.16.1/kubelet --authorization-mode=Webhook --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --cgroup-driver=cgroupfs --client-ca-file=/var/lib/minikube/certs/ca.crt --cluster-dns=10.96.0.10 --cluster-domain=cluster.local --container-runtime=remote --container-runtime-endpoint=unix:///run/containerd/containerd.sock --fail-swap-on=false --hostname-override=minikube --image-service-endpoint=unix:///run/containerd/containerd.sock --kubeconfig=/etc/kubernetes/kubelet.conf --node-ip=192.168.1.200 --pod-manifest-path=/etc/kubernetes/manifests --runtime-request-timeout=15m [Install] `, @@ -128,7 +128,7 @@ Wants=docker.socket [Service] ExecStart= -ExecStart=/var/lib/minikube/binaries/v1.16.0/kubelet --authorization-mode=Webhook --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --cgroup-driver=cgroupfs --client-ca-file=/var/lib/minikube/certs/ca.crt --cluster-dns=10.96.0.10 --cluster-domain=cluster.local --container-runtime=docker --fail-swap-on=false --hostname-override=minikube --kubeconfig=/etc/kubernetes/kubelet.conf --node-ip=192.168.1.100 --pod-infra-container-image=docker-proxy-image.io/google_containers/pause:3.1 --pod-manifest-path=/etc/kubernetes/manifests +ExecStart=/var/lib/minikube/binaries/v1.16.1/kubelet --authorization-mode=Webhook --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --cgroup-driver=cgroupfs --client-ca-file=/var/lib/minikube/certs/ca.crt --cluster-dns=10.96.0.10 --cluster-domain=cluster.local --container-runtime=docker --fail-swap-on=false --hostname-override=minikube --kubeconfig=/etc/kubernetes/kubelet.conf --node-ip=192.168.1.100 --pod-infra-container-image=docker-proxy-image.io/google_containers/pause:3.1 --pod-manifest-path=/etc/kubernetes/manifests [Install] `, diff --git a/pkg/minikube/constants/constants.go b/pkg/minikube/constants/constants.go index 3f005e3516..1c61d75e06 100644 --- a/pkg/minikube/constants/constants.go +++ b/pkg/minikube/constants/constants.go @@ -92,10 +92,10 @@ var DefaultISOURL = fmt.Sprintf("https://storage.googleapis.com/%s/minikube-%s.i var DefaultISOSHAURL = DefaultISOURL + SHASuffix // DefaultKubernetesVersion is the default kubernetes version -var DefaultKubernetesVersion = "v1.16.0" +var DefaultKubernetesVersion = "v1.16.1" // NewestKubernetesVersion is the newest Kubernetes version to test against -var NewestKubernetesVersion = "v1.16.0" +var NewestKubernetesVersion = "v1.16.1" // OldestKubernetesVersion is the oldest Kubernetes version to test against var OldestKubernetesVersion = "v1.11.10" diff --git a/pkg/minikube/constants/constants_darwin.go b/pkg/minikube/constants/constants_darwin.go index 707f5f9925..29821c8d31 100644 --- a/pkg/minikube/constants/constants_darwin.go +++ b/pkg/minikube/constants/constants_darwin.go @@ -18,6 +18,7 @@ limitations under the License. package constants +// DefaultMountDir is the default mounting directory for Darwin var DefaultMountDir = "/Users" // SupportedVMDrivers is a list of supported drivers on Darwin. diff --git a/pkg/minikube/extract/extract.go b/pkg/minikube/extract/extract.go index 55a8969724..8453d53ea5 100644 --- a/pkg/minikube/extract/extract.go +++ b/pkg/minikube/extract/extract.go @@ -385,7 +385,7 @@ func checkKeyValueExpression(kvp *ast.KeyValueExpr, e *state) { // Ok now this is just a mess if help, ok := kvp.Value.(*ast.BinaryExpr); ok { - s := checkBinaryExpression(help, e) + s := checkBinaryExpression(help) if s != "" { e.translations[s] = "" } @@ -394,7 +394,7 @@ func checkKeyValueExpression(kvp *ast.KeyValueExpr, e *state) { } // checkBinaryExpression checks binary expressions, stuff of the form x + y, for strings and concats them -func checkBinaryExpression(b *ast.BinaryExpr, e *state) string { +func checkBinaryExpression(b *ast.BinaryExpr) string { // Check the left side var s string if l, ok := b.X.(*ast.BasicLit); ok { @@ -410,7 +410,7 @@ func checkBinaryExpression(b *ast.BinaryExpr, e *state) string { } if b1, ok := b.X.(*ast.BinaryExpr); ok { - if x := checkBinaryExpression(b1, e); x != "" { + if x := checkBinaryExpression(b1); x != "" { s += x } } @@ -429,7 +429,7 @@ func checkBinaryExpression(b *ast.BinaryExpr, e *state) string { } if b1, ok := b.Y.(*ast.BinaryExpr); ok { - if x := checkBinaryExpression(b1, e); x != "" { + if x := checkBinaryExpression(b1); x != "" { s += x } } diff --git a/pkg/minikube/tunnel/tunnel_manager.go b/pkg/minikube/tunnel/tunnel_manager.go index 69f9e972b1..4c3ed6f4d9 100644 --- a/pkg/minikube/tunnel/tunnel_manager.go +++ b/pkg/minikube/tunnel/tunnel_manager.go @@ -122,8 +122,8 @@ func (mgr *Manager) run(ctx context.Context, t controller, ready, check, done ch } } -func (mgr *Manager) cleanup(t controller) *Status { - return t.cleanup() +func (mgr *Manager) cleanup(t controller) { + t.cleanup() } // CleanupNotRunningTunnels cleans up tunnels that are not running