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

Adding depth in case of git config in fetch section of app/package #1633

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config/config/crds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ spec:
git:
description: Uses git to clone repository
properties:
depth:
description: depth of commits to fetch; 1 (default) means only latest commit, 0 means everything (optional)
format: int64
type: integer
forceHTTPBasicAuth:
description: Force the usage of HTTP Basic Auth when Basic Auth is provided (optional)
type: boolean
Expand Down Expand Up @@ -828,6 +832,10 @@ spec:
git:
description: Uses git to clone repository
properties:
depth:
description: depth of commits to fetch; 1 (default) means only latest commit, 0 means everything (optional)
format: int64
type: integer
forceHTTPBasicAuth:
description: Force the usage of HTTP Basic Auth when Basic Auth is provided (optional)
type: boolean
Expand Down Expand Up @@ -1653,6 +1661,10 @@ spec:
git:
description: Uses git to clone repository containing package list
properties:
depth:
description: depth of commits to fetch; 1 (default) means only latest commit, 0 means everything (optional)
format: int64
type: integer
forceHTTPBasicAuth:
description: Force the usage of HTTP Basic Auth when Basic Auth is provided (optional)
type: boolean
Expand Down
339 changes: 185 additions & 154 deletions pkg/apis/kappctrl/v1alpha1/generated.pb.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pkg/apis/kappctrl/v1alpha1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/apis/kappctrl/v1alpha1/types_fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ type AppFetchGit struct {
// Force the usage of HTTP Basic Auth when Basic Auth is provided (optional)
// +optional
ForceHTTPBasicAuth bool `json:"forceHTTPBasicAuth,omitempty" protobuf:"varint,7,opt,name=forceHTTPBasicAuth"`
// depth of commits to fetch; 1 (default) means only latest commit, 0 means everything (optional)
// +optional
Depth *int64 `json:"depth,omitempty" protobuf:"bytes,8,opt,name=depth"`
}

// +k8s:openapi-gen=true
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/kappctrl/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/apiserver/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions pkg/fetch/vendir.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ func (v *Vendir) httpConf(http v1alpha1.AppFetchHTTP) vendirconf.DirectoryConten
}

func (v *Vendir) gitConf(git v1alpha1.AppFetchGit) vendirconf.DirectoryContents {

// By default, we only fetch the latest commit.
depth := 1
if git.Depth != nil {
depth = int(*(git.Depth))
}

return vendirconf.DirectoryContents{
Path: vendirEntireDirPath,
NewRootPath: git.SubPath,
Expand All @@ -171,6 +178,7 @@ func (v *Vendir) gitConf(git v1alpha1.AppFetchGit) vendirconf.DirectoryContents
LFSSkipSmudge: git.LFSSkipSmudge,
DangerousSkipTLSVerify: v.shouldSkipTLSVerify(git.URL, GitURL),
ForceHTTPBasicAuth: git.ForceHTTPBasicAuth,
Depth: depth,
},
}
}
Expand Down
35 changes: 35 additions & 0 deletions pkg/fetch/vendir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,38 @@ func TestExtractHost(t *testing.T) {
})
}
}

func Test_GitConfig_depth(t *testing.T) {
k8scs := k8sfake.NewSimpleClientset()
config, err := kcconfig.NewConfig(k8scs)
assert.NoError(t, err)

vendir := fetch.NewVendir("default", k8scs,
fetch.VendirOpts{SkipTLSConfig: config}, exec.NewPlainCmdRunner())

type testCase struct {
URL string
Depth *int64
ExpectedDepth int
}
testCases := []testCase{
{"https://github.com/bitnami/charts/", convertToInt64(1), 1},
{"https://gitlab.com/bitnami/charts/", convertToInt64(0), 0},
{"https://gitlab.com/bitnami/charts/", nil, 1},
}
for i, tc := range testCases {
err = vendir.AddDir(v1alpha1.AppFetch{
Git: &v1alpha1.AppFetchGit{URL: tc.URL, Depth: tc.Depth},
},
"dirpath/0")
assert.NoError(t, err)

vConf := vendir.Config()
assert.Equal(t, i+1, len(vConf.Directories), "Failed on iteration %d", i)
assert.Equal(t, tc.ExpectedDepth, vConf.Directories[i].Contents[0].Git.Depth, "Expected depth: %d, Got: %d", tc.ExpectedDepth, vConf.Directories[i].Contents[0].Git.Depth)
}
}

func convertToInt64(x int64) *int64 {
return &x
}
Loading