mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
rename SplitYAMLDocuments function
This commit is contained in:
parent
2d8d972cb8
commit
77647cdfc3
@ -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{}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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{
|
||||
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ func LoadOrDefaultInitConfiguration(cfgPath string, versionedInitCfg *kubeadmapi
|
||||
// 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)
|
||||
gvkmap, err := kubeadmutil.SplitConfigDocuments(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ func LoadJoinConfigurationFromFile(cfgPath string, opts LoadOrDefaultConfigurati
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ func LoadResetConfigurationFromFile(cfgPath string, opts LoadOrDefaultConfigurat
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ func LoadUpgradeConfigurationFromFile(cfgPath string, _ LoadOrDefaultConfigurati
|
||||
}
|
||||
|
||||
// Split the YAML/JSON documents in the file into a DocumentMap
|
||||
docmap, err := kubeadmutil.SplitYAMLDocuments(configBytes)
|
||||
docmap, err := kubeadmutil.SplitConfigDocuments(configBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -122,9 +122,9 @@ func TestDocMapToUpgradeConfiguration(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error while marshalling to YAML: %v", err)
|
||||
}
|
||||
docmap, err := kubeadmutil.SplitYAMLDocuments(b)
|
||||
docmap, err := kubeadmutil.SplitConfigDocuments(b)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error of SplitYAMLDocuments: %v", err)
|
||||
t.Fatalf("Unexpected error of SplitConfigDocuments: %v", err)
|
||||
}
|
||||
cfg, err := DocMapToUpgradeConfiguration(docmap)
|
||||
if (err != nil) != tc.expectedError {
|
||||
|
@ -65,13 +65,13 @@ func UniversalUnmarshal(buffer []byte) (runtime.Object, error) {
|
||||
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
|
||||
func SplitYAMLDocuments(yamlBytes []byte) (kubeadmapi.DocumentMap, error) {
|
||||
func SplitConfigDocuments(documentBytes []byte) (kubeadmapi.DocumentMap, error) {
|
||||
gvkmap := kubeadmapi.DocumentMap{}
|
||||
knownKinds := map[string]bool{}
|
||||
errs := []error{}
|
||||
buf := bytes.NewBuffer(yamlBytes)
|
||||
buf := bytes.NewBuffer(documentBytes)
|
||||
reader := utilyaml.NewYAMLReader(bufio.NewReader(buf))
|
||||
for {
|
||||
// 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
|
||||
func GroupVersionKindsFromBytes(b []byte) ([]schema.GroupVersionKind, error) {
|
||||
gvkmap, err := SplitYAMLDocuments(b)
|
||||
gvkmap, err := SplitConfigDocuments(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ func TestSplitYAMLDocuments(t *testing.T) {
|
||||
for _, rt := range tests {
|
||||
t.Run(rt.name, func(t2 *testing.T) {
|
||||
|
||||
gvkmap, err := SplitYAMLDocuments(rt.fileContents)
|
||||
gvkmap, err := SplitConfigDocuments(rt.fileContents)
|
||||
if (err != nil) != rt.expectedErr {
|
||||
t2.Errorf("expected error: %t, actual: %t", rt.expectedErr, err != nil)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user