Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yangcao77 opened this issue Dec 11, 2020 · 0 comments · Fixed by #277
Closed
Assignees
Labels
kind/bug Something isn't working

Comments

@yangcao77
Copy link
Contributor

yangcao77 commented Dec 11, 2020

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant