Merge pull request #13912 from kadern0/issue-12643

feat: added configure option to registry-alieases addon
pull/14181/head
Sharif Elgamal 2022-05-16 11:33:40 -07:00 committed by GitHub
commit 7292031c08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 2 deletions

View File

@ -23,6 +23,7 @@ import (
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/addons"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/mustload"
@ -234,6 +235,26 @@ var addonsConfigureCmd = &cobra.Command{
if err := config.SaveProfile(profile, cfg); err != nil {
out.ErrT(style.Fatal, "Failed to save config {{.profile}}", out.V{"profile": profile})
}
case "registry-aliases":
profile := ClusterFlagValue()
_, cfg := mustload.Partial(profile)
validator := func(s string) bool {
format := regexp.MustCompile(`^([a-zA-Z0-9-_]+\.[a-zA-Z0-9-_]+)+(\ [a-zA-Z0-9-_]+\.[a-zA-Z0-9-_]+)*$`)
return format.MatchString(s)
}
registryAliases := AskForStaticValidatedValue("-- Enter registry aliases separated by space: ", validator)
cfg.KubernetesConfig.RegistryAliases = registryAliases
if err := config.SaveProfile(profile, cfg); err != nil {
out.ErrT(style.Fatal, "Failed to save config {{.profile}}", out.V{"profile": profile})
}
addon := assets.Addons["registry-aliases"]
if addon.IsEnabled(cfg) {
// Re-enable registry-aliases addon in order to generate template manifest files with custom hosts
if err := addons.EnableOrDisableAddon(cfg, "registry-aliases", "true"); err != nil {
out.ErrT(style.Fatal, "Failed to configure registry-aliases {{.profile}}", out.V{"profile": profile})
}
}
default:
out.FailureT("{{.name}} has no available configuration options", out.V{"name": addon})

View File

@ -9,11 +9,14 @@ metadata:
data:
# Add additional hosts separated by new-line
registryAliases: >-
{{- if .RegistryAliases}}
{{ .RegistryAliases}}
{{- else}}
example.org
example.com
test.com
test.org
{{- end}}
registry.minikube
# default registry address in minikube when enabled via minikube addons enable registry
registrySvc: registry.kube-system.svc.cluster.local

View File

@ -813,6 +813,7 @@ func GenerateTemplateData(addon *Addon, cfg config.KubernetesConfig, netInfo Net
CustomIngressCert string
IngressAPIVersion string
ContainerRuntime string
RegistryAliases string
Images map[string]string
Registries map[string]string
CustomRegistries map[string]string
@ -825,6 +826,7 @@ func GenerateTemplateData(addon *Addon, cfg config.KubernetesConfig, netInfo Net
LoadBalancerStartIP: cfg.LoadBalancerStartIP,
LoadBalancerEndIP: cfg.LoadBalancerEndIP,
CustomIngressCert: cfg.CustomIngressCert,
RegistryAliases: cfg.RegistryAliases,
IngressAPIVersion: "v1", // api version for ingress (eg, "v1beta1"; defaults to "v1" for k8s 1.19+)
ContainerRuntime: cfg.ContainerRuntime,
Images: images,

View File

@ -120,6 +120,7 @@ type KubernetesConfig struct {
LoadBalancerStartIP string // currently only used by MetalLB addon
LoadBalancerEndIP string // currently only used by MetalLB addon
CustomIngressCert string // used by Ingress addon
RegistryAliases string // currently only used by registry-aliases addon
ExtraOptions ExtraOptionSlice
ShouldLoadCachedImages bool