Merge branch 'master' of github.com:kubernetes/minikube into node-start

pull/8169/head
Sharif Elgamal 2020-05-18 11:52:57 -07:00
commit 412cef3002
15 changed files with 283 additions and 23 deletions

View File

@ -22,6 +22,7 @@ import (
"github.com/golang/glog"
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/localpath"
)
@ -32,21 +33,23 @@ type setFn func(string, string) error
// Setting represents a setting
type Setting struct {
name string
set func(config.MinikubeConfig, string, string) error
setMap func(config.MinikubeConfig, string, map[string]interface{}) error
validations []setFn
callbacks []setFn
name string
set func(config.MinikubeConfig, string, string) error
setMap func(config.MinikubeConfig, string, map[string]interface{}) error
validDefaults func() []string
validations []setFn
callbacks []setFn
}
// These are all the settings that are configurable
// and their validation and callback fn run on Set
var settings = []Setting{
{
name: "driver",
set: SetString,
validations: []setFn{IsValidDriver},
callbacks: []setFn{RequiresRestartMsg},
name: "driver",
set: SetString,
validDefaults: driver.SupportedDrivers,
validations: []setFn{IsValidDriver},
callbacks: []setFn{RequiresRestartMsg},
},
{
name: "vm-driver",

View File

@ -0,0 +1,92 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package config
import (
"encoding/json"
"fmt"
"strings"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/out"
)
var configDefaultsCommand = &cobra.Command{
Use: "defaults PROPERTY_NAME",
Short: "Lists all valid default values for PROPERTY_NAME",
Long: `list displays all valid default settings for PROPERTY_NAME
Acceptable fields: ` + "\n\n" + fieldsWithDefaults(),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
cmd.SilenceErrors = true
return errors.New("not enough arguments.\nusage: minikube config list PROPERTY_NAME")
}
if len(args) > 1 {
cmd.SilenceErrors = true
return fmt.Errorf("too many arguments (%d)\nusage: minikube config list PROPERTY_NAME", len(args))
}
property := args[0]
defaults, err := getDefaults(property)
if err != nil {
return err
}
return printDefaults(defaults)
},
}
func getDefaults(property string) ([]string, error) {
setting, err := findSetting(property)
if err != nil {
return nil, err
}
if setting.validDefaults == nil {
return nil, fmt.Errorf("%s is not a valid option for the `defaults` command; to see valid options run `minikube config defaults -h`", property)
}
return setting.validDefaults(), nil
}
func printDefaults(defaults []string) error {
if output == "json" {
encoding, err := json.Marshal(defaults)
if err != nil {
return errors.Wrap(err, "encoding json")
}
out.Ln(string(encoding))
return nil
}
for _, d := range defaults {
out.Ln("* %s", d)
}
return nil
}
func fieldsWithDefaults() string {
fields := []string{}
for _, s := range settings {
if s.validDefaults != nil {
fields = append(fields, " * "+s.name)
}
}
return strings.Join(fields, "\n")
}
func init() {
configDefaultsCommand.Flags().StringVar(&output, "output", "", "Output format. Accepted values: [json]")
ConfigCmd.AddCommand(configDefaultsCommand)
}

View File

@ -0,0 +1,91 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package config
import (
"testing"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/tests"
)
func TestGetDefaults(t *testing.T) {
tcs := []struct {
property string
expectedContents string
shouldErr bool
}{
{
property: "driver",
expectedContents: "docker",
}, {
property: "invalid",
shouldErr: true,
},
}
for _, tc := range tcs {
t.Run(tc.property, func(t *testing.T) {
defaults, err := getDefaults(tc.property)
if err != nil && !tc.shouldErr {
t.Fatalf("test shouldn't have failed, error listing defaults: %v", err)
}
if err == nil && tc.shouldErr {
t.Fatal("test should have failed but did not")
}
if tc.shouldErr {
return
}
for _, d := range defaults {
if d == tc.expectedContents {
return
}
}
t.Fatalf("defaults didn't contain expected default. Actual: %v\nExpected: %v\n", defaults, tc.expectedContents)
})
}
}
func TestPrintDefaults(t *testing.T) {
defaults := []string{"a", "b", "c"}
tcs := []struct {
description string
format string
expected string
}{
{
description: "print to stdout",
expected: "* a\n* b\n* c\n",
}, {
description: "print in json",
format: "json",
expected: "[\"a\",\"b\",\"c\"]\n",
},
}
for _, tc := range tcs {
t.Run(tc.description, func(t *testing.T) {
output = tc.format
f := tests.NewFakeFile()
out.SetOutFile(f)
if err := printDefaults(defaults); err != nil {
t.Fatalf("error printing defaults: %v", err)
}
if f.String() != tc.expected {
t.Fatalf("Expected: %v\n Actual: %v\n", tc.expected, f.String())
}
})
}
}

