@@ -178,7 +178,7 @@ func getSupportedComponentConfigAPIObjects() []string {
178
178
}
179
179
180
180
func getDefaultedInitConfig () (* kubeadmapi.InitConfiguration , error ) {
181
- return configutil .ConfigFileAndDefaultsToInternalConfig ( "" , & kubeadmapiv1beta1.InitConfiguration {
181
+ return configutil .DefaultedInitConfiguration ( & kubeadmapiv1beta1.InitConfiguration {
182
182
// TODO: Probably move to getDefaultedClusterConfig?
183
183
LocalAPIEndpoint : kubeadmapiv1beta1.APIEndpoint {AdvertiseAddress : "1.2.3.4" },
184
184
ClusterConfiguration : kubeadmapiv1beta1.ClusterConfiguration {
@@ -320,12 +320,13 @@ func NewCmdConfigUploadFromFile(out io.Writer, kubeConfigFile *string) *cobra.Co
320
320
client , err := kubeconfigutil .ClientSetFromFile (* kubeConfigFile )
321
321
kubeadmutil .CheckErr (err )
322
322
323
- // The default configuration is empty; everything should come from the file on disk
324
- klog .V (1 ).Infoln ("[config] creating empty default configuration" )
325
- defaultcfg := & kubeadmapiv1beta1.InitConfiguration {}
326
- // Upload the configuration using the file; don't care about the defaultcfg really
323
+ // Default both statically and dynamically, convert to internal API type, and validate everything
324
+ internalcfg , err := configutil .LoadInitConfigurationFromFile (cfgPath )
325
+ kubeadmutil .CheckErr (err )
326
+
327
+ // Upload the configuration using the file
327
328
klog .V (1 ).Infof ("[config] uploading configuration" )
328
- err = uploadConfiguration ( client , cfgPath , defaultcfg )
329
+ err = uploadconfig . UploadConfiguration ( internalcfg , client )
329
330
kubeadmutil .CheckErr (err )
330
331
},
331
332
}
@@ -360,10 +361,18 @@ func NewCmdConfigUploadFromFlags(out io.Writer, kubeConfigFile *string) *cobra.C
360
361
client , err := kubeconfigutil .ClientSetFromFile (* kubeConfigFile )
361
362
kubeadmutil .CheckErr (err )
362
363
364
+ // KubernetesVersion is not used, but we set it explicitly to avoid the lookup
365
+ // of the version from the internet when executing DefaultedInitConfiguration
366
+ phaseutil .SetKubernetesVersion (& cfg .ClusterConfiguration )
367
+
363
368
// Default both statically and dynamically, convert to internal API type, and validate everything
364
- // The cfgPath argument is unset here as we shouldn't load a config file from disk, just go with cfg
369
+ klog .V (1 ).Infoln ("[config] converting to internal API type" )
370
+ internalcfg , err := configutil .DefaultedInitConfiguration (cfg )
371
+ kubeadmutil .CheckErr (err )
372
+
373
+ // Finally, upload the configuration
365
374
klog .V (1 ).Infof ("[config] uploading configuration" )
366
- err = uploadConfiguration ( client , "" , cfg )
375
+ err = uploadconfig . UploadConfiguration ( internalcfg , client )
367
376
kubeadmutil .CheckErr (err )
368
377
},
369
378
}
@@ -384,24 +393,6 @@ func RunConfigView(out io.Writer, client clientset.Interface) error {
384
393
return nil
385
394
}
386
395
387
- // uploadConfiguration handles the uploading of the configuration internally
388
- func uploadConfiguration (client clientset.Interface , cfgPath string , defaultcfg * kubeadmapiv1beta1.InitConfiguration ) error {
389
- // KubernetesVersion is not used, but we set it explicitly to avoid the lookup
390
- // of the version from the internet when executing ConfigFileAndDefaultsToInternalConfig
391
- phaseutil .SetKubernetesVersion (& defaultcfg .ClusterConfiguration )
392
-
393
- // Default both statically and dynamically, convert to internal API type, and validate everything
394
- // First argument is unset here as we shouldn't load a config file from disk
395
- klog .V (1 ).Infoln ("[config] converting to internal API type" )
396
- internalcfg , err := configutil .ConfigFileAndDefaultsToInternalConfig (cfgPath , defaultcfg )
397
- if err != nil {
398
- return err
399
- }
400
-
401
- // Then just call the uploadconfig phase to do the rest of the work
402
- return uploadconfig .UploadConfiguration (internalcfg , client )
403
- }
404
-
405
396
// NewCmdConfigImages returns the "kubeadm config images" command
406
397
func NewCmdConfigImages (out io.Writer ) * cobra.Command {
407
398
cmd := & cobra.Command {
@@ -427,7 +418,7 @@ func NewCmdConfigImagesPull() *cobra.Command {
427
418
Run : func (_ * cobra.Command , _ []string ) {
428
419
externalcfg .ClusterConfiguration .FeatureGates , err = features .NewFeatureGate (& features .InitFeatureGates , featureGatesString )
429
420
kubeadmutil .CheckErr (err )
430
- internalcfg , err := configutil .ConfigFileAndDefaultsToInternalConfig (cfgPath , externalcfg )
421
+ internalcfg , err := configutil .LoadOrDefaultInitConfiguration (cfgPath , externalcfg )
431
422
kubeadmutil .CheckErr (err )
432
423
containerRuntime , err := utilruntime .NewContainerRuntime (utilsexec .New (), internalcfg .GetCRISocket ())
433
424
kubeadmutil .CheckErr (err )
@@ -496,7 +487,7 @@ func NewCmdConfigImagesList(out io.Writer, mockK8sVersion *string) *cobra.Comman
496
487
497
488
// NewImagesList returns the underlying struct for the "kubeadm config images list" command
498
489
func NewImagesList (cfgPath string , cfg * kubeadmapiv1beta1.InitConfiguration ) (* ImagesList , error ) {
499
- initcfg , err := configutil .ConfigFileAndDefaultsToInternalConfig (cfgPath , cfg )
490
+ initcfg , err := configutil .LoadOrDefaultInitConfiguration (cfgPath , cfg )
500
491
if err != nil {
501
492
return nil , errors .Wrap (err , "could not convert cfg to an internal cfg" )
502
493
}
0 commit comments