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

Panic while parsing Git repository URL from Bitbucket #4011

Closed
patrick246 opened this issue Jun 23, 2021 · 0 comments · Fixed by #4039
Closed

Panic while parsing Git repository URL from Bitbucket #4011

patrick246 opened this issue Jun 23, 2021 · 0 comments · Fixed by #4039
Labels
area/api issues for api module help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@patrick246
Copy link

Describe the bug

When specifying a Bitbucket repository HTTPS URL as a resource, there is a panic in api/internal/git/repospec.go:128

if n[0] == '/' {

n is empty while parsing the URL below, therefore it panics when accessing n[0]. This happens in general, when the repository URL ends in .git.

Files that can reproduce the issue
kustomization.yaml

resources:
 - https://bitbucket.example.com/scm/project/repository.git

Expected output
Resources from that repository, or an error message related to the repository not existing.

Actual output

panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
sigs.k8s.io/kustomize/api/internal/git.parseGitUrl(0xc000329380, 0x3d, 0x1, 0x1db0e00, 0xc00033fb80, 0x20, 0x1b74a40, 0x0, 0xc00033fb60, 0xc00029f358, ...)
	/go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/git/repospec.go:128 +0x7f7
sigs.k8s.io/kustomize/api/internal/git.NewRepoSpecFromUrl(0xc000329380, 0x3d, 0x15ad005, 0x17c4580, 0xc0003495f0)
	/go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/git/repospec.go:89 +0x6a
sigs.k8s.io/kustomize/api/loader.(*fileLoader).New(0xc00035c0f0, 0xc000329380, 0x3d, 0x3d, 0x17c4680, 0xc00033fb80, 0x203000)
	/go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/loader/fileloader.go:174 +0x5f
sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateResources(0xc0002ff340, 0xc00033fb00, 0xc0002ff740, 0x1, 0x4, 0x1b74a40, 0x0, 0xc00029f568)
	/go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/target/kusttarget.go:339 +0x144
sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateTarget(0xc0002ff340, 0xc00033fb00, 0xc00029f600, 0x1431b53, 0x0)
	/go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/target/kusttarget.go:163 +0x74
sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).AccumulateTarget(0xc0002ff340, 0x0, 0xffffffffffffffff, 0x0)
	/go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/target/kusttarget.go:156 +0xce
sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).makeCustomizedResMap(0xc0002ff340, 0x0, 0x0, 0x0, 0x1)
	/go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/target/kusttarget.go:111 +0x2f
sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).MakeCustomizedResMap(...)
	/go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/target/kusttarget.go:107
sigs.k8s.io/kustomize/api/krusty.(*Kustomizer).Run(0xc00029fd50, 0x17defa0, 0x1ba5708, 0x7ffeefbff578, 0x1, 0x0, 0x0, 0x0, 0x0)
	/go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/krusty/kustomizer.go:88 +0x3db
sigs.k8s.io/kustomize/kustomize/v4/commands/build.NewCmdBuild.func1(0xc00032a000, 0xc0003485b0, 0x1, 0x1, 0x0, 0x0)
	/workspace/myClone/kustomize/commands/build/build.go:80 +0x1c8
github.com/spf13/cobra.(*Command).execute(0xc00032a000, 0xc000348580, 0x1, 0x1, 0xc00032a000, 0xc000348580)
	/go/pkg/mod/github.com/spf13/[email protected]/command.go:842 +0x47c
github.com/spf13/cobra.(*Command).ExecuteC(0xc00015f8c0, 0x0, 0x1619a40, 0xc00008c058)
	/go/pkg/mod/github.com/spf13/[email protected]/command.go:950 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
	/go/pkg/mod/github.com/spf13/[email protected]/command.go:887
main.main()
	/workspace/myClone/kustomize/main.go:14 +0x2a

Kustomize version
{Version:kustomize/v4.1.3 GitCommit:0f614e92f72f1b938a9171b964d90b197ca8fb68 BuildDate:2021-05-20T20:52:40Z GoOs:darwin GoArch:amd64}

Platform
MacOS 10.15.7

Additional context
Working around this bug is possible, by leaving out the .git at the end, or if not possible, specifying ?ref=master. That should not change the behavior, but it gives the parser something to parse, so the n[0] access is possible.

@patrick246 patrick246 added the kind/bug Categorizes issue or PR as related to a bug. label Jun 23, 2021
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Jun 23, 2021
@natasha41575 natasha41575 added the triage/accepted Indicates an issue or PR is ready to be actively worked on. label Jun 23, 2021
@k8s-ci-robot k8s-ci-robot removed the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Jun 23, 2021
@natasha41575 natasha41575 added area/api issues for api module needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 23, 2021
@natasha41575 natasha41575 added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Jul 2, 2021
zhouhaibing089 added a commit to zhouhaibing089/kustomize that referenced this issue Jul 5, 2021
This change adds a new test case for parsing url with `.git` suffix. In
that case, we should have the full url as clone spec with an empty
abspath.

This fixes kubernetes-sigs#4011.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api issues for api module help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants