Parse parses manifest bytes into MappingResult
(manifest []byte, defaultNamespace string, normalizeManifests bool, excludedHooks ...string)
| 71 | |
| 72 | // Parse parses manifest bytes into MappingResult |
| 73 | func Parse(manifest []byte, defaultNamespace string, normalizeManifests bool, excludedHooks ...string) map[string]*MappingResult { |
| 74 | scanner := bufio.NewScanner(io.MultiReader(strings.NewReader("\n"), bytes.NewReader(manifest))) |
| 75 | scanner.Split(scanYamlSpecs) |
| 76 | // Allow for tokens (specs) up to 10MiB in size |
| 77 | scanner.Buffer(make([]byte, bufio.MaxScanTokenSize), 10485760) |
| 78 | |
| 79 | result := make(map[string]*MappingResult) |
| 80 | |
| 81 | for scanner.Scan() { |
| 82 | content := bytes.TrimSpace(scanner.Bytes()) |
| 83 | if len(content) == 0 { |
| 84 | continue |
| 85 | } |
| 86 | |
| 87 | parsed, err := parseContent(content, defaultNamespace, normalizeManifests, excludedHooks...) |
| 88 | if err != nil { |
| 89 | log.Fatalf("%v", err) |
| 90 | } |
| 91 | |
| 92 | for _, p := range parsed { |
| 93 | name := p.Name |
| 94 | |
| 95 | if _, ok := result[name]; ok { |
| 96 | log.Printf("Error: Found duplicate key %#v in manifest", name) |
| 97 | } else { |
| 98 | result[name] = p |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | if err := scanner.Err(); err != nil { |
| 103 | log.Fatalf("Error reading input: %s", err) |
| 104 | } |
| 105 | return result |
| 106 | } |
| 107 | |
| 108 | func ParseObject(object runtime.Object, defaultNamespace string, excludedHooks ...string) (*MappingResult, string, error) { |
| 109 | json, _ := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(object) |