Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubeadm: Replace the yaml in the log/comments with a generic term. #130345

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/kubeadm/app/cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ func TestNewCmdConfigPrintActionDefaults(t *testing.T) {
t.Fatalf("Error from running the print command: %v", err)
}

gvkmap, err := kubeadmutil.SplitYAMLDocuments(output.Bytes())
gvkmap, err := kubeadmutil.SplitConfigDocuments(output.Bytes())
if err != nil {
t.Fatalf("unexpected failure of SplitYAMLDocuments: %v", err)
t.Fatalf("unexpected failure of SplitConfigDocuments: %v", err)
}

gotKinds := []string{}
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubeadm/app/componentconfigs/configset.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (h *handler) fromConfigMap(client clientset.Interface, cmName, cmKey string
return nil, errors.Errorf("unexpected error when reading %s ConfigMap: %s key value pair missing", cmName, cmKey)
}

gvkmap, err := kubeadmutil.SplitYAMLDocuments([]byte(configData))
gvkmap, err := kubeadmutil.SplitConfigDocuments([]byte(configData))
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubeadm/app/componentconfigs/configset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ func TestFetchFromDocumentMap(t *testing.T) {
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
`)
gvkmap, err := kubeadmutil.SplitYAMLDocuments([]byte(test))
gvkmap, err := kubeadmutil.SplitConfigDocuments([]byte(test))
if err != nil {
t.Fatalf("unexpected failure of SplitYAMLDocuments: %v", err)
t.Fatalf("unexpected failure of SplitConfigDocuments: %v", err)
}

clusterCfg := testClusterCfg()
Expand Down
8 changes: 4 additions & 4 deletions cmd/kubeadm/app/componentconfigs/fakeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ func TestConfigBaseUnmarshal(t *testing.T) {
config: validUnmarshallableClusterConfig.obj,
}

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

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

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

return clusterConfigHandler.FromDocumentMap(gvkmap)
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubeadm/app/phases/kubelet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func ApplyPatchesToConfig(cfg *kubeadmapi.ClusterConfiguration, patchesDir strin
}
}

gvkmap, err := kubeadmutil.SplitYAMLDocuments(kubeletBytes)
gvkmap, err := kubeadmutil.SplitConfigDocuments(kubeletBytes)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubeadm/app/util/config/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func FetchInitConfigurationFromCluster(client clientset.Interface, printer outpu
}
_, _ = printer.Printf("[%s] Reading configuration from the %q ConfigMap in namespace %q...\n",
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
cfg, err := getInitConfigurationFromCluster(constants.KubernetesDir, client, newControlPlane, skipComponentConfigs)
Expand Down Expand Up @@ -214,7 +214,7 @@ func GetNodeRegistration(kubeconfigFile string, client clientset.Interface, node

// 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
// information in the local kubelet config.yaml
// information in the local kubelet config configuration file.
func getNodeNameFromKubeletConfig(fileName string) (string, error) {
// loads the kubelet.conf file
config, err := clientcmd.LoadFromFile(fileName)
Expand Down
8 changes: 4 additions & 4 deletions cmd/kubeadm/app/util/config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ func validateSupportedVersion(gvk schema.GroupVersionKind, allowDeprecated, allo
gvString := gvk.GroupVersion().String()

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 {
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 {
Expand Down Expand Up @@ -256,7 +256,7 @@ func MigrateOldConfig(oldConfig []byte, allowExperimental bool, mutators migrate
mutators = defaultMigrateMutators()
}

gvkmap, err := kubeadmutil.SplitYAMLDocuments(oldConfig)
gvkmap, err := kubeadmutil.SplitConfigDocuments(oldConfig)
if err != nil {
return []byte{}, err
}
Expand Down Expand Up @@ -329,7 +329,7 @@ func MigrateOldConfig(oldConfig []byte, allowExperimental bool, mutators migrate
// ValidateConfig takes a byte slice containing a kubeadm configuration and performs conversion
// to internal types and validation.
func ValidateConfig(config []byte, allowExperimental bool) error {
gvkmap, err := kubeadmutil.SplitYAMLDocuments(config)
gvkmap, err := kubeadmutil.SplitConfigDocuments(config)
if err != nil {
return err
}
Expand Down
10 changes: 10 additions & 0 deletions cmd/kubeadm/app/util/config/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ import (

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/apimachinery/pkg/util/version"
apimachineryversion "k8s.io/apimachinery/pkg/version"
"sigs.k8s.io/yaml"

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

const KubeadmGroupName = "kubeadm.k8s.io"

var formats = []struct {
name string
marshal func(interface{}) ([]byte, error)
}{
{name: "JSON", marshal: json.Marshal},
{name: "YAML", marshal: yaml.Marshal},
}

func TestValidateSupportedVersion(t *testing.T) {
tests := []struct {
gvk schema.GroupVersionKind
Expand Down
17 changes: 9 additions & 8 deletions cmd/kubeadm/app/util/config/initconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,19 +291,20 @@ 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 documents. These YAML 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) {
gvkmap, err := kubeadmutil.SplitYAMLDocuments(b)
// Split the YAML/JSON documents in the file into a DocumentMap
gvkmap, err := kubeadmutil.SplitConfigDocuments(b)
if err != nil {
return nil, err
}

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) {
var initcfg *kubeadmapi.InitConfiguration
var clustercfg *kubeadmapi.ClusterConfiguration
Expand All @@ -326,7 +327,7 @@ func documentMapToInitConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecat
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 !strictErrors {
klog.Warning(err.Error())
Expand Down Expand Up @@ -358,13 +359,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 !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 {
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
Expand Down Expand Up @@ -408,7 +409,7 @@ func documentMapToInitConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecat
}

// 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) {
initbytes, err := kubeadmutil.MarshalToYamlForCodecs(cfg, gv, kubeadmscheme.Codecs)
if err != nil {
Expand Down
Loading