Skip to content

Commit eacb9be

Browse files
authored
Merge pull request kubernetes#130345 from HirazawaUi/kubeadm-yaml-json
kubeadm: Replace the yaml in the log/comments with a generic term.
2 parents 47dbade + 9a84379 commit eacb9be

18 files changed

+573
-330
lines changed

cmd/kubeadm/app/cmd/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,9 @@ func TestNewCmdConfigPrintActionDefaults(t *testing.T) {
399399
t.Fatalf("Error from running the print command: %v", err)
400400
}
401401

402-
gvkmap, err := kubeadmutil.SplitYAMLDocuments(output.Bytes())
402+
gvkmap, err := kubeadmutil.SplitConfigDocuments(output.Bytes())
403403
if err != nil {
404-
t.Fatalf("unexpected failure of SplitYAMLDocuments: %v", err)
404+
t.Fatalf("unexpected failure of SplitConfigDocuments: %v", err)
405405
}
406406

407407
gotKinds := []string{}

cmd/kubeadm/app/componentconfigs/configset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (h *handler) fromConfigMap(client clientset.Interface, cmName, cmKey string
8686
return nil, errors.Errorf("unexpected error when reading %s ConfigMap: %s key value pair missing", cmName, cmKey)
8787
}
8888

89-
gvkmap, err := kubeadmutil.SplitYAMLDocuments([]byte(configData))
89+
gvkmap, err := kubeadmutil.SplitConfigDocuments([]byte(configData))
9090
if err != nil {
9191
return nil, err
9292
}