View File

@ -877,8 +877,27 @@ func validateRegistryMirror() {
}
}
func createNode(cc config.ClusterConfig, kubeNodeName string) (config.ClusterConfig, config.Node, error) {
func createNode(cc config.ClusterConfig, kubeNodeName string, existing *config.ClusterConfig) (config.ClusterConfig, config.Node, error) {
// Create the initial node, which will necessarily be a control plane
if existing != nil {
cp, err := config.PrimaryControlPlane(existing)
cp.KubernetesVersion = getKubernetesVersion(&cc)
if err != nil {
return cc, config.Node{}, err
}
// Make sure that existing nodes honor if KubernetesVersion gets specified on restart
// KubernetesVersion is the only attribute that the user can override in the Node object
nodes := []config.Node{}
for _, n := range existing.Nodes {
n.KubernetesVersion = getKubernetesVersion(&cc)
nodes = append(nodes, n)
}
cc.Nodes = nodes
return cc, cp, nil
}
cp := config.Node{
Port: cc.KubernetesConfig.NodePort,
KubernetesVersion: getKubernetesVersion(&cc),

View File

@ -348,7 +348,7 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k
if driver.BareMetal(cc.Driver) {
kubeNodeName = "m01"
}
return createNode(cc, kubeNodeName)
return createNode(cc, kubeNodeName, existing)
}
// updateExistingConfigFromFlags will update the existing config from the flags - used on a second start

View File

@ -46,7 +46,7 @@ spec:
value: kube-system
- name: TILLER_HISTORY_MAX
value: "0"
image: gcr.io/kubernetes-helm/tiller:v2.16.3
image: gcr.io/kubernetes-helm/tiller:v2.16.7
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3

View File

@ -24,7 +24,7 @@ metadata:
kubernetes.io/minikube-addons: helm
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: tiller-clusterrolebinding
labels:

1
go.sum
View File

@ -405,6 +405,7 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.9.5 h1:UImYN5qQ8tuGpGE16ZmjvcTtTw24zw1QAp/SlnNrZhI=
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hashicorp/go-cleanhttp v0.5.0 h1:wvCrVc9TjDls6+YGAF2hAifE1E5U1+b4tH6KdvN3Gig=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=

View File

@ -181,6 +181,12 @@ func generateSharedCACerts() (CACerts, error) {
// generateProfileCerts generates profile certs for a profile
func generateProfileCerts(k8s config.KubernetesConfig, n config.Node, ccs CACerts) ([]string, error) {
// Only generate these certs for the api server
if !n.ControlPlane {
return []string{}, nil
}
profilePath := localpath.Profile(k8s.ClusterName)
serviceIP, err := util.GetServiceClusterIP(k8s.ServiceCIDR)

View File

@ -76,12 +76,7 @@ func remoteTarballURL(k8sVersion, containerRuntime string) string {
}
// PreloadExists returns true if there is a preloaded tarball that can be used
func PreloadExists(k8sVersion, containerRuntime string) bool {
// TODO: debug why this func is being called two times
glog.Infof("Checking if preload exists for k8s version %s and runtime %s", k8sVersion, containerRuntime)
if !viper.GetBool("preload") {
return false
}
func PreloadExists(k8sVersion, containerRuntime string, forcePreload ...bool) bool {
// and https://github.com/kubernetes/minikube/issues/6934
// to track status of adding crio
@ -90,6 +85,18 @@ func PreloadExists(k8sVersion, containerRuntime string) bool {
return false
}
// TODO (#8166): Get rid of the need for this and viper at all
force := false
if len(forcePreload) > 0 {
force = forcePreload[0]
}
// TODO: debug why this func is being called two times
glog.Infof("Checking if preload exists for k8s version %s and runtime %s", k8sVersion, containerRuntime)
if !viper.GetBool("preload") && !force {
return false
}
// Omit remote check if tarball exists locally
targetPath := TarballPath(k8sVersion, containerRuntime)
if _, err := os.Stat(targetPath); err == nil {

View File

@ -68,6 +68,42 @@ minikube config SUBCOMMAND [flags]
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
```
## minikube config defaults
Lists all valid default values for PROPERTY_NAME
### Synopsis
list displays all valid default settings for PROPERTY_NAME
Acceptable fields:
* driver
```
minikube config defaults PROPERTY_NAME [flags]
```
### Options
```
-h, --help help for defaults
--output string Output format. Accepted values: [json]
```
### Options inherited from parent commands
```
--alsologtostderr log to standard error as well as files
-b, --bootstrapper string The name of the cluster bootstrapper that will set up the Kubernetes cluster. (default "kubeadm")
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log_dir string If non-empty, write log files in this directory
--logtostderr log to standard error instead of files
-p, --profile string The name of the minikube VM being used. This can be set to allow having multiple instances of minikube independently. (default "minikube")
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
-v, --v Level log level for V logs
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
```
## minikube config get
Gets the value of PROPERTY_NAME from the minikube config file

View File

@ -17,3 +17,9 @@ The easiest approach is to use the `docker` driver, as the backend service alway
`none` users may want to try `CHANGE_MINIKUBE_NONE_USER=true`, where kubectl and such will still work: [see environment variables]({{< ref "/docs/handbook/config.md#environment-variables" >}})
Alternatively, configure `sudo` to never prompt for the commands issued by minikube.
## How to ignore system verification?
minikube's bootstrapper, [Kubeadm] (https://github.com/kubernetes/kubeadm) verifies a list of features on the host system before installing Kubernetes. in case you get this error, and you still want to try minikube anyways despite your system's limitation you can skip the verification by starting minikube with this extra option:
`minikube start --extra-config kubeadm.ignore-preflight-errors=SystemVerification`

View File

@ -218,7 +218,7 @@ For more information on the `docker build` command, read the [Docker documentati
For Podman, use:
```shell
sudo -E podman build
sudo podman build
```
For more information on the `podman build` command, read the [Podman documentation](https://github.com/containers/libpod/blob/master/docs/source/markdown/podman-build.1.md) (podman.io).

View File

@ -57,7 +57,6 @@ func TestDownloadOnly(t *testing.T) {
t.Run(v, func(t *testing.T) {
defer PostMortemLogs(t, profile)
// Explicitly does not pass StartArgs() to test driver default
// --force to avoid uid check
args := append([]string{"start", "--download-only", "-p", profile, "--force", "--alsologtostderr", fmt.Sprintf("--kubernetes-version=%s", v), fmt.Sprintf("--container-runtime=%s", r)}, StartArgs()...)
@ -74,7 +73,7 @@ func TestDownloadOnly(t *testing.T) {
// skip for none, as none driver does not have preload feature.
if !NoneDriver() {
if download.PreloadExists(v, r) {
if download.PreloadExists(v, r, true) {
// Just make sure the tarball path exists
if _, err := os.Stat(download.TarballPath(v, r)); err != nil {
t.Errorf("failed to verify preloaded tarball file exists: %v", err)

View File

@ -203,7 +203,7 @@ func PostMortemLogs(t *testing.T, profile string) {
t.Logf("-----------------------post-mortem--------------------------------")
if DockerDriver() {
t.Logf("======> post-mortem[%s]: docker inpect <======", t.Name())
t.Logf("======> post-mortem[%s]: docker inspect <======", t.Name())
rr, err := Run(t, exec.Command("docker", "inspect", profile))
if err != nil {
t.Logf("failed to get docker inspect: %v", err)