-
Notifications
You must be signed in to change notification settings - Fork 5k
/
Copy pathconstants.go
277 lines (224 loc) · 8.67 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
/*
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"
"strings"
"github.com/blang/semver"
"github.com/golang/glog"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
"k8s.io/kubernetes/pkg/version"
minikubeVersion "k8s.io/minikube/pkg/version"
)
// APIServerPort is the port that the API server should listen on.
const (
APIServerName = "minikubeCA"
ClusterDNSDomain = "cluster.local"
)
const MinikubeHome = "MINIKUBE_HOME"
// Minipath is 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",
"vmwarefusion",
"kvm",
"xhyve",
"hyperv",
"hyperkit",
"kvm2",
"none",
}
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"
// The name of the default storage class provisioner
const DefaultStorageClassProvisioner = "standard"
// Used to modify the cache field in the config file
const Cache = "cache"
// 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...)
}
var MountProcessFileName = ".mount-process"
// Only pass along these flags to localkube.
var LogFlags = [...]string{
"v",
"vmodule",
}
const (
DefaultKeepContext = false
ShaSuffix = ".sha256"
DefaultMemory = 2048
DefaultCPUS = 2
DefaultDiskSize = "20g"
MinimumDiskSizeMB = 2000
DefaultVMDriver = "virtualbox"
DefaultStatusFormat = "minikube: {{.MinikubeStatus}}\n" +
"cluster: {{.ClusterStatus}}\n" + "kubectl: {{.KubeconfigStatus}}\n"
DefaultAddonListFormat = "- {{.AddonName}}: {{.AddonStatus}}\n"
DefaultConfigViewFormat = "- {{.ConfigKey}}: {{.ConfigValue}}\n"
DefaultCacheListFormat = "{{.CacheImage}}\n"
GithubMinikubeReleasesURL = "https://storage.googleapis.com/minikube/releases.json"
KubernetesVersionGCSURL = "https://storage.googleapis.com/minikube/k8s_releases.json"
DefaultWait = 20
DefaultInterval = 6
DefaultClusterBootstrapper = "kubeadm"
)
var DefaultIsoUrl = fmt.Sprintf("https://storage.googleapis.com/%s/minikube-%s.iso", minikubeVersion.GetIsoPath(), minikubeVersion.GetIsoVersion())
var DefaultIsoShaUrl = DefaultIsoUrl + ShaSuffix
var DefaultKubernetesVersion = version.Get().GitVersion
var ConfigFilePath = MakeMiniPath("config")
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")
}
var LocalkubeDownloadURLPrefix = "https://storage.googleapis.com/minikube/k8sReleases/"
var LocalkubeLinuxFilename = "localkube-linux-amd64"
// DockerAPIVersion is the API version implemented by Docker running in the minikube VM.
const DockerAPIVersion = "1.23"
const ReportingURL = "https://clouderrorreporting.googleapis.com/v1beta1/projects/k8s-minikube/events:report?key=AIzaSyACUwzG0dEPcl-eOgpDKnyKoUFgHdfoFuA"
const AddonsPath = "/etc/kubernetes/addons"
const FilesPath = "/files"
const (
RemoteLocalKubeErrPath = "/var/lib/localkube/localkube.err"
RemoteLocalKubeOutPath = "/var/lib/localkube/localkube.out"
LocalkubePIDPath = "/var/run/localkube.pid"
)
const (
KubeletServiceFile = "/lib/systemd/system/kubelet.service"
KubeletSystemdConfFile = "/etc/systemd/system/kubelet.service.d/10-kubeadm.conf"
KubeadmConfigFile = "/var/lib/kubeadm.yaml"
)
var Preflights = []string{
// We use --ignore-preflight-errors=DirAvailable since we have our own custom addons
// that we also stick in /etc/kubernetes/manifests
"DirAvailable--etc-kubernetes-manifests",
"DirAvailable--data",
"FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml",
"FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml",
"FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml",
"FileAvailable--etc-kubernetes-manifests-etcd.yaml",
// We use --ignore-preflight-errors=Swap since minikube.iso allocates a swap partition.
// (it should probably stop doing this, though...)
"Swap",
// We use --ignore-preflight-errors=CRI since /var/run/dockershim.sock is not present.
// (because we start kubelet with an invalid config)
"CRI",
}
const (
LocalkubeServicePath = "/etc/systemd/system/localkube.service"
LocalkubeRunning = "active"
LocalkubeStopped = "inactive"
)
const (
DefaultUfsPort = "5640"
DefaultUfsDebugLvl = 0
DefaultMountEndpoint = "/minikube-host"
DefaultMsize = 262144
DefaultMountVersion = "9p2000.u"
)
func GetKubernetesReleaseURL(binaryName, version string) string {
return fmt.Sprintf("https://storage.googleapis.com/kubernetes-release/release/%s/bin/linux/amd64/%s", version, binaryName)
}
func GetKubernetesReleaseURLSha1(binaryName, version string) string {
return fmt.Sprintf("%s.sha1", GetKubernetesReleaseURL(binaryName, version))
}
const IsMinikubeChildProcess = "IS_MINIKUBE_CHILD_PROCESS"
const DriverNone = "none"
const FileScheme = "file"
var LocalkubeCachedImages = []string{
// Dashboard
"k8s.gcr.io/kubernetes-dashboard-amd64:v1.8.1",
// DNS
"k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.5",
"k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64:1.14.5",
"k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.5",
// Addon Manager
"k8s.gcr.io/kube-addon-manager:v6.5",
// Pause
"k8s.gcr.io/pause-amd64:3.0",
//Storage Provisioner
"gcr.io/k8s-minikube/storage-provisioner:v1.8.0",
}
func GetKubeadmCachedImages(kubernetesVersionStr string) []string {
var images = []string{
"k8s.gcr.io/kube-proxy-amd64:" + kubernetesVersionStr,
"k8s.gcr.io/kube-scheduler-amd64:" + kubernetesVersionStr,
"k8s.gcr.io/kube-controller-manager-amd64:" + kubernetesVersionStr,
"k8s.gcr.io/kube-apiserver-amd64:" + kubernetesVersionStr,
}
gt_v1_10 := semver.MustParseRange(">=1.11.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")
kubernetesVersion, err := semver.Make(strings.TrimPrefix(kubernetesVersionStr, minikubeVersion.VersionPrefix))
if err != nil {
glog.Errorln("Error parsing version semver: ", err)
}
if v1_10(kubernetesVersion) || gt_v1_10(kubernetesVersion) {
images = append(images, []string{
"k8s.gcr.io/pause-amd64:3.1",
"k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.8",
"k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64:1.14.8",
"k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.8",
"k8s.gcr.io/etcd-amd64:3.1.12",
}...)
} else if v1_9(kubernetesVersion) {
images = append(images, []string{
"k8s.gcr.io/pause-amd64:3.0",
"k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.7",
"k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64:1.14.7",
"k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.7",
"k8s.gcr.io/etcd-amd64:3.1.10",
}...)
} else if v1_8(kubernetesVersion) {
images = append(images, []string{
"k8s.gcr.io/pause-amd64:3.0",
"k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.5",
"k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64:1.14.5",
"k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.5",
"k8s.gcr.io/etcd-amd64:3.0.17",
}...)
}
images = append(images, []string{
"k8s.gcr.io/kubernetes-dashboard-amd64:v1.8.1",
"k8s.gcr.io/kube-addon-manager:v8.6",
"gcr.io/k8s-minikube/storage-provisioner:v1.8.1",
}...)
return images
}
var ImageCacheDir = MakeMiniPath("cache", "images")