kubeadm: Replace MigrateOldConfigFromFile

MigrateOldConfigFromFile is a function, whose purpose is to migrate one config
into another. It is working OK for now, but it has some issues:

- It is incredibly inefficient. It can reload and re-parse a single config file
  for up to 3 times.

- Because of the reloads, it has to take a file containing the configuration
  (not a byte slice as most of the rest config functions). However, it returns
  the migrated config in a byte slice (rather asymmetric from the input
  method).

- Due to the above points it's difficult to implement a proper interface for
  deprecated kubeadm config versions.

To fix the issues of MigrateOldConfigFromFile, the following is done:

- Re-implement the function by removing the calls to file loading package
  public APIs and replacing them with newly extracted package private APIs that
  do the job with pre-provided input data in the form of
  map[GroupVersionKind][]byte.

- Take a byte slice of the input configuration as an argument. This makes the
  function input symmetric to its output. Also, it's now renamed to
  MigrateOldConfig to represent the change from config file path as an input
  to byte slice.

- As a bonus (actually forgotten from a previous change) BytesToInternalConfig
  is renamed to the more descriptive BytesToInitConfiguration.

Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
This commit is contained in:
Rostislav M. Georgiev
2018-12-07 17:15:43 +02:00
parent 7944fed44b
commit f73ac0da3e
7 changed files with 49 additions and 63 deletions

View File

@@ -76,7 +76,6 @@ go_test(
embed = [":go_default_library"],
deps = [
"//cmd/kubeadm/app/apis/kubeadm:go_default_library",
"//cmd/kubeadm/app/apis/kubeadm/validation:go_default_library",
"//cmd/kubeadm/app/constants:go_default_library",
"//cmd/kubeadm/app/phases/certs:go_default_library",
"//cmd/kubeadm/app/phases/controlplane:go_default_library",

View File

@@ -32,7 +32,6 @@ import (
"github.com/pkg/errors"
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/validation"
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
certsphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/certs"
controlplanephase "k8s.io/kubernetes/cmd/kubeadm/app/phases/controlplane"
@@ -541,22 +540,7 @@ func getConfig(version, certsDir, etcdDataDir string) (*kubeadmapi.InitConfigura
configBytes := []byte(fmt.Sprintf(testConfiguration, certsDir, etcdDataDir, version))
// Unmarshal the config
cfg, err := configutil.BytesToInternalConfig(configBytes)
if err != nil {
return nil, err
}
// Applies dynamic defaults to settings not provided with flags
if err = configutil.SetInitDynamicDefaults(cfg); err != nil {
return nil, err
}
// Validates cfg (flags/configs + defaults + dynamic defaults)
if err = validation.ValidateInitConfiguration(cfg).ToAggregate(); err != nil {
return nil, err
}
return cfg, nil
return configutil.BytesToInitConfiguration(configBytes)
}
func getTempDir(t *testing.T, name string) (string, func()) {