Skip to content

Commit a94403e

Browse files
committed
add BytesToXConfiguration function
1 parent 77647cd commit a94403e

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

cmd/kubeadm/app/util/config/initconfiguration.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,11 @@ func LoadOrDefaultInitConfiguration(cfgPath string, versionedInitCfg *kubeadmapi
291291
}
292292

293293
// BytesToInitConfiguration converts a byte slice to an internal, defaulted and validated InitConfiguration object.
294-
// The map may contain many different YAML/JSON documents. These YAML/JSON documents are parsed one-by-one
294+
// The map may contain many different YAML/JSON documents. These documents are parsed one-by-one
295295
// and well-known ComponentConfig GroupVersionKinds are stored inside of the internal InitConfiguration struct.
296296
// The resulting InitConfiguration is then dynamically defaulted and validated prior to return.
297297
func BytesToInitConfiguration(b []byte, skipCRIDetect bool) (*kubeadmapi.InitConfiguration, error) {
298+
// Split the YAML/JSON documents in the file into a DocumentMap
298299
gvkmap, err := kubeadmutil.SplitConfigDocuments(b)
299300
if err != nil {
300301
return nil, err

cmd/kubeadm/app/util/config/joinconfiguration.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ func LoadJoinConfigurationFromFile(cfgPath string, opts LoadOrDefaultConfigurati
8787
return nil, errors.Wrapf(err, "unable to read config from %q ", cfgPath)
8888
}
8989

90+
return BytesToJoinConfiguration(b, opts)
91+
}
92+
93+
// BytesToJoinConfiguration converts a byte slice to an internal, defaulted and validated JoinConfiguration object.
94+
// The map may contain many different YAML/JSON documents. These documents are parsed one-by-one.
95+
// The resulting JoinConfiguration is then dynamically defaulted and validated prior to return.
96+
func BytesToJoinConfiguration(b []byte, opts LoadOrDefaultConfigurationOptions) (*kubeadmapi.JoinConfiguration, error) {
97+
// Split the YAML/JSON documents in the file into a DocumentMap
9098
gvkmap, err := kubeadmutil.SplitConfigDocuments(b)
9199
if err != nil {
92100
return nil, err

cmd/kubeadm/app/util/config/resetconfiguration.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ func LoadResetConfigurationFromFile(cfgPath string, opts LoadOrDefaultConfigurat
9191
return nil, errors.Wrapf(err, "unable to read config from %q ", cfgPath)
9292
}
9393

94+
return BytesToResetConfiguration(b, opts)
95+
}
96+
97+
// BytesToResetConfiguration converts a byte slice to an internal, defaulted and validated ResetConfiguration object.
98+
// The map may contain many different YAML/JSON documents. These documents are parsed one-by-one.
99+
// The resulting ResetConfiguration is then dynamically defaulted and validated prior to return.
100+
func BytesToResetConfiguration(b []byte, opts LoadOrDefaultConfigurationOptions) (*kubeadmapi.ResetConfiguration, error) {
101+
// Split the YAML/JSON documents in the file into a DocumentMap
94102
gvkmap, err := kubeadmutil.SplitConfigDocuments(b)
95103
if err != nil {
96104
return nil, err

cmd/kubeadm/app/util/config/upgradeconfiguration.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,29 @@ func LoadUpgradeConfigurationFromFile(cfgPath string, _ LoadOrDefaultConfigurati
9393
return nil, errors.Wrapf(err, "unable to load config from file %q", cfgPath)
9494
}
9595

96-
// Split the YAML/JSON documents in the file into a DocumentMap
97-
docmap, err := kubeadmutil.SplitConfigDocuments(configBytes)
98-
if err != nil {
99-
return nil, err
100-
}
101-
10296
// Convert documentMap to internal UpgradeConfiguration, InitConfiguration and ClusterConfiguration from config file will be ignored.
10397
// Upgrade should respect the cluster configuration from the existing cluster, re-configure the cluster with a InitConfiguration and
10498
// ClusterConfiguration from the config file is not allowed for upgrade.
105-
if upgradeCfg, err = DocMapToUpgradeConfiguration(docmap); err != nil {
99+
if upgradeCfg, err = BytesToUpgradeConfiguration(configBytes); err != nil {
106100
return nil, err
107101
}
108102

109103
return upgradeCfg, nil
110104
}
111105

106+
// BytesToUpgradeConfiguration converts a byte slice to an internal, defaulted and validated UpgradeConfiguration object.
107+
// The map may contain many different YAML/JSON documents. These documents are parsed one-by-one.
108+
// The resulting UpgradeConfiguration is then dynamically defaulted and validated prior to return.
109+
func BytesToUpgradeConfiguration(b []byte) (*kubeadmapi.UpgradeConfiguration, error) {
110+
// Split the YAML/JSON documents in the file into a DocumentMap
111+
gvkmap, err := kubeadmutil.SplitConfigDocuments(b)
112+
if err != nil {
113+
return nil, err
114+
}
115+
116+
return documentMapToUpgradeConfiguration(gvkmap, false)
117+
}
118+
112119
// LoadOrDefaultUpgradeConfiguration takes a path to a config file and a versioned configuration that can serve as the default config
113120
// If cfgPath is specified, defaultversionedcfg will always get overridden. Otherwise, the default config (often populated by flags) will be used.
114121
// Then the external, versioned configuration is defaulted and converted to the internal type.

0 commit comments

Comments
 (0)