mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 04:06:03 +00:00
add BytesToXConfiguration function
This commit is contained in:
parent
77647cdfc3
commit
a94403e942
@ -291,10 +291,11 @@ func LoadOrDefaultInitConfiguration(cfgPath string, versionedInitCfg *kubeadmapi
|
||||
}
|
||||
|
||||
// BytesToInitConfiguration converts a byte slice to an internal, defaulted and validated InitConfiguration object.
|
||||
// The map may contain many different YAML/JSON documents. These YAML/JSON documents are parsed one-by-one
|
||||
// The map may contain many different YAML/JSON documents. These documents are parsed one-by-one
|
||||
// and well-known ComponentConfig GroupVersionKinds are stored inside of the internal InitConfiguration struct.
|
||||
// The resulting InitConfiguration is then dynamically defaulted and validated prior to return.
|
||||
func BytesToInitConfiguration(b []byte, skipCRIDetect bool) (*kubeadmapi.InitConfiguration, error) {
|
||||
// Split the YAML/JSON documents in the file into a DocumentMap
|
||||
gvkmap, err := kubeadmutil.SplitConfigDocuments(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -87,6 +87,14 @@ func LoadJoinConfigurationFromFile(cfgPath string, opts LoadOrDefaultConfigurati
|
||||
return nil, errors.Wrapf(err, "unable to read config from %q ", cfgPath)
|
||||
}
|
||||
|
||||
return BytesToJoinConfiguration(b, opts)
|
||||
}
|
||||
|
||||
// BytesToJoinConfiguration converts a byte slice to an internal, defaulted and validated JoinConfiguration object.
|
||||
// The map may contain many different YAML/JSON documents. These documents are parsed one-by-one.
|
||||
// The resulting JoinConfiguration is then dynamically defaulted and validated prior to return.
|
||||
func BytesToJoinConfiguration(b []byte, opts LoadOrDefaultConfigurationOptions) (*kubeadmapi.JoinConfiguration, error) {
|
||||
// Split the YAML/JSON documents in the file into a DocumentMap
|
||||
gvkmap, err := kubeadmutil.SplitConfigDocuments(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -91,6 +91,14 @@ func LoadResetConfigurationFromFile(cfgPath string, opts LoadOrDefaultConfigurat
|
||||
return nil, errors.Wrapf(err, "unable to read config from %q ", cfgPath)
|
||||
}
|
||||
|
||||
return BytesToResetConfiguration(b, opts)
|
||||
}
|
||||
|
||||
// BytesToResetConfiguration converts a byte slice to an internal, defaulted and validated ResetConfiguration object.
|
||||
// The map may contain many different YAML/JSON documents. These documents are parsed one-by-one.
|
||||
// The resulting ResetConfiguration is then dynamically defaulted and validated prior to return.
|
||||
func BytesToResetConfiguration(b []byte, opts LoadOrDefaultConfigurationOptions) (*kubeadmapi.ResetConfiguration, error) {
|
||||
// Split the YAML/JSON documents in the file into a DocumentMap
|
||||
gvkmap, err := kubeadmutil.SplitConfigDocuments(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -93,22 +93,29 @@ func LoadUpgradeConfigurationFromFile(cfgPath string, _ LoadOrDefaultConfigurati
|
||||
return nil, errors.Wrapf(err, "unable to load config from file %q", cfgPath)
|
||||
}
|
||||
|
||||
// Split the YAML/JSON documents in the file into a DocumentMap
|
||||
docmap, err := kubeadmutil.SplitConfigDocuments(configBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Convert documentMap to internal UpgradeConfiguration, InitConfiguration and ClusterConfiguration from config file will be ignored.
|
||||
// Upgrade should respect the cluster configuration from the existing cluster, re-configure the cluster with a InitConfiguration and
|
||||
// ClusterConfiguration from the config file is not allowed for upgrade.
|
||||
if upgradeCfg, err = DocMapToUpgradeConfiguration(docmap); err != nil {
|
||||
if upgradeCfg, err = BytesToUpgradeConfiguration(configBytes); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return upgradeCfg, nil
|
||||
}
|
||||
|
||||
// BytesToUpgradeConfiguration converts a byte slice to an internal, defaulted and validated UpgradeConfiguration object.
|
||||
// The map may contain many different YAML/JSON documents. These documents are parsed one-by-one.
|
||||
// The resulting UpgradeConfiguration is then dynamically defaulted and validated prior to return.
|
||||
func BytesToUpgradeConfiguration(b []byte) (*kubeadmapi.UpgradeConfiguration, error) {
|
||||
// Split the YAML/JSON documents in the file into a DocumentMap
|
||||
gvkmap, err := kubeadmutil.SplitConfigDocuments(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return documentMapToUpgradeConfiguration(gvkmap, false)
|
||||
}
|
||||
|
||||
// LoadOrDefaultUpgradeConfiguration takes a path to a config file and a versioned configuration that can serve as the default config
|
||||
// If cfgPath is specified, defaultversionedcfg will always get overridden. Otherwise, the default config (often populated by flags) will be used.
|
||||
// Then the external, versioned configuration is defaulted and converted to the internal type.
|
||||
|
Loading…
Reference in New Issue
Block a user