mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
distinguish between YAML and JSON file formats during log output
This commit is contained in:
parent
49bbe19460
commit
6a59c98a9e
@ -60,7 +60,7 @@ func FetchInitConfigurationFromCluster(client clientset.Interface, printer outpu
|
|||||||
}
|
}
|
||||||
_, _ = printer.Printf("[%s] Reading configuration from the %q ConfigMap in namespace %q...\n",
|
_, _ = printer.Printf("[%s] Reading configuration from the %q ConfigMap in namespace %q...\n",
|
||||||
logPrefix, constants.KubeadmConfigConfigMap, metav1.NamespaceSystem)
|
logPrefix, constants.KubeadmConfigConfigMap, metav1.NamespaceSystem)
|
||||||
_, _ = printer.Printf("[%s] Use 'kubeadm init phase upload-config --config your-config.yaml' to re-upload it.\n", logPrefix)
|
_, _ = printer.Printf("[%s] Use 'kubeadm init phase upload-config --config your-config-file' to re-upload it.\n", logPrefix)
|
||||||
|
|
||||||
// Fetch the actual config from cluster
|
// Fetch the actual config from cluster
|
||||||
cfg, err := getInitConfigurationFromCluster(constants.KubernetesDir, client, newControlPlane, skipComponentConfigs)
|
cfg, err := getInitConfigurationFromCluster(constants.KubernetesDir, client, newControlPlane, skipComponentConfigs)
|
||||||
@ -214,7 +214,7 @@ func GetNodeRegistration(kubeconfigFile string, client clientset.Interface, node
|
|||||||
|
|
||||||
// getNodeNameFromKubeletConfig gets the node name from a kubelet config file
|
// getNodeNameFromKubeletConfig gets the node name from a kubelet config file
|
||||||
// TODO: in future we want to switch to a more canonical way for doing this e.g. by having this
|
// TODO: in future we want to switch to a more canonical way for doing this e.g. by having this
|
||||||
// information in the local kubelet config.yaml
|
// information in the local kubelet config configuration file.
|
||||||
func getNodeNameFromKubeletConfig(fileName string) (string, error) {
|
func getNodeNameFromKubeletConfig(fileName string) (string, error) {
|
||||||
// loads the kubelet.conf file
|
// loads the kubelet.conf file
|
||||||
config, err := clientcmd.LoadFromFile(fileName)
|
config, err := clientcmd.LoadFromFile(fileName)
|
||||||
|
@ -94,11 +94,11 @@ func validateSupportedVersion(gvk schema.GroupVersionKind, allowDeprecated, allo
|
|||||||
gvString := gvk.GroupVersion().String()
|
gvString := gvk.GroupVersion().String()
|
||||||
|
|
||||||
if useKubeadmVersion := oldKnownAPIVersions[gvString]; useKubeadmVersion != "" {
|
if useKubeadmVersion := oldKnownAPIVersions[gvString]; useKubeadmVersion != "" {
|
||||||
return errors.Errorf("your configuration file uses an old API spec: %q (kind: %q). Please use kubeadm %s instead and run 'kubeadm config migrate --old-config old.yaml --new-config new.yaml', which will write the new, similar spec using a newer API version.", gvString, gvk.Kind, useKubeadmVersion)
|
return errors.Errorf("your configuration file uses an old API spec: %q (kind: %q). Please use kubeadm %s instead and run 'kubeadm config migrate --old-config old-config-file --new-config new-config-file', which will write the new, similar spec using a newer API version.", gvString, gvk.Kind, useKubeadmVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, present := deprecatedAPIVersions[gvString]; present && !allowDeprecated {
|
if _, present := deprecatedAPIVersions[gvString]; present && !allowDeprecated {
|
||||||
klog.Warningf("your configuration file uses a deprecated API spec: %q (kind: %q). Please use 'kubeadm config migrate --old-config old.yaml --new-config new.yaml', which will write the new, similar spec using a newer API version.", gvString, gvk.Kind)
|
klog.Warningf("your configuration file uses a deprecated API spec: %q (kind: %q). Please use 'kubeadm config migrate --old-config old-config-file --new-config new-config-file', which will write the new, similar spec using a newer API version.", gvString, gvk.Kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, present := experimentalAPIVersions[gvString]; present && !allowExperimental {
|
if _, present := experimentalAPIVersions[gvString]; present && !allowExperimental {
|
||||||
|
@ -291,7 +291,7 @@ func LoadOrDefaultInitConfiguration(cfgPath string, versionedInitCfg *kubeadmapi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BytesToInitConfiguration converts a byte slice to an internal, defaulted and validated InitConfiguration object.
|
// BytesToInitConfiguration converts a byte slice to an internal, defaulted and validated InitConfiguration object.
|
||||||
// The map may contain many different YAML documents. These YAML documents are parsed one-by-one
|
// The map may contain many different YAML/JSON documents. These YAML/JSON documents are parsed one-by-one
|
||||||
// and well-known ComponentConfig GroupVersionKinds are stored inside of the internal InitConfiguration struct.
|
// 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.
|
// The resulting InitConfiguration is then dynamically defaulted and validated prior to return.
|
||||||
func BytesToInitConfiguration(b []byte, skipCRIDetect bool) (*kubeadmapi.InitConfiguration, error) {
|
func BytesToInitConfiguration(b []byte, skipCRIDetect bool) (*kubeadmapi.InitConfiguration, error) {
|
||||||
@ -303,7 +303,7 @@ func BytesToInitConfiguration(b []byte, skipCRIDetect bool) (*kubeadmapi.InitCon
|
|||||||
return documentMapToInitConfiguration(gvkmap, false, false, false, skipCRIDetect)
|
return documentMapToInitConfiguration(gvkmap, false, false, false, skipCRIDetect)
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentMapToInitConfiguration converts a map of GVKs and YAML documents to defaulted and validated configuration object.
|
// documentMapToInitConfiguration converts a map of GVKs and YAML/JSON documents to defaulted and validated configuration object.
|
||||||
func documentMapToInitConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecated, allowExperimental, strictErrors, skipCRIDetect bool) (*kubeadmapi.InitConfiguration, error) {
|
func documentMapToInitConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecated, allowExperimental, strictErrors, skipCRIDetect bool) (*kubeadmapi.InitConfiguration, error) {
|
||||||
var initcfg *kubeadmapi.InitConfiguration
|
var initcfg *kubeadmapi.InitConfiguration
|
||||||
var clustercfg *kubeadmapi.ClusterConfiguration
|
var clustercfg *kubeadmapi.ClusterConfiguration
|
||||||
@ -326,7 +326,7 @@ func documentMapToInitConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecat
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify the validity of the YAML
|
// verify the validity of the JSON/YAML
|
||||||
if err := strict.VerifyUnmarshalStrict([]*runtime.Scheme{kubeadmscheme.Scheme, componentconfigs.Scheme}, gvk, fileContent); err != nil {
|
if err := strict.VerifyUnmarshalStrict([]*runtime.Scheme{kubeadmscheme.Scheme, componentconfigs.Scheme}, gvk, fileContent); err != nil {
|
||||||
if !strictErrors {
|
if !strictErrors {
|
||||||
klog.Warning(err.Error())
|
klog.Warning(err.Error())
|
||||||
@ -358,13 +358,13 @@ func documentMapToInitConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecat
|
|||||||
|
|
||||||
// If the group is neither a kubeadm core type or of a supported component config group, we dump a warning about it being ignored
|
// If the group is neither a kubeadm core type or of a supported component config group, we dump a warning about it being ignored
|
||||||
if !componentconfigs.Scheme.IsGroupRegistered(gvk.Group) {
|
if !componentconfigs.Scheme.IsGroupRegistered(gvk.Group) {
|
||||||
klog.Warningf("[config] WARNING: Ignored YAML document with GroupVersionKind %v\n", gvk)
|
klog.Warningf("[config] WARNING: Ignored configuration document with GroupVersionKind %v\n", gvk)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enforce that InitConfiguration and/or ClusterConfiguration has to exist among the YAML documents
|
// Enforce that InitConfiguration and/or ClusterConfiguration has to exist among the configuration documents
|
||||||
if initcfg == nil && clustercfg == nil {
|
if initcfg == nil && clustercfg == nil {
|
||||||
return nil, errors.New("no InitConfiguration or ClusterConfiguration kind was found in the YAML file")
|
return nil, errors.New("no InitConfiguration or ClusterConfiguration kind was found in the configuration file")
|
||||||
}
|
}
|
||||||
|
|
||||||
// If InitConfiguration wasn't given, default it by creating an external struct instance, default it and convert into the internal type
|
// If InitConfiguration wasn't given, default it by creating an external struct instance, default it and convert into the internal type
|
||||||
@ -408,7 +408,7 @@ func documentMapToInitConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecat
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MarshalInitConfigurationToBytes marshals the internal InitConfiguration object to bytes. It writes the embedded
|
// MarshalInitConfigurationToBytes marshals the internal InitConfiguration object to bytes. It writes the embedded
|
||||||
// ClusterConfiguration object with ComponentConfigs out as separate YAML documents
|
// ClusterConfiguration object with ComponentConfigs out as separate YAML/JSON documents
|
||||||
func MarshalInitConfigurationToBytes(cfg *kubeadmapi.InitConfiguration, gv schema.GroupVersion) ([]byte, error) {
|
func MarshalInitConfigurationToBytes(cfg *kubeadmapi.InitConfiguration, gv schema.GroupVersion) ([]byte, error) {
|
||||||
initbytes, err := kubeadmutil.MarshalToYamlForCodecs(cfg, gv, kubeadmscheme.Codecs)
|
initbytes, err := kubeadmutil.MarshalToYamlForCodecs(cfg, gv, kubeadmscheme.Codecs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -95,7 +95,7 @@ func LoadJoinConfigurationFromFile(cfgPath string, opts LoadOrDefaultConfigurati
|
|||||||
return documentMapToJoinConfiguration(gvkmap, false, false, false, opts.SkipCRIDetect)
|
return documentMapToJoinConfiguration(gvkmap, false, false, false, opts.SkipCRIDetect)
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentMapToJoinConfiguration takes a map between GVKs and YAML documents (as returned by SplitYAMLDocuments),
|
// documentMapToJoinConfiguration takes a map between GVKs and YAML/JSON documents (as returned by SplitYAMLDocuments),
|
||||||
// finds a JoinConfiguration, decodes it, dynamically defaults it and then validates it prior to return.
|
// finds a JoinConfiguration, decodes it, dynamically defaults it and then validates it prior to return.
|
||||||
func documentMapToJoinConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecated, allowExperimental, strictErrors, skipCRIDetect bool) (*kubeadmapi.JoinConfiguration, error) {
|
func documentMapToJoinConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecated, allowExperimental, strictErrors, skipCRIDetect bool) (*kubeadmapi.JoinConfiguration, error) {
|
||||||
joinBytes := []byte{}
|
joinBytes := []byte{}
|
||||||
@ -110,7 +110,7 @@ func documentMapToJoinConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecat
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify the validity of the YAML
|
// verify the validity of the YAML/JSON
|
||||||
if err := strict.VerifyUnmarshalStrict([]*runtime.Scheme{kubeadmscheme.Scheme}, gvk, bytes); err != nil {
|
if err := strict.VerifyUnmarshalStrict([]*runtime.Scheme{kubeadmscheme.Scheme}, gvk, bytes); err != nil {
|
||||||
if !strictErrors {
|
if !strictErrors {
|
||||||
klog.Warning(err.Error())
|
klog.Warning(err.Error())
|
||||||
|
@ -99,7 +99,7 @@ func LoadResetConfigurationFromFile(cfgPath string, opts LoadOrDefaultConfigurat
|
|||||||
return documentMapToResetConfiguration(gvkmap, false, opts.AllowExperimental, false, opts.SkipCRIDetect)
|
return documentMapToResetConfiguration(gvkmap, false, opts.AllowExperimental, false, opts.SkipCRIDetect)
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentMapToResetConfiguration takes a map between GVKs and YAML documents (as returned by SplitYAMLDocuments),
|
// documentMapToResetConfiguration takes a map between GVKs and YAML/JSON documents (as returned by SplitYAMLDocuments),
|
||||||
// finds a ResetConfiguration, decodes it, dynamically defaults it and then validates it prior to return.
|
// finds a ResetConfiguration, decodes it, dynamically defaults it and then validates it prior to return.
|
||||||
func documentMapToResetConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecated, allowExperimental bool, strictErrors bool, skipCRIDetect bool) (*kubeadmapi.ResetConfiguration, error) {
|
func documentMapToResetConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecated, allowExperimental bool, strictErrors bool, skipCRIDetect bool) (*kubeadmapi.ResetConfiguration, error) {
|
||||||
resetBytes := []byte{}
|
resetBytes := []byte{}
|
||||||
@ -114,7 +114,7 @@ func documentMapToResetConfiguration(gvkmap kubeadmapi.DocumentMap, allowDepreca
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify the validity of the YAML
|
// verify the validity of the YAML/JSON
|
||||||
if err := strict.VerifyUnmarshalStrict([]*runtime.Scheme{kubeadmscheme.Scheme}, gvk, bytes); err != nil {
|
if err := strict.VerifyUnmarshalStrict([]*runtime.Scheme{kubeadmscheme.Scheme}, gvk, bytes); err != nil {
|
||||||
if !strictErrors {
|
if !strictErrors {
|
||||||
klog.Warning(err.Error())
|
klog.Warning(err.Error())
|
||||||
|
@ -28,25 +28,19 @@ import (
|
|||||||
kubeadmscheme "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme"
|
kubeadmscheme "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme"
|
||||||
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta4"
|
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta4"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/validation"
|
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/validation"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/componentconfigs"
|
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/util/config/strict"
|
"k8s.io/kubernetes/cmd/kubeadm/app/util/config/strict"
|
||||||
)
|
)
|
||||||
|
|
||||||
// documentMapToUpgradeConfiguration takes a map between GVKs and YAML documents (as returned by SplitYAMLDocuments),
|
// documentMapToUpgradeConfiguration takes a map between GVKs and YAML/JSON documents (as returned by SplitYAMLDocuments),
|
||||||
// finds a UpgradeConfiguration, decodes it, dynamically defaults it and then validates it prior to return.
|
// finds a UpgradeConfiguration, decodes it, dynamically defaults it and then validates it prior to return.
|
||||||
func documentMapToUpgradeConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecated bool) (*kubeadmapi.UpgradeConfiguration, error) {
|
func documentMapToUpgradeConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecated bool) (*kubeadmapi.UpgradeConfiguration, error) {
|
||||||
upgradeBytes := []byte{}
|
upgradeBytes := []byte{}
|
||||||
|
|
||||||
for gvk, bytes := range gvkmap {
|
for gvk, bytes := range gvkmap {
|
||||||
if kubeadmutil.GroupVersionKindsHasInitConfiguration(gvk) || kubeadmutil.GroupVersionKindsHasClusterConfiguration(gvk) || componentconfigs.Scheme.IsGroupRegistered(gvk.Group) {
|
|
||||||
klog.Warningf("[config] WARNING: YAML document with GroupVersionKind %v is deprecated for upgrade, please use config file with kind of UpgradeConfiguration instead \n", gvk)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if gvk.Kind != constants.UpgradeConfigurationKind {
|
if gvk.Kind != constants.UpgradeConfigurationKind {
|
||||||
klog.Warningf("[config] WARNING: Ignored YAML document with GroupVersionKind %v\n", gvk)
|
klog.Warningf("[config] WARNING: Ignored configuration document with GroupVersionKind %v\n", gvk)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +49,7 @@ func documentMapToUpgradeConfiguration(gvkmap kubeadmapi.DocumentMap, allowDepre
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify the validity of the YAML
|
// verify the validity of the YAML/JSON
|
||||||
if err := strict.VerifyUnmarshalStrict([]*runtime.Scheme{kubeadmscheme.Scheme}, gvk, bytes); err != nil {
|
if err := strict.VerifyUnmarshalStrict([]*runtime.Scheme{kubeadmscheme.Scheme}, gvk, bytes); err != nil {
|
||||||
klog.Warning(err.Error())
|
klog.Warning(err.Error())
|
||||||
}
|
}
|
||||||
@ -99,7 +93,7 @@ func LoadUpgradeConfigurationFromFile(cfgPath string, _ LoadOrDefaultConfigurati
|
|||||||
return nil, errors.Wrapf(err, "unable to load config from file %q", cfgPath)
|
return nil, errors.Wrapf(err, "unable to load config from file %q", cfgPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split the YAML documents in the file into a DocumentMap
|
// Split the YAML/JSON documents in the file into a DocumentMap
|
||||||
docmap, err := kubeadmutil.SplitYAMLDocuments(configBytes)
|
docmap, err := kubeadmutil.SplitYAMLDocuments(configBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user