MergeDevWorkspaceTemplateSpecBytes implements the merging logic of a main devfile content with flattened, already-overridden parent devfiles or plugins. On an json or yaml document that contains the core content of the devfile (which is the core part of a devfile, without the `apiVersion` and `metad
(originalBytes []byte, flattenedParentBytes []byte, flattenPluginsBytes ...[]byte)
| 166 | // The result is a transformed `DevfileWorkspaceTemplateSpec` object, that does not contain any `plugin` component |
| 167 | // (since they are expected to be provided as flattened overridden devfiles in the arguments) |
| 168 | func MergeDevWorkspaceTemplateSpecBytes(originalBytes []byte, flattenedParentBytes []byte, flattenPluginsBytes ...[]byte) (*dw.DevWorkspaceTemplateSpecContent, error) { |
| 169 | originalJson, err := yaml.ToJSON(originalBytes) |
| 170 | if err != nil { |
| 171 | return nil, err |
| 172 | } |
| 173 | |
| 174 | original := dw.DevWorkspaceTemplateSpecContent{} |
| 175 | err = json.Unmarshal(originalJson, &original) |
| 176 | if err != nil { |
| 177 | return nil, err |
| 178 | } |
| 179 | |
| 180 | flattenedParentJson, err := yaml.ToJSON(flattenedParentBytes) |
| 181 | if err != nil { |
| 182 | return nil, err |
| 183 | } |
| 184 | |
| 185 | flattenedParent := dw.DevWorkspaceTemplateSpecContent{} |
| 186 | err = json.Unmarshal(flattenedParentJson, &flattenedParent) |
| 187 | if err != nil { |
| 188 | return nil, err |
| 189 | } |
| 190 | |
| 191 | flattenedPlugins := []*dw.DevWorkspaceTemplateSpecContent{} |
| 192 | for _, flattenedPluginBytes := range flattenPluginsBytes { |
| 193 | flattenedPluginJson, err := yaml.ToJSON(flattenedPluginBytes) |
| 194 | if err != nil { |
| 195 | return nil, err |
| 196 | } |
| 197 | |
| 198 | flattenedPlugin := dw.DevWorkspaceTemplateSpecContent{} |
| 199 | err = json.Unmarshal(flattenedPluginJson, &flattenedPlugin) |
| 200 | if err != nil { |
| 201 | return nil, err |
| 202 | } |
| 203 | flattenedPlugins = append(flattenedPlugins, &flattenedPlugin) |
| 204 | } |
| 205 | |
| 206 | return MergeDevWorkspaceTemplateSpec(&original, &flattenedParent, flattenedPlugins...) |
| 207 | } |
| 208 | |
| 209 | func ensureNoConflictWithParent(mainContent *dw.DevWorkspaceTemplateSpecContent, parentflattenedContent *dw.DevWorkspaceTemplateSpecContent) error { |
| 210 | return checkKeys(func(elementType string, keysSets []sets.String) []error { |