rename SplitYAMLDocuments function

This commit is contained in:
HirazawaUi 2025-02-21 22:34:52 +08:00
parent 2d8d972cb8
commit 77647cdfc3
13 changed files with 23 additions and 23 deletions

View File

@ -399,9 +399,9 @@ func TestNewCmdConfigPrintActionDefaults(t *testing.T) {
t.Fatalf("Error from running the print command: %v", err) 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 { if err != nil {
t.Fatalf("unexpected failure of SplitYAMLDocuments: %v", err) t.Fatalf("unexpected failure of SplitConfigDocuments: %v", err)
} }
gotKinds := []string{} gotKinds := []string{}

View File

@ -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) 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 { if err != nil {
return nil, err return nil, err
} }

View File

@ -78,9 +78,9 @@ func TestFetchFromDocumentMap(t *testing.T) {
apiVersion: kubelet.config.k8s.io/v1beta1 apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration kind: KubeletConfiguration
`) `)
gvkmap, err := kubeadmutil.SplitYAMLDocuments([]byte(test)) gvkmap, err := kubeadmutil.SplitConfigDocuments([]byte(test))
if err != nil { if err != nil {
t.Fatalf("unexpected failure of SplitYAMLDocuments: %v", err) t.Fatalf("unexpected failure of SplitConfigDocuments: %v", err)
} }
clusterCfg := testClusterCfg() clusterCfg := testClusterCfg()

View File

@ -293,9 +293,9 @@ func TestConfigBaseUnmarshal(t *testing.T) {
config: validUnmarshallableClusterConfig.obj, config: validUnmarshallableClusterConfig.obj,
} }
gvkmap, err := kubeadmutil.SplitYAMLDocuments([]byte(validUnmarshallableClusterConfig.yaml)) gvkmap, err := kubeadmutil.SplitConfigDocuments([]byte(validUnmarshallableClusterConfig.yaml))
if err != nil { if err != nil {
t.Fatalf("unexpected failure of SplitYAMLDocuments: %v", err) t.Fatalf("unexpected failure of SplitConfigDocuments: %v", err)
} }
got := &clusterConfig{ got := &clusterConfig{
@ -461,9 +461,9 @@ func runClusterConfigFromTest(t *testing.T, perform func(t *testing.T, in string
func TestLoadingFromDocumentMap(t *testing.T) { func TestLoadingFromDocumentMap(t *testing.T) {
runClusterConfigFromTest(t, func(t *testing.T, in string) (kubeadmapi.ComponentConfig, error) { 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 { if err != nil {
t.Fatalf("unexpected failure of SplitYAMLDocuments: %v", err) t.Fatalf("unexpected failure of SplitConfigDocuments: %v", err)
} }
return clusterConfigHandler.FromDocumentMap(gvkmap) return clusterConfigHandler.FromDocumentMap(gvkmap)

View File

@ -110,7 +110,7 @@ func ApplyPatchesToConfig(cfg *kubeadmapi.ClusterConfiguration, patchesDir strin
} }
} }
gvkmap, err := kubeadmutil.SplitYAMLDocuments(kubeletBytes) gvkmap, err := kubeadmutil.SplitConfigDocuments(kubeletBytes)
if err != nil { if err != nil {
return err return err
} }

View File

@ -256,7 +256,7 @@ func MigrateOldConfig(oldConfig []byte, allowExperimental bool, mutators migrate
mutators = defaultMigrateMutators() mutators = defaultMigrateMutators()
} }
gvkmap, err := kubeadmutil.SplitYAMLDocuments(oldConfig) gvkmap, err := kubeadmutil.SplitConfigDocuments(oldConfig)
if err != nil { if err != nil {
return []byte{}, err return []byte{}, err
} }
@ -329,7 +329,7 @@ func MigrateOldConfig(oldConfig []byte, allowExperimental bool, mutators migrate
// ValidateConfig takes a byte slice containing a kubeadm configuration and performs conversion // ValidateConfig takes a byte slice containing a kubeadm configuration and performs conversion
// to internal types and validation. // to internal types and validation.
func ValidateConfig(config []byte, allowExperimental bool) error { func ValidateConfig(config []byte, allowExperimental bool) error {
gvkmap, err := kubeadmutil.SplitYAMLDocuments(config) gvkmap, err := kubeadmutil.SplitConfigDocuments(config)
if err != nil { if err != nil {
return err return err
} }

View File

@ -295,7 +295,7 @@ func LoadOrDefaultInitConfiguration(cfgPath string, versionedInitCfg *kubeadmapi
// 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) {
gvkmap, err := kubeadmutil.SplitYAMLDocuments(b) gvkmap, err := kubeadmutil.SplitConfigDocuments(b)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -87,7 +87,7 @@ func LoadJoinConfigurationFromFile(cfgPath string, opts LoadOrDefaultConfigurati
return nil, errors.Wrapf(err, "unable to read config from %q ", cfgPath) return nil, errors.Wrapf(err, "unable to read config from %q ", cfgPath)
} }
gvkmap, err := kubeadmutil.SplitYAMLDocuments(b) gvkmap, err := kubeadmutil.SplitConfigDocuments(b)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -91,7 +91,7 @@ func LoadResetConfigurationFromFile(cfgPath string, opts LoadOrDefaultConfigurat
return nil, errors.Wrapf(err, "unable to read config from %q ", cfgPath) return nil, errors.Wrapf(err, "unable to read config from %q ", cfgPath)
} }
gvkmap, err := kubeadmutil.SplitYAMLDocuments(b) gvkmap, err := kubeadmutil.SplitConfigDocuments(b)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -94,7 +94,7 @@ func LoadUpgradeConfigurationFromFile(cfgPath string, _ LoadOrDefaultConfigurati
} }
// Split the YAML/JSON 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.SplitConfigDocuments(configBytes)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -122,9 +122,9 @@ func TestDocMapToUpgradeConfiguration(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unexpected error while marshalling to YAML: %v", err) t.Fatalf("unexpected error while marshalling to YAML: %v", err)
} }
docmap, err := kubeadmutil.SplitYAMLDocuments(b) docmap, err := kubeadmutil.SplitConfigDocuments(b)
if err != nil { if err != nil {
t.Fatalf("Unexpected error of SplitYAMLDocuments: %v", err) t.Fatalf("Unexpected error of SplitConfigDocuments: %v", err)
} }
cfg, err := DocMapToUpgradeConfiguration(docmap) cfg, err := DocMapToUpgradeConfiguration(docmap)
if (err != nil) != tc.expectedError { if (err != nil) != tc.expectedError {

View File

@ -65,13 +65,13 @@ func UniversalUnmarshal(buffer []byte) (runtime.Object, error) {
return obj, nil return obj, nil
} }
// SplitYAMLDocuments reads the YAML bytes per-document, unmarshals the TypeMeta information from each document // SplitConfigDocuments reads the YAML/JSON bytes per-document, unmarshals the TypeMeta information from each document
// and returns a map between the GroupVersionKind of the document and the document bytes // and returns a map between the GroupVersionKind of the document and the document bytes
func SplitYAMLDocuments(yamlBytes []byte) (kubeadmapi.DocumentMap, error) { func SplitConfigDocuments(documentBytes []byte) (kubeadmapi.DocumentMap, error) {
gvkmap := kubeadmapi.DocumentMap{} gvkmap := kubeadmapi.DocumentMap{}
knownKinds := map[string]bool{} knownKinds := map[string]bool{}
errs := []error{} errs := []error{}
buf := bytes.NewBuffer(yamlBytes) buf := bytes.NewBuffer(documentBytes)
reader := utilyaml.NewYAMLReader(bufio.NewReader(buf)) reader := utilyaml.NewYAMLReader(bufio.NewReader(buf))
for { for {
// Read one YAML document at a time, until io.EOF is returned // Read one YAML document at a time, until io.EOF is returned
@ -111,7 +111,7 @@ func SplitYAMLDocuments(yamlBytes []byte) (kubeadmapi.DocumentMap, error) {
// GroupVersionKindsFromBytes parses the bytes and returns a gvk slice // GroupVersionKindsFromBytes parses the bytes and returns a gvk slice
func GroupVersionKindsFromBytes(b []byte) ([]schema.GroupVersionKind, error) { func GroupVersionKindsFromBytes(b []byte) ([]schema.GroupVersionKind, error) {
gvkmap, err := SplitYAMLDocuments(b) gvkmap, err := SplitConfigDocuments(b)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -199,7 +199,7 @@ func TestSplitYAMLDocuments(t *testing.T) {
for _, rt := range tests { for _, rt := range tests {
t.Run(rt.name, func(t2 *testing.T) { t.Run(rt.name, func(t2 *testing.T) {
gvkmap, err := SplitYAMLDocuments(rt.fileContents) gvkmap, err := SplitConfigDocuments(rt.fileContents)
if (err != nil) != rt.expectedErr { if (err != nil) != rt.expectedErr {
t2.Errorf("expected error: %t, actual: %t", rt.expectedErr, err != nil) t2.Errorf("expected error: %t, actual: %t", rt.expectedErr, err != nil)
} }