@@ -60,7 +60,7 @@ Every cluster will consist of one or more containers:
6060 * we use two different instances of Viper here to handle
6161 * - cfgViper: "static" configuration
6262 * - ppViper: "pre-processed" configuration, where CLI input has to be pre-processed
63- * to be treated as part of the SImpleConfig
63+ * to be treated as part of the SimpleConfig
6464 */
6565var (
6666 cfgViper = viper .New ()
@@ -329,6 +329,9 @@ func NewCmdClusterCreate() *cobra.Command {
329329 cmd .Flags ().StringArray ("registry-use" , nil , "Connect to one or more k3d-managed registries running locally" )
330330 _ = cfgViper .BindPFlag ("registries.use" , cmd .Flags ().Lookup ("registry-use" ))
331331
332+ cmd .Flags ().Bool ("enforce-registry-port-match" , false , "Make the internal registry port match the external one" )
333+ _ = cfgViper .BindPFlag ("registries.create.enforcePortMatch" , cmd .Flags ().Lookup ("enforce-registry-port-match" ))
334+
332335 cmd .Flags ().String ("registry-config" , "" , "Specify path to an extra registries.yaml file" )
333336 _ = cfgViper .BindPFlag ("registries.config" , cmd .Flags ().Lookup ("registry-config" ))
334337 if err := cmd .MarkFlagFilename ("registry-config" , "yaml" , "yml" ); err != nil {
@@ -373,7 +376,7 @@ func applyCLIOverrides(cfg conf.SimpleConfig) (conf.SimpleConfig, error) {
373376 if cfg .ExposeAPI .HostPort != "" {
374377 l .Log ().Debugf ("Overriding pre-defined kubeAPI Exposure Spec %+v with CLI argument %s" , cfg .ExposeAPI , ppViper .GetString ("cli.api-port" ))
375378 }
376- exposeAPI , err = cliutil .ParsePortExposureSpec (ppViper .GetString ("cli.api-port" ), k3d .DefaultAPIPort )
379+ exposeAPI , err = cliutil .ParsePortExposureSpec (ppViper .GetString ("cli.api-port" ), k3d .DefaultAPIPort , false )
377380 if err != nil {
378381 return cfg , fmt .Errorf ("failed to parse API Port spec: %w" , err )
379382 }
@@ -575,7 +578,7 @@ func applyCLIOverrides(cfg conf.SimpleConfig) (conf.SimpleConfig, error) {
575578 }
576579 cfg .Registries .Create .Name = fvSplit [0 ]
577580 if len (fvSplit ) > 1 {
578- exposeAPI , err = cliutil .ParsePortExposureSpec (fvSplit [1 ], "1234" ) // internal port is unused after all
581+ exposeAPI , err = cliutil .ParsePortExposureSpec (fvSplit [1 ], k3d . DefaultRegistryPort , cfg . Registries . Create . EnforcePortMatch )
579582 if err != nil {
580583 return cfg , fmt .Errorf ("failed to registry port spec: %w" , err )
581584 }
0 commit comments