Skip to content

Commit a154e82

Browse files
committed
Add nil checks to MergeDevWorkspaceTemplateSpec
Signed-off-by: Angel Misevski <[email protected]>
1 parent e6e50e6 commit a154e82

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

pkg/utils/overriding/merging.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,31 @@ func MergeDevWorkspaceTemplateSpec(
2525
parentFlattenedContent *workspaces.DevWorkspaceTemplateSpecContent,
2626
pluginFlattenedContents ...*workspaces.DevWorkspaceTemplateSpecContent) (*workspaces.DevWorkspaceTemplateSpecContent, error) {
2727

28-
allContents := []*workspaces.DevWorkspaceTemplateSpecContent{parentFlattenedContent}
29-
allContents = append(allContents, pluginFlattenedContents...)
30-
allContents = append(allContents, mainContent)
31-
32-
if err := ensureNoConflictWithParent(mainContent, parentFlattenedContent); err != nil {
33-
return nil, err
28+
allContents := []*workspaces.DevWorkspaceTemplateSpecContent{}
29+
if parentFlattenedContent != nil {
30+
allContents = append(allContents, parentFlattenedContent)
31+
}
32+
if len(pluginFlattenedContents) > 0 {
33+
allContents = append(allContents, pluginFlattenedContents...)
3434
}
35+
allContents = append(allContents, mainContent)
3536

36-
if err := ensureNoConflictsWithPlugins(mainContent, pluginFlattenedContents...); err != nil {
37-
return nil, err
37+
// Check for conflicts
38+
if parentFlattenedContent != nil {
39+
if err := ensureNoConflictWithParent(mainContent, parentFlattenedContent); err != nil {
40+
return nil, err
41+
}
3842
}
39-
// also need to ensure no conflict between parent and plugins
40-
if err := ensureNoConflictsWithPlugins(parentFlattenedContent, pluginFlattenedContents...); err != nil {
41-
return nil, err
43+
if len(pluginFlattenedContents) > 0 {
44+
if err := ensureNoConflictsWithPlugins(mainContent, pluginFlattenedContents...); err != nil {
45+
return nil, err
46+
}
47+
if parentFlattenedContent != nil {
48+
// also need to ensure no conflict between parent and plugins
49+
if err := ensureNoConflictsWithPlugins(parentFlattenedContent, pluginFlattenedContents...); err != nil {
50+
return nil, err
51+
}
52+
}
4253
}
4354

4455
result := workspaces.DevWorkspaceTemplateSpecContent{}

0 commit comments

Comments
 (0)