Skip to content

Commit aff7efa

Browse files
authoredAug 11, 2022
Merge pull request #14690 from spowelljr/fixCustomImage
Fix registry when custom images provided
2 parents 1bc30be + 071193d commit aff7efa

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed
 

‎pkg/addons/addons.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func EnableOrDisableAddon(cc *config.ClusterConfig, name string, val string) err
221221
out.WarningT("At least needs control plane nodes to enable addon")
222222
}
223223

224-
data := assets.GenerateTemplateData(addon, cc.KubernetesConfig, networkInfo, images, customRegistries, enable)
224+
data := assets.GenerateTemplateData(addon, cc, networkInfo, images, customRegistries, enable)
225225
return enableOrDisableAddonInternal(cc, addon, runner, data, enable)
226226
}
227227

‎pkg/minikube/assets/addons.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ func SelectAndPersistImages(addon *Addon, cc *config.ClusterConfig) (images, cus
786786
// Use newly configured custom images.
787787
images = overrideDefaults(addonDefaultImages, newImages)
788788
// Store custom addon images to be written.
789-
cc.CustomAddonImages = mergeMaps(cc.CustomAddonImages, images)
789+
cc.CustomAddonImages = mergeMaps(cc.CustomAddonImages, newImages)
790790
}
791791

792792
// Use previously configured custom registries.
@@ -819,8 +819,8 @@ func SelectAndPersistImages(addon *Addon, cc *config.ClusterConfig) (images, cus
819819
}
820820

821821
// GenerateTemplateData generates template data for template assets
822-
func GenerateTemplateData(addon *Addon, cfg config.KubernetesConfig, netInfo NetworkInfo, images, customRegistries map[string]string, enable bool) interface{} {
823-
822+
func GenerateTemplateData(addon *Addon, cc *config.ClusterConfig, netInfo NetworkInfo, images, customRegistries map[string]string, enable bool) interface{} {
823+
cfg := cc.KubernetesConfig
824824
a := runtime.GOARCH
825825
// Some legacy docker images still need the -arch suffix
826826
// for less common architectures blank suffix for amd64
@@ -902,6 +902,15 @@ func GenerateTemplateData(addon *Addon, cfg config.KubernetesConfig, netInfo Net
902902
opts.Registries[name] = "" // Avoid nil access when rendering
903903
}
904904

905+
// tl;dr If the user specified a custom image remove the default registry
906+
// Without the line below, if you try to overwrite an image the default registry is still used in the templating
907+
// Example - image name: MetricsScraper, default registry: docker.io, default image: kubernetesui/metrics-scraper
908+
// Passed on addon enable: --images=MetricsScraper=k8s.gcr.io/echoserver:1.4
909+
// Without this line the resulting image would be docker.io/k8s.gcr.io/echoserver:1.4
910+
if _, ok := cc.CustomAddonImages[name]; ok {
911+
opts.Registries[name] = ""
912+
}
913+
905914
if enable {
906915
if override, ok := opts.CustomRegistries[name]; ok {
907916
out.Infof("Using image {{.registry}}{{.image}}", out.V{

0 commit comments

Comments
 (0)
Please sign in to comment.