@@ -93,22 +93,29 @@ func LoadUpgradeConfigurationFromFile(cfgPath string, _ LoadOrDefaultConfigurati
93
93
return nil , errors .Wrapf (err , "unable to load config from file %q" , cfgPath )
94
94
}
95
95
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
-
102
96
// Convert documentMap to internal UpgradeConfiguration, InitConfiguration and ClusterConfiguration from config file will be ignored.
103
97
// Upgrade should respect the cluster configuration from the existing cluster, re-configure the cluster with a InitConfiguration and
104
98
// 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 {
106
100
return nil , err
107
101
}
108
102
109
103
return upgradeCfg , nil
110
104
}
111
105
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
+
112
119
// LoadOrDefaultUpgradeConfiguration takes a path to a config file and a versioned configuration that can serve as the default config
113
120
// If cfgPath is specified, defaultversionedcfg will always get overridden. Otherwise, the default config (often populated by flags) will be used.
114
121
// Then the external, versioned configuration is defaulted and converted to the internal type.
0 commit comments