-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
config.go
127 lines (110 loc) · 3.96 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
Copyright 2020 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 node
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strconv"
"sync"
"github.com/spf13/viper"
"k8s.io/klog/v2"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/cruntime"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/out/register"
"k8s.io/minikube/pkg/minikube/reason"
"k8s.io/minikube/pkg/minikube/style"
"k8s.io/minikube/pkg/util"
"k8s.io/minikube/pkg/util/lock"
)
func showVersionInfo(k8sVersion string, cr cruntime.Manager) {
version, _ := cr.Version()
register.Reg.SetStep(register.PreparingKubernetes)
out.Step(cr.Style(), "Preparing Kubernetes {{.k8sVersion}} on {{.runtime}} {{.runtimeVersion}} ...", out.V{"k8sVersion": k8sVersion, "runtime": cr.Name(), "runtimeVersion": version})
for _, v := range config.DockerOpt {
v = util.MaskProxyPasswordWithKey(v)
out.Infof("opt {{.docker_option}}", out.V{"docker_option": v})
}
for _, v := range config.DockerEnv {
out.Infof("env {{.docker_env}}", out.V{"docker_env": v})
}
}
func showNoK8sVersionInfo(cr cruntime.Manager) {
err := cruntime.CheckCompatibility(cr)
if err != nil {
klog.Warningf("%s check compatibility failed: %v", cr.Name(), err)
}
version, err := cr.Version()
if err != nil {
klog.Warningf("%s get version failed: %v", cr.Name(), err)
}
out.Step(cr.Style(), "Preparing {{.runtime}} {{.runtimeVersion}} ...", out.V{"runtime": cr.Name(), "runtimeVersion": version})
}
// configureMounts configures any requested filesystem mounts
func configureMounts(wg *sync.WaitGroup, cc config.ClusterConfig) {
wg.Add(1)
defer wg.Done()
if !cc.Mount || driver.IsKIC(cc.Driver) {
return
}
out.Step(style.Mounting, "Creating mount {{.name}} ...", out.V{"name": cc.MountString})
path := os.Args[0]
profile := viper.GetString("profile")
args := generateMountArgs(profile, cc)
mountCmd := exec.Command(path, args...)
mountCmd.Env = append(os.Environ(), constants.IsMinikubeChildProcess+"=true")
if klog.V(8).Enabled() {
mountCmd.Stdout = os.Stdout
mountCmd.Stderr = os.Stderr
}
if err := mountCmd.Start(); err != nil {
exit.Error(reason.GuestMount, "Error starting mount", err)
}
if err := lock.AppendToFile(filepath.Join(localpath.Profile(profile), constants.MountProcessFileName), []byte(fmt.Sprintf(" %s", strconv.Itoa(mountCmd.Process.Pid))), 0o644); err != nil {
exit.Error(reason.HostMountPid, "Error writing mount pid", err)
}
}
func generateMountArgs(profile string, cc config.ClusterConfig) []string {
mountDebugVal := 0
if klog.V(8).Enabled() {
mountDebugVal = 1
}
args := []string{"mount", cc.MountString}
flags := []struct {
name string
value string
}{
{"profile", profile},
{"v", fmt.Sprintf("%d", mountDebugVal)},
{constants.Mount9PVersionFlag, cc.Mount9PVersion},
{constants.MountGIDFlag, cc.MountGID},
{constants.MountIPFlag, cc.MountIP},
{constants.MountMSizeFlag, fmt.Sprintf("%d", cc.MountMSize)},
{constants.MountPortFlag, fmt.Sprintf("%d", cc.MountPort)},
{constants.MountTypeFlag, cc.MountType},
{constants.MountUIDFlag, cc.MountUID},
}
for _, flag := range flags {
args = append(args, fmt.Sprintf("--%s", flag.name), flag.value)
}
for _, option := range cc.MountOptions {
args = append(args, fmt.Sprintf("--%s", constants.MountOptionsFlag), option)
}
return args
}