Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix registry when custom images provided #14690

Merged
merged 4 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/addons/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func EnableOrDisableAddon(cc *config.ClusterConfig, name string, val string) err
out.WarningT("At least needs control plane nodes to enable addon")
}

data := assets.GenerateTemplateData(addon, cc.KubernetesConfig, networkInfo, images, customRegistries, enable)
data := assets.GenerateTemplateData(addon, cc, networkInfo, images, customRegistries, enable)
return enableOrDisableAddonInternal(cc, addon, runner, data, enable)
}

Expand Down
15 changes: 12 additions & 3 deletions pkg/minikube/assets/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ func SelectAndPersistImages(addon *Addon, cc *config.ClusterConfig) (images, cus
// Use newly configured custom images.
images = overrideDefaults(addonDefaultImages, newImages)
// Store custom addon images to be written.
cc.CustomAddonImages = mergeMaps(cc.CustomAddonImages, images)
cc.CustomAddonImages = mergeMaps(cc.CustomAddonImages, newImages)
}

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

// GenerateTemplateData generates template data for template assets
func GenerateTemplateData(addon *Addon, cfg config.KubernetesConfig, netInfo NetworkInfo, images, customRegistries map[string]string, enable bool) interface{} {

func GenerateTemplateData(addon *Addon, cc *config.ClusterConfig, netInfo NetworkInfo, images, customRegistries map[string]string, enable bool) interface{} {
cfg := cc.KubernetesConfig
a := runtime.GOARCH
// Some legacy docker images still need the -arch suffix
// for less common architectures blank suffix for amd64
Expand Down Expand Up @@ -902,6 +902,15 @@ func GenerateTemplateData(addon *Addon, cfg config.KubernetesConfig, netInfo Net
opts.Registries[name] = "" // Avoid nil access when rendering
}

// Without the line below, if you try to overwrite an image the default registry is still used in the templating
spowelljr marked this conversation as resolved.
Show resolved Hide resolved
// Example - image name: MetricsScraper, default registry: docker.io, default image: kubernetesui/metrics-scraper
// Passed on addon enable: --images=MetricsScraper=k8s.gcr.io/echoserver:1.4
// Without this line the resulting image would be docker.io/k8s.gcr.io/echoserver:1.4
// Therefore, if the user specified a custom image remove the default registry
if _, ok := cc.CustomAddonImages[name]; ok {
opts.Registries[name] = ""
}

if enable {
if override, ok := opts.CustomRegistries[name]; ok {
out.Infof("Using image {{.registry}}{{.image}}", out.V{
Expand Down