forked from kubernetes/minikube
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconstants.go
399 lines (337 loc) · 14.5 KB
/
constants.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
/*
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 constants
import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"time"
"github.com/blang/semver"
"github.com/golang/glog"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
minikubeVersion "k8s.io/minikube/pkg/version"
)
// APIServerPort is the port that the API server should listen on.
const (
APIServerName = "minikubeCA"
ClusterDNSDomain = "cluster.local"
)
// MinikubeHome is the name of the minikube home directory variable.
const MinikubeHome = "MINIKUBE_HOME"
// GetMinipath returns the path to the user's minikube dir
func GetMinipath() string {
if os.Getenv(MinikubeHome) == "" {
return DefaultMinipath
}
if filepath.Base(os.Getenv(MinikubeHome)) == ".minikube" {
return os.Getenv(MinikubeHome)
}
return filepath.Join(os.Getenv(MinikubeHome), ".minikube")
}
// SupportedVMDrivers is a list of supported drivers on all platforms. Currently
// used in gendocs.
var SupportedVMDrivers = [...]string{
"virtualbox",
"parallels",
"vmwarefusion",
"kvm",
"xhyve",
"hyperv",
"hyperkit",
"kvm2",
"vmware",
"none",
}
// DefaultMinipath is the default Minikube path (under the home directory)
var DefaultMinipath = filepath.Join(homedir.HomeDir(), ".minikube")
// KubeconfigPath is the path to the Kubernetes client config
var KubeconfigPath = clientcmd.RecommendedHomeFile
// KubeconfigEnvVar is the env var to check for the Kubernetes client config
var KubeconfigEnvVar = clientcmd.RecommendedConfigPathEnvVar
// MinikubeContext is the kubeconfig context name used for minikube
const MinikubeContext = "minikube"
// MinikubeEnvPrefix is the prefix for the environmental variables
const MinikubeEnvPrefix = "MINIKUBE"
// DefaultMachineName is the default name for the VM
const DefaultMachineName = "minikube"
// DefaultNodeName is the default name for the kubeadm node within the VM
const DefaultNodeName = "minikube"
// DefaultStorageClassProvisioner is the name of the default storage class provisioner
const DefaultStorageClassProvisioner = "standard"
// Cache is used to modify the cache field in the config file
const Cache = "cache"
// TunnelRegistryPath returns the path to the runnel registry file
func TunnelRegistryPath() string {
return filepath.Join(GetMinipath(), "tunnels.json")
}
// MakeMiniPath is a utility to calculate a relative path to our directory.
func MakeMiniPath(fileName ...string) string {
args := []string{GetMinipath()}
args = append(args, fileName...)
return filepath.Join(args...)
}
// MountProcessFileName is the filename of the mount process
var MountProcessFileName = ".mount-process"
const (
// DefaultKeepContext is if we should keep context by default
DefaultKeepContext = false
// SHASuffix is the suffix of a SHA-256 checksum file
SHASuffix = ".sha256"
// DefaultMemory is the default memory of a host, in megabytes
DefaultMemory = 2048
// DefaultCPUS is the default number of cpus of a host
DefaultCPUS = 2
// DefaultDiskSize is the default disk image size, parseable
DefaultDiskSize = "20g"
// MinimumDiskSizeMB is the minimum disk image size, in megabytes
MinimumDiskSizeMB = 2000
// DefaultVMDriver is the default virtual machine driver name
DefaultVMDriver = "virtualbox"
// DefaultStatusFormat is the default format of a host
DefaultStatusFormat = `host: {{.Host}}
kubelet: {{.Kubelet}}
apiserver: {{.APIServer}}
kubectl: {{.Kubeconfig}}
`
// DefaultAddonListFormat is the default format of addon list
DefaultAddonListFormat = "- {{.AddonName}}: {{.AddonStatus}}\n"
// DefaultConfigViewFormat is the default format of config view
DefaultConfigViewFormat = "- {{.ConfigKey}}: {{.ConfigValue}}\n"
// DefaultCacheListFormat is the default format of cache list
DefaultCacheListFormat = "{{.CacheImage}}\n"
// GithubMinikubeReleasesURL is the URL of the minikube github releases JSON file
GithubMinikubeReleasesURL = "https://storage.googleapis.com/minikube/releases.json"
// DefaultWait is the default wait time, in seconds
DefaultWait = 20
// DefaultInterval is the default interval, in seconds
DefaultInterval = 6
// DefaultK8sClientTimeout is the default kubernetes client timeout
DefaultK8sClientTimeout = 60 * time.Second
// DefaultClusterBootstrapper is the default cluster bootstrapper
DefaultClusterBootstrapper = "kubeadm"
)
// DefaultISOURL is the default location of the minikube.iso file
var DefaultISOURL = fmt.Sprintf("https://storage.googleapis.com/%s/minikube-%s.iso", minikubeVersion.GetISOPath(), minikubeVersion.GetISOVersion())
// DefaultISOSHAURL is the default location of the minikube.iso.sha256 file
var DefaultISOSHAURL = DefaultISOURL + SHASuffix
// DefaultKubernetesVersion is the default kubernetes version
var DefaultKubernetesVersion = "v1.14.1"
// NewestKubernetesVersion is the newest Kubernetes version to test against
var NewestKubernetesVersion = "v1.14.1"
// OldestKubernetesVersion is the oldest Kubernetes version to test against
var OldestKubernetesVersion = "v1.10.13"
// ConfigFilePath is the path of the config directory
var ConfigFilePath = MakeMiniPath("config")
// ConfigFile is the path of the config file
var ConfigFile = MakeMiniPath("config", "config.json")
// GetProfileFile returns the Minikube profile config file
func GetProfileFile(profile string) string {
return filepath.Join(GetMinipath(), "profiles", profile, "config.json")
}
// DockerAPIVersion is the API version implemented by Docker running in the minikube VM.
const DockerAPIVersion = "1.35"
// ReportingURL is the URL for reporting a minikube error
const ReportingURL = "https://clouderrorreporting.googleapis.com/v1beta1/projects/k8s-minikube/events:report?key=AIzaSyACUwzG0dEPcl-eOgpDKnyKoUFgHdfoFuA"
// AddonsPath is the default path of the addons configuration
const AddonsPath = "/etc/kubernetes/addons"
// FilesPath is the default path of files
const FilesPath = "/files"
const (
// KubeletServiceFile is the path to the kubelet systemd service
KubeletServiceFile = "/lib/systemd/system/kubelet.service"
// KubeletSystemdConfFile is the path to the kubelet systemd configuration
KubeletSystemdConfFile = "/etc/systemd/system/kubelet.service.d/10-kubeadm.conf"
// KubeadmConfigFile is the path to the kubeadm configuration
KubeadmConfigFile = "/var/lib/kubeadm.yaml"
// DefaultCNIConfigPath is the path to the CNI configuration
DefaultCNIConfigPath = "/etc/cni/net.d/k8s.conf"
// DefaultRktNetConfigPath is the path to the rkt net configuration
DefaultRktNetConfigPath = "/etc/rkt/net.d/k8s.conf"
)
const (
// DefaultUfsPort is the default port of UFS
DefaultUfsPort = "5640"
// DefaultUfsDebugLvl is the default debug level of UFS
DefaultUfsDebugLvl = 0
// DefaultMountEndpoint is the default mount endpoint
DefaultMountEndpoint = "/minikube-host"
// DefaultMsize is the default number of bytes to use for 9p packet payload
DefaultMsize = 262144
// DefaultMountVersion is the default 9p version to use for mount
DefaultMountVersion = "9p2000.L"
)
// ImageRepositories contains all known image repositories
var ImageRepositories = map[string][]string{
"": {""}, // global
"cn": {"registry.cn-hangzhou.aliyuncs.com/google_containers"},
}
// GetKubernetesReleaseURL gets the location of a kubernetes client
func GetKubernetesReleaseURL(binaryName, version string) string {
return fmt.Sprintf("https://storage.googleapis.com/kubernetes-release/release/%s/bin/linux/%s/%s", version, runtime.GOARCH, binaryName)
}
// GetKubernetesReleaseURLSHA1 gets the location of a kubernetes client checksum
func GetKubernetesReleaseURLSHA1(binaryName, version string) string {
return fmt.Sprintf("%s.sha1", GetKubernetesReleaseURL(binaryName, version))
}
// IsMinikubeChildProcess is the name of "is minikube child process" variable
const IsMinikubeChildProcess = "IS_MINIKUBE_CHILD_PROCESS"
// DriverNone is the none driver
const DriverNone = "none"
// FileScheme is the file scheme
const FileScheme = "file"
// GetKubeadmCachedBinaries gets the binaries to cache for kubeadm
func GetKubeadmCachedBinaries() []string {
return []string{"kubelet", "kubeadm"}
}
// GetKubeadmCachedImages gets the images to cache for kubeadm for a version
func GetKubeadmCachedImages(imageRepository string, kubernetesVersionStr string) (string, []string) {
minikubeRepository := imageRepository
if imageRepository == "" {
imageRepository = "k8s.gcr.io"
minikubeRepository = "gcr.io/k8s-minikube"
}
if !strings.HasSuffix(imageRepository, "/") {
imageRepository += "/"
}
if !strings.HasSuffix(minikubeRepository, "/") {
minikubeRepository += "/"
}
v1_14plus := semver.MustParseRange(">=1.14.0")
v1_13 := semver.MustParseRange(">=1.13.0 <1.14.0")
v1_12 := semver.MustParseRange(">=1.12.0 <1.13.0")
v1_11 := semver.MustParseRange(">=1.11.0 <1.12.0")
v1_10 := semver.MustParseRange(">=1.10.0 <1.11.0")
v1_9 := semver.MustParseRange(">=1.9.0 <1.10.0")
v1_8 := semver.MustParseRange(">=1.8.0 <1.9.0")
v1_12plus := semver.MustParseRange(">=1.12.0")
kubernetesVersion, err := semver.Make(strings.TrimPrefix(kubernetesVersionStr, minikubeVersion.VersionPrefix))
if err != nil {
glog.Errorln("Error parsing version semver: ", err)
}
var images []string
if v1_12plus(kubernetesVersion) {
images = append(images, []string{
imageRepository + "kube-proxy:" + kubernetesVersionStr,
imageRepository + "kube-scheduler:" + kubernetesVersionStr,
imageRepository + "kube-controller-manager:" + kubernetesVersionStr,
imageRepository + "kube-apiserver:" + kubernetesVersionStr,
}...)
} else {
images = append(images, []string{
imageRepository + "kube-proxy-amd64:" + kubernetesVersionStr,
imageRepository + "kube-scheduler-amd64:" + kubernetesVersionStr,
imageRepository + "kube-controller-manager-amd64:" + kubernetesVersionStr,
imageRepository + "kube-apiserver-amd64:" + kubernetesVersionStr,
}...)
}
var podInfraContainerImage string
if v1_14plus(kubernetesVersion) {
podInfraContainerImage = imageRepository + "pause:3.1"
images = append(images, []string{
podInfraContainerImage,
imageRepository + "k8s-dns-kube-dns-amd64:1.14.13",
imageRepository + "k8s-dns-dnsmasq-nanny-amd64:1.14.13",
imageRepository + "k8s-dns-sidecar-amd64:1.14.13",
imageRepository + "etcd:3.3.10",
imageRepository + "coredns:1.3.1",
}...)
} else if v1_13(kubernetesVersion) {
podInfraContainerImage = imageRepository + "pause:3.1"
images = append(images, []string{
podInfraContainerImage,
imageRepository + "k8s-dns-kube-dns-amd64:1.14.8",
imageRepository + "k8s-dns-dnsmasq-nanny-amd64:1.14.8",
imageRepository + "k8s-dns-sidecar-amd64:1.14.8",
imageRepository + "etcd:3.2.24",
imageRepository + "coredns:1.2.6",
}...)
} else if v1_12(kubernetesVersion) {
podInfraContainerImage = imageRepository + "pause:3.1"
images = append(images, []string{
podInfraContainerImage,
imageRepository + "k8s-dns-kube-dns-amd64:1.14.8",
imageRepository + "k8s-dns-dnsmasq-nanny-amd64:1.14.8",
imageRepository + "k8s-dns-sidecar-amd64:1.14.8",
imageRepository + "etcd:3.2.24",
imageRepository + "coredns:1.2.2",
}...)
} else if v1_11(kubernetesVersion) {
podInfraContainerImage = imageRepository + "pause:3.1"
images = append(images, []string{
podInfraContainerImage,
imageRepository + "k8s-dns-kube-dns-amd64:1.14.8",
imageRepository + "k8s-dns-dnsmasq-nanny-amd64:1.14.8",
imageRepository + "k8s-dns-sidecar-amd64:1.14.8",
imageRepository + "etcd-amd64:3.2.18",
imageRepository + "coredns:1.1.3",
}...)
} else if v1_10(kubernetesVersion) {
podInfraContainerImage = imageRepository + "pause:3.1"
images = append(images, []string{
podInfraContainerImage,
imageRepository + "k8s-dns-kube-dns-amd64:1.14.8",
imageRepository + "k8s-dns-dnsmasq-nanny-amd64:1.14.8",
imageRepository + "k8s-dns-sidecar-amd64:1.14.8",
imageRepository + "etcd-amd64:3.1.12",
}...)
} else if v1_9(kubernetesVersion) {
podInfraContainerImage = imageRepository + "pause:3.0"
images = append(images, []string{
podInfraContainerImage,
imageRepository + "k8s-dns-kube-dns-amd64:1.14.7",
imageRepository + "k8s-dns-dnsmasq-nanny-amd64:1.14.7",
imageRepository + "k8s-dns-sidecar-amd64:1.14.7",
imageRepository + "etcd-amd64:3.1.10",
}...)
} else if v1_8(kubernetesVersion) {
podInfraContainerImage = imageRepository + "pause:3.0"
images = append(images, []string{
podInfraContainerImage,
imageRepository + "k8s-dns-kube-dns-amd64:1.14.5",
imageRepository + "k8s-dns-dnsmasq-nanny-amd64:1.14.5",
imageRepository + "k8s-dns-sidecar-amd64:1.14.5",
imageRepository + "etcd-amd64:3.0.17",
}...)
} else {
podInfraContainerImage = imageRepository + "pause:3.0"
}
images = append(images, []string{
imageRepository + "kubernetes-dashboard-amd64:v1.10.1",
imageRepository + "kube-addon-manager:v9.0",
minikubeRepository + "storage-provisioner:v1.8.1",
}...)
return podInfraContainerImage, images
}
// ImageCacheDir is the path to the image cache directory
var ImageCacheDir = MakeMiniPath("cache", "images")
const (
// GvisorFilesPath is the path to the gvisor files saved by go-bindata
GvisorFilesPath = "/tmp/gvisor"
// ContainerdConfigTomlPath is the path to the containerd config.toml
ContainerdConfigTomlPath = "/etc/containerd/config.toml"
// GvisorContainerdShimTomlPath is the path to gvisor-containerd-shim.toml
GvisorContainerdShimTomlPath = "/etc/containerd/gvisor-containerd-shim.toml"
// StoredContainerdConfigTomlPath is the path where the default config.toml will be stored
StoredContainerdConfigTomlPath = "/tmp/config.toml"
//GvisorConfigTomlTargetName is the go-bindata target name for the gvisor config.toml
GvisorConfigTomlTargetName = "gvisor-config.toml"
// GvisorContainerdShimTargetName is the go-bindata target name for gvisor-containerd-shim
GvisorContainerdShimTargetName = "gvisor-containerd-shim.toml"
// GvisorContainerdShimURL is the url to download gvisor-containerd-shim
GvisorContainerdShimURL = "https://github.com/google/gvisor-containerd-shim/releases/download/v0.0.1-rc.0/gvisor-containerd-shim-v0.0.1-rc.0.linux-amd64"
// GvisorURL is the url to download gvisor
GvisorURL = "https://storage.googleapis.com/gvisor/releases/nightly/2018-12-07/runsc"
)