cmd/kubeadm/app/componentconfigs/configset_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ func TestFetchFromDocumentMap(t *testing.T) {
7878
apiVersion: kubelet.config.k8s.io/v1beta1
7979
kind: KubeletConfiguration
8080
`)
81-
gvkmap, err := kubeadmutil.SplitYAMLDocuments([]byte(test))
81+
gvkmap, err := kubeadmutil.SplitConfigDocuments([]byte(test))
8282
if err != nil {
83-
t.Fatalf("unexpected failure of SplitYAMLDocuments: %v", err)
83+
t.Fatalf("unexpected failure of SplitConfigDocuments: %v", err)
8484
}
8585

8686
clusterCfg := testClusterCfg()

cmd/kubeadm/app/componentconfigs/fakeconfig_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,9 @@ func TestConfigBaseUnmarshal(t *testing.T) {
293293
config: validUnmarshallableClusterConfig.obj,
294294
}
295295

296-
gvkmap, err := kubeadmutil.SplitYAMLDocuments([]byte(validUnmarshallableClusterConfig.yaml))
296+
gvkmap, err := kubeadmutil.SplitConfigDocuments([]byte(validUnmarshallableClusterConfig.yaml))
297297
if err != nil {
298-
t.Fatalf("unexpected failure of SplitYAMLDocuments: %v", err)
298+
t.Fatalf("unexpected failure of SplitConfigDocuments: %v", err)
299299
}
300300

301301
got := &clusterConfig{
@@ -461,9 +461,9 @@ func runClusterConfigFromTest(t *testing.T, perform func(t *testing.T, in string
461461

462462
func TestLoadingFromDocumentMap(t *testing.T) {
463463
runClusterConfigFromTest(t, func(t *testing.T, in string) (kubeadmapi.ComponentConfig, error) {
464-
gvkmap, err := kubeadmutil.SplitYAMLDocuments([]byte(in))
464+
gvkmap, err := kubeadmutil.SplitConfigDocuments([]byte(in))
465465
if err != nil {
466-
t.Fatalf("unexpected failure of SplitYAMLDocuments: %v", err)
466+
t.Fatalf("unexpected failure of SplitConfigDocuments: %v", err)
467467
}
468468

469469
return clusterConfigHandler.FromDocumentMap(gvkmap)

cmd/kubeadm/app/phases/kubelet/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func ApplyPatchesToConfig(cfg *kubeadmapi.ClusterConfiguration, patchesDir strin
110110
}
111111
}
112112

113-
gvkmap, err := kubeadmutil.SplitYAMLDocuments(kubeletBytes)
113+
gvkmap, err := kubeadmutil.SplitConfigDocuments(kubeletBytes)
114114
if err != nil {
115115
return err
116116
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func FetchInitConfigurationFromCluster(client clientset.Interface, printer outpu
6060
}
6161
_, _ = printer.Printf("[%s] Reading configuration from the %q ConfigMap in namespace %q...\n",
6262
logPrefix, constants.KubeadmConfigConfigMap, metav1.NamespaceSystem)
63-
_, _ = printer.Printf("[%s] Use 'kubeadm init phase upload-config --config your-config.yaml' to re-upload it.\n", logPrefix)
63+
_, _ = printer.Printf("[%s] Use 'kubeadm init phase upload-config --config your-config-file' to re-upload it.\n", logPrefix)
6464

6565
// Fetch the actual config from cluster
6666
cfg, err := getInitConfigurationFromCluster(constants.KubernetesDir, client, newControlPlane, skipComponentConfigs)
@@ -214,7 +214,7 @@ func GetNodeRegistration(kubeconfigFile string, client clientset.Interface, node
214214

215215
// getNodeNameFromKubeletConfig gets the node name from a kubelet config file
216216
// TODO: in future we want to switch to a more canonical way for doing this e.g. by having this
217-
// information in the local kubelet config.yaml
217+
// information in the local kubelet config configuration file.
218218
func getNodeNameFromKubeletConfig(fileName string) (string, error) {
219219
// loads the kubelet.conf file
220220
config, err := clientcmd.LoadFromFile(fileName)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ func validateSupportedVersion(gvk schema.GroupVersionKind, allowDeprecated, allo
9494
gvString := gvk.GroupVersion().String()
9595

9696
if useKubeadmVersion := oldKnownAPIVersions[gvString]; useKubeadmVersion != "" {
97-
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)
97+
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)
9898
}
9999

100100
if _, present := deprecatedAPIVersions[gvString]; present && !allowDeprecated {
101-
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)
101+
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)
102102
}
103103

104104
if _, present := experimentalAPIVersions[gvString]; present && !allowExperimental {
@@ -256,7 +256,7 @@ func MigrateOldConfig(oldConfig []byte, allowExperimental bool, mutators migrate
256256
mutators = defaultMigrateMutators()
257257
}
258258

259-
gvkmap, err := kubeadmutil.SplitYAMLDocuments(oldConfig)
259+
gvkmap, err := kubeadmutil.SplitConfigDocuments(oldConfig)
260260
if err != nil {
261261
return []byte{}, err
262262
}
@@ -329,7 +329,7 @@ func MigrateOldConfig(oldConfig []byte, allowExperimental bool, mutators migrate
329329
// ValidateConfig takes a byte slice containing a kubeadm configuration and performs conversion
330330
// to internal types and validation.
331331
func ValidateConfig(config []byte, allowExperimental bool) error {
332-
gvkmap, err := kubeadmutil.SplitYAMLDocuments(config)
332+
gvkmap, err := kubeadmutil.SplitConfigDocuments(config)
333333
if err != nil {
334334
return err
335335
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ import (
2929

3030
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3131
"k8s.io/apimachinery/pkg/runtime/schema"
32+
"k8s.io/apimachinery/pkg/util/json"
3233
"k8s.io/apimachinery/pkg/util/version"
3334
apimachineryversion "k8s.io/apimachinery/pkg/version"
35+
"sigs.k8s.io/yaml"
3436

3537
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
3638
kubeadmapiv1old "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3"
@@ -41,6 +43,14 @@ import (
4143

4244
const KubeadmGroupName = "kubeadm.k8s.io"
4345

46+
var formats = []struct {
47+
name string
48+
marshal func(interface{}) ([]byte, error)
49+
}{
50+
{name: "JSON", marshal: json.Marshal},
51+
{name: "YAML", marshal: yaml.Marshal},
52+
}
53+
4454
func TestValidateSupportedVersion(t *testing.T) {
4555
tests := []struct {
4656
gvk schema.GroupVersionKind

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,19 +291,20 @@ 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 documents. These YAML 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-
gvkmap, err := kubeadmutil.SplitYAMLDocuments(b)
298+
// Split the YAML/JSON documents in the file into a DocumentMap
299+
gvkmap, err := kubeadmutil.SplitConfigDocuments(b)
299300
if err != nil {
300301
return nil, err
301302
}
302303

303304
return documentMapToInitConfiguration(gvkmap, false, false, false, skipCRIDetect)
304305
}
305306

306-
// documentMapToInitConfiguration converts a map of GVKs and YAML documents to defaulted and validated configuration object.
307+
// documentMapToInitConfiguration converts a map of GVKs and YAML/JSON documents to defaulted and validated configuration object.
307308
func documentMapToInitConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecated, allowExperimental, strictErrors, skipCRIDetect bool) (*kubeadmapi.InitConfiguration, error) {
308309
var initcfg *kubeadmapi.InitConfiguration
309310
var clustercfg *kubeadmapi.ClusterConfiguration
@@ -326,7 +327,7 @@ func documentMapToInitConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecat
326327
return nil, err
327328
}
328329

329-
// verify the validity of the YAML
330+
// verify the validity of the JSON/YAML
330331
if err := strict.VerifyUnmarshalStrict([]*runtime.Scheme{kubeadmscheme.Scheme, componentconfigs.Scheme}, gvk, fileContent); err != nil {
331332
if !strictErrors {
332333
klog.Warning(err.Error())
@@ -358,13 +359,13 @@ func documentMapToInitConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecat
358359

359360
// If the group is neither a kubeadm core type or of a supported component config group, we dump a warning about it being ignored
360361
if !componentconfigs.Scheme.IsGroupRegistered(gvk.Group) {
361-
klog.Warningf("[config] WARNING: Ignored YAML document with GroupVersionKind %v\n", gvk)
362+
klog.Warningf("[config] WARNING: Ignored configuration document with GroupVersionKind %v\n", gvk)
362363
}
363364
}
364365

365-
// Enforce that InitConfiguration and/or ClusterConfiguration has to exist among the YAML documents
366+
// Enforce that InitConfiguration and/or ClusterConfiguration has to exist among the configuration documents
366367
if initcfg == nil && clustercfg == nil {
367-
return nil, errors.New("no InitConfiguration or ClusterConfiguration kind was found in the YAML file")
368+
return nil, errors.New("no InitConfiguration or ClusterConfiguration kind was found in the configuration file")
368369
}
369370

370371
// If InitConfiguration wasn't given, default it by creating an external struct instance, default it and convert into the internal type
@@ -408,7 +409,7 @@ func documentMapToInitConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecat
408409
}
409410

410411
// MarshalInitConfigurationToBytes marshals the internal InitConfiguration object to bytes. It writes the embedded
411-
// ClusterConfiguration object with ComponentConfigs out as separate YAML documents
412+
// ClusterConfiguration object with ComponentConfigs out as separate YAML/JSON documents
412413
func MarshalInitConfigurationToBytes(cfg *kubeadmapi.InitConfiguration, gv schema.GroupVersion) ([]byte, error) {
413414
initbytes, err := kubeadmutil.MarshalToYamlForCodecs(cfg, gv, kubeadmscheme.Codecs)
414415
if err != nil {

0 commit comments

Comments
 (0)