Skip to content

override checkkeys should not assume there is a matching key in the override patch #276

Closed
@yangcao77

Description

@yangcao77

Describe the bug
Override checkkeys assume there is a matching key in the override patch

overlayKeys := keysSets[1]

However, for pluginOverride, it only contains command and component, when try to override a plugin devfile with projects defined, it would throw error because the keyset[1] does not exist.

The plugin devfile content,

					Devfile: v1.Devfile{
						DevfileHeader: devfilepkg.DevfileHeader{
							SchemaVersion: schemaV200,
						},
						DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{
							DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{
								Commands: []v1.Command{
									{
										Id: "devrun",
										CommandUnion: v1.CommandUnion{
											Exec: &v1.ExecCommand{
												WorkingDir:  "/projects",
												CommandLine: "npm run",
											},
										},
									},
								},
								Components: []v1.Component{
									{
										Name: "nodejs",
										ComponentUnion: v1.ComponentUnion{
											Container: &v1.ContainerComponent{
												Container: v1.Container{
													Image: "quay.io/nodejs-10",
												},
											},
										},
									},
								},
								Events: &v1.Events{
									WorkspaceEvents: v1.WorkspaceEvents{
										PostStart: []string{"post-start-0"},
									},
								},
								Projects: []v1.Project{
									{
										ClonePath: "/data",
										ProjectSource: v1.ProjectSource{
											Github: &v1.GithubProjectSource{
												GitLikeProjectSource: v1.GitLikeProjectSource{
													Remotes: map[string]string{
														"master": "https://githube.com/somerepo/someproject.git",
													},
												},
											},
										},
										Name: "nodejs-starter",
									},
								},
							},
						},
					},
				},

The pluginOverride content:

v1.PluginOverrides{
				OverridesBase: v1.OverridesBase{},
				Components: []v1.ComponentPluginOverride{
					{
						Name: "nodejs",
						ComponentUnionPluginOverride: v1.ComponentUnionPluginOverride{
							Container: &v1.ContainerComponentPluginOverride{
								ContainerPluginOverride: v1.ContainerPluginOverride{
									Image: "quay.io/nodejs-12",
								},
							},
						},
					},
				},
				Commands: []v1.CommandPluginOverride{
					{
						Id: "devrun",
						CommandUnionPluginOverride: v1.CommandUnionPluginOverride{
							Exec: &v1.ExecCommandPluginOverride{
								WorkingDir:  "/projects-new",
								CommandLine: "npm build",
							},
						},
					},
				},
			},

The following is the error thrown due to no project key match for nodejs-starter in pluginOverride.

i is 0, and keysSets[i] is map[nodejs:{}]
i is 1, and keysSets[i] is map[nodejs:{}]
i is 0, and keysSets[i] is map[nodejs-starter:{}]
--- FAIL: Test_parseParentAndPlugin (0.01s)
    --- FAIL: Test_parseParentAndPlugin/case_9:_it_should_override_the_plugin's_data_with_local_overrides_and_add_the_local_devfile's_data (0.01s)
panic: runtime error: index out of range [1] with length 1 [recovered]
	panic: runtime error: index out of range [1] with length 1

goroutine 21 [running]:
testing.tRunner.func1.1(0x1a302a0, 0xc0004e8b40)
	/usr/local/go/src/testing/testing.go:1072 +0x30d
testing.tRunner.func1(0xc000103500)
	/usr/local/go/src/testing/testing.go:1075 +0x41a
panic(0x1a302a0, 0xc0004e8b40)
	/usr/local/go/src/runtime/panic.go:969 +0x1b9
github.com/devfile/api/pkg/utils/overriding.ensureOnlyExistingElementsAreOverridden.func1(0x1aa1446, 0x8, 0xc0000107c0, 0x1, 0x1, 0xc000528660, 0x0, 0x0)
	/Users/stephanie/go/pkg/mod/github.com/devfile/[email protected]/pkg/utils/overriding/overriding.go:127 +0x317
github.com/devfile/api/pkg/utils/overriding.checkKeys(0x1b2ab98, 0xc0004b3838, 0x2, 0x2, 0xc000524e40, 0x1010398)
	/Users/stephanie/go/pkg/mod/github.com/devfile/[email protected]/pkg/utils/overriding/keys.go:32 +0x394
github.com/devfile/api/pkg/utils/overriding.ensureOnlyExistingElementsAreOverridden(0xc00009c358, 0x1be0000, 0xc000524e40, 0x10171bb, 0xc000524e40)
	/Users/stephanie/go/pkg/mod/github.com/devfile/[email protected]/pkg/utils/overriding/overriding.go:117 +0xa8
github.com/devfile/api/pkg/utils/overriding.OverrideDevWorkspaceTemplateSpec(0xc00009c358, 0x1be0000, 0xc000524e40, 0xc000524e40, 0x1, 0x1a)
	/Users/stephanie/go/pkg/mod/github.com/devfile/[email protected]/pkg/utils/overriding/overriding.go:59 +0xba
github.com/devfile/library/pkg/devfile/parser.parseParentAndPlugin(0x0, 0x0, 0x0, 0x0, 0x1aa4071, 0xc, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/stephanie/go/src/github.com/devfile/library/pkg/devfile/parser/parse.go:146 +0x63b
github.com/devfile/library/pkg/devfile/parser.Test_parseParentAndPlugin.func1(0xc000103500)
	/Users/stephanie/go/src/github.com/devfile/library/pkg/devfile/parser/parse_test.go:1155 +0x258

Metadata

Metadata

Assignees

Labels

kind/bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions