Skip to content

Commit

Permalink
Merge pull request #3714 from laozc/custom-image-repository
Browse files Browse the repository at this point in the history
Add --image-repository flag so that users can select an alternative repository mirror
  • Loading branch information
tstromberg authored Mar 22, 2019
2 parents cbac94a + daec030 commit 702d471
Show file tree
Hide file tree
Showing 26 changed files with 426 additions and 134 deletions.
33 changes: 31 additions & 2 deletions cmd/minikube/cmd/config/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package config

import (
"fmt"
"os"
"strconv"
"strings"

Expand All @@ -26,6 +27,7 @@ import (
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/storageclass"
)
Expand Down Expand Up @@ -123,15 +125,42 @@ func EnableOrDisableAddon(name string, val string) error {
if err != nil {
return errors.Wrap(err, "command runner")
}

cfg, err := config.Load()
if err != nil && !os.IsNotExist(err) {
exit.WithCode(exit.Data, "Unable to load config: %v", err)
}

data := assets.GenerateTemplateData(cfg.KubernetesConfig)
if enable {
for _, addon := range addon.Assets {
if err := cmd.Copy(addon); err != nil {
var addonFile assets.CopyableFile
if addon.IsTemplate() {
addonFile, err = addon.Evaluate(data)
if err != nil {
return errors.Wrapf(err, "evaluate bundled addon %s asset", addon.GetAssetName())
}

} else {
addonFile = addon
}
if err := cmd.Copy(addonFile); err != nil {
return errors.Wrapf(err, "enabling addon %s", addon.AssetName)
}
}
} else {
for _, addon := range addon.Assets {
if err := cmd.Remove(addon); err != nil {
var addonFile assets.CopyableFile
if addon.IsTemplate() {
addonFile, err = addon.Evaluate(data)
if err != nil {
return errors.Wrapf(err, "evaluate bundled addon %s asset", addon.GetAssetName())
}

} else {
addonFile = addon
}
if err := cmd.Remove(addonFile); err != nil {
return errors.Wrapf(err, "disabling addon %s", addon.AssetName)
}
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const (
apiServerPort = "apiserver-port"
dnsDomain = "dns-domain"
serviceCIDR = "service-cluster-ip-range"
imageRepository = "image-repository"
mountString = "mount-string"
disableDriverMounts = "disable-driver-mounts"
cacheImages = "cache-images"
Expand Down Expand Up @@ -126,6 +127,7 @@ func init() {
startCmd.Flags().String(serviceCIDR, pkgutil.DefaultServiceCIDR, "The CIDR to be used for service cluster IPs.")
startCmd.Flags().StringSliceVar(&insecureRegistry, "insecure-registry", nil, "Insecure Docker registries to pass to the Docker daemon. The default service CIDR range will automatically be added.")
startCmd.Flags().StringSliceVar(&registryMirror, "registry-mirror", nil, "Registry mirrors to pass to the Docker daemon")
startCmd.Flags().String(imageRepository, "", "Alternative image repository to pull docker images from. This can be used when you have limited access to gcr.io. For Chinese mainland users, you may use local gcr.io mirrors such as registry.cn-hangzhou.aliyuncs.com/google_containers")
startCmd.Flags().String(containerRuntime, "docker", "The container runtime to be used (docker, crio, containerd)")
startCmd.Flags().String(criSocket, "", "The cri socket path to be used")
startCmd.Flags().String(kubernetesVersion, constants.DefaultKubernetesVersion, "The kubernetes version that the minikube VM will use (ex: v1.2.3)")
Expand Down Expand Up @@ -245,7 +247,7 @@ func beginCacheImages(g *errgroup.Group, k8sVersion string) {
}
console.OutStyle("caching", "Downloading Kubernetes %s images in the background ...", k8sVersion)
g.Go(func() error {
return machine.CacheImagesForBootstrapper(k8sVersion, viper.GetString(cmdcfg.Bootstrapper))
return machine.CacheImagesForBootstrapper(viper.GetString(imageRepository), k8sVersion, viper.GetString(cmdcfg.Bootstrapper))
})
}

Expand Down Expand Up @@ -316,6 +318,7 @@ func generateConfig(cmd *cobra.Command, k8sVersion string) (cfg.Config, error) {
CRISocket: viper.GetString(criSocket),
NetworkPlugin: selectedNetworkPlugin,
ServiceCIDR: viper.GetString(serviceCIDR),
ImageRepository: viper.GetString(imageRepository),
ExtraOptions: extraOptions,
ShouldLoadCachedImages: viper.GetBool(cacheImages),
EnableDefaultCNI: selectedEnableDefaultCNI,
Expand Down
2 changes: 1 addition & 1 deletion deploy/addons/addon-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
hostNetwork: true
containers:
- name: kube-addon-manager
image: k8s.gcr.io/kube-addon-manager:v8.6
image: {{default "k8s.gcr.io" .ImageRepository}}/kube-addon-manager:v8.6
env:
- name: KUBECONFIG
value: /var/lib/minikube/kubeconfig
Expand Down
2 changes: 1 addition & 1 deletion deploy/addons/dashboard/dashboard-dp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ spec:
spec:
containers:
- name: kubernetes-dashboard
image: k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1
image: {{default "k8s.gcr.io" .ImageRepository}}/kubernetes-dashboard-amd64:v1.10.1
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9090
Expand Down
2 changes: 1 addition & 1 deletion deploy/addons/efk/elasticsearch-rc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ spec:
spec:
containers:
- name: elasticsearch-logging
image: k8s.gcr.io/elasticsearch:v5.6.2
image: {{default "k8s.gcr.io" .ImageRepository}}/elasticsearch:v5.6.2
resources:
limits:
cpu: 500m
Expand Down
2 changes: 1 addition & 1 deletion deploy/addons/efk/fluentd-es-rc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
spec:
containers:
- name: fluentd-es
image: k8s.gcr.io/fluentd-elasticsearch:v2.0.2
image: {{default "k8s.gcr.io" .ImageRepository}}/fluentd-elasticsearch:v2.0.2
env:
- name: FLUENTD_ARGS
value: --no-supervisor -q
Expand Down
2 changes: 1 addition & 1 deletion deploy/addons/freshpod/freshpod-rc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ spec:
spec:
containers:
- name: freshpod
image: gcr.io/google-samples/freshpod:v0.0.1
image: {{default "gcr.io/google-samples" .ImageRepository}}/freshpod:v0.0.1
imagePullPolicy: IfNotPresent
volumeMounts:
- name: docker
Expand Down
4 changes: 2 additions & 2 deletions deploy/addons/gpu/nvidia-driver-installer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ spec:
hostPath:
path: /
initContainers:
- image: k8s.gcr.io/minikube-nvidia-driver-installer@sha256:492d46f2bc768d6610ec5940b6c3c33c75e03e201cc8786e04cc488659fd6342
- image: {{default "k8s.gcr.io" .ImageRepository}}/minikube-nvidia-driver-installer@sha256:492d46f2bc768d6610ec5940b6c3c33c75e03e201cc8786e04cc488659fd6342
name: nvidia-driver-installer
resources:
requests:
Expand All @@ -72,5 +72,5 @@ spec:
- name: root-mount
mountPath: /root
containers:
- image: "gcr.io/google-containers/pause:2.0"
- image: "{{default "gcr.io/google-containers" .ImageRepository}}/pause:2.0"
name: pause
2 changes: 1 addition & 1 deletion deploy/addons/gpu/nvidia-gpu-device-plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ spec:
hostPath:
path: /dev
containers:
- image: "k8s.gcr.io/nvidia-gpu-device-plugin@sha256:0842734032018be107fa2490c98156992911e3e1f2a21e059ff0105b07dd8e9e"
- image: "{{default "k8s.gcr.io" .ImageRepository}}/nvidia-gpu-device-plugin@sha256:0842734032018be107fa2490c98156992911e3e1f2a21e059ff0105b07dd8e9e"
command: ["/usr/bin/nvidia-gpu-device-plugin", "-logtostderr"]
name: nvidia-gpu-device-plugin
resources:
Expand Down
2 changes: 1 addition & 1 deletion deploy/addons/gvisor/gvisor-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ oom_score = 0
stream_server_address = ""
stream_server_port = "10010"
enable_selinux = false
sandbox_image = "k8s.gcr.io/pause:3.1"
sandbox_image = "{{default "k8s.gcr.io" .ImageRepository}}/pause:3.1"
stats_collect_period = 10
systemd_cgroup = false
enable_tls_streaming = false
Expand Down
2 changes: 1 addition & 1 deletion deploy/addons/gvisor/gvisor-pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
hostPID: true
containers:
- name: gvisor
image: gcr.io/k8s-minikube/gvisor-addon:latest
image: {{default "gcr.io/k8s-minikube" .ImageRepository}}/gvisor-addon:latest
securityContext:
privileged: true
volumeMounts:
Expand Down
2 changes: 1 addition & 1 deletion deploy/addons/heapster/heapster-rc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ spec:
spec:
containers:
- name: heapster
image: k8s.gcr.io/heapster-amd64:v1.5.3
image: {{default "k8s.gcr.io" .ImageRepository}}/heapster-amd64:v1.5.3
imagePullPolicy: IfNotPresent
command:
- /heapster
Expand Down
4 changes: 2 additions & 2 deletions deploy/addons/heapster/influx-grafana-rc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ spec:
spec:
containers:
- name: influxdb
image: k8s.gcr.io/heapster-influxdb-amd64:v1.3.3
image: {{default "k8s.gcr.io" .ImageRepository}}/heapster-influxdb-amd64:v1.3.3
imagePullPolicy: IfNotPresent
ports:
- name: http
Expand All @@ -45,7 +45,7 @@ spec:
- mountPath: /data
name: influxdb-storage
- name: grafana
image: k8s.gcr.io/heapster-grafana-amd64:v4.4.3
image: {{default "k8s.gcr.io" .ImageRepository}}/heapster-grafana-amd64:v4.4.3
imagePullPolicy: IfNotPresent
env:
- name: INFLUXDB_SERVICE_URL
Expand Down
2 changes: 1 addition & 1 deletion deploy/addons/ingress/ingress-dp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ spec:
# Any image is permissible as long as:
# 1. It serves a 404 page at /
# 2. It serves 200 on a /healthz endpoint
image: gcr.io/google_containers/defaultbackend:1.4
image: {{default "gcr.io/google_containers" .ImageRepository}}/defaultbackend:1.4
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spec:
spec:
containers:
- name: metrics-server
image: k8s.gcr.io/metrics-server-amd64:v0.2.1
image: {{default "k8s.gcr.io" .ImageRepository}}/metrics-server-amd64:v0.2.1
imagePullPolicy: Always
command:
- /metrics-server
Expand Down
2 changes: 1 addition & 1 deletion deploy/addons/storage-provisioner/storage-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ spec:
hostNetwork: true
containers:
- name: storage-provisioner
image: gcr.io/k8s-minikube/storage-provisioner:v1.8.1
image: {{default "gcr.io/k8s-minikube" .ImageRepository}}/storage-provisioner:v1.8.1
command: ["/storage-provisioner"]
imagePullPolicy: IfNotPresent
volumeMounts:
Expand Down
Loading

0 comments on commit 702d471

Please sign in to comment.