Skip to content

Commit c6dbae6

Browse files
committed
Adding depth in case of git config in fetch section of app/package
Signed-off-by: Rohit Aggarwal <[email protected]>
1 parent 68347a9 commit c6dbae6

File tree

8 files changed

+259
-154
lines changed

8 files changed

+259
-154
lines changed

config/config/crds.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ spec:
209209
git:
210210
description: Uses git to clone repository
211211
properties:
212+
depth:
213+
description: depth of commits to fetch; 1 (default) means only latest commit, 0 means everything (optional)
214+
format: int64
215+
type: integer
212216
forceHTTPBasicAuth:
213217
description: Force the usage of HTTP Basic Auth when Basic Auth is provided (optional)
214218
type: boolean
@@ -828,6 +832,10 @@ spec:
828832
git:
829833
description: Uses git to clone repository
830834
properties:
835+
depth:
836+
description: depth of commits to fetch; 1 (default) means only latest commit, 0 means everything (optional)
837+
format: int64
838+
type: integer
831839
forceHTTPBasicAuth:
832840
description: Force the usage of HTTP Basic Auth when Basic Auth is provided (optional)
833841
type: boolean
@@ -1653,6 +1661,10 @@ spec:
16531661
git:
16541662
description: Uses git to clone repository containing package list
16551663
properties:
1664+
depth:
1665+
description: depth of commits to fetch; 1 (default) means only latest commit, 0 means everything (optional)
1666+
format: int64
1667+
type: integer
16561668
forceHTTPBasicAuth:
16571669
description: Force the usage of HTTP Basic Auth when Basic Auth is provided (optional)
16581670
type: boolean

pkg/apis/kappctrl/v1alpha1/generated.pb.go

Lines changed: 185 additions & 154 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/kappctrl/v1alpha1/generated.proto

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/kappctrl/v1alpha1/types_fetch.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ type AppFetchGit struct {
109109
// Force the usage of HTTP Basic Auth when Basic Auth is provided (optional)
110110
// +optional
111111
ForceHTTPBasicAuth bool `json:"forceHTTPBasicAuth,omitempty" protobuf:"varint,7,opt,name=forceHTTPBasicAuth"`
112+
// depth of commits to fetch; 1 (default) means only latest commit, 0 means everything (optional)
113+
// +optional
114+
Depth *int64 `json:"depth,omitempty" protobuf:"bytes,8,opt,name=depth"`
112115
}
113116

114117
// +k8s:openapi-gen=true

pkg/apis/kappctrl/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apiserver/openapi/zz_generated.openapi.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/fetch/vendir.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ func (v *Vendir) httpConf(http v1alpha1.AppFetchHTTP) vendirconf.DirectoryConten
160160
}
161161

162162
func (v *Vendir) gitConf(git v1alpha1.AppFetchGit) vendirconf.DirectoryContents {
163+
164+
// By default, we only fetch the latest commit.
165+
depth := 1
166+
if git.Depth != nil {
167+
depth = int(*(git.Depth))
168+
}
169+
163170
return vendirconf.DirectoryContents{
164171
Path: vendirEntireDirPath,
165172
NewRootPath: git.SubPath,
@@ -171,6 +178,7 @@ func (v *Vendir) gitConf(git v1alpha1.AppFetchGit) vendirconf.DirectoryContents
171178
LFSSkipSmudge: git.LFSSkipSmudge,
172179
DangerousSkipTLSVerify: v.shouldSkipTLSVerify(git.URL, GitURL),
173180
ForceHTTPBasicAuth: git.ForceHTTPBasicAuth,
181+
Depth: depth,
174182
},
175183
}
176184
}

pkg/fetch/vendir_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,38 @@ func TestExtractHost(t *testing.T) {
149149
})
150150
}
151151
}
152+
153+
func Test_GitConfig_depth(t *testing.T) {
154+
k8scs := k8sfake.NewSimpleClientset()
155+
config, err := kcconfig.NewConfig(k8scs)
156+
assert.NoError(t, err)
157+
158+
vendir := fetch.NewVendir("default", k8scs,
159+
fetch.VendirOpts{SkipTLSConfig: config}, exec.NewPlainCmdRunner())
160+
161+
type testCase struct {
162+
URL string
163+
Depth *int64
164+
ExpectedDepth int
165+
}
166+
testCases := []testCase{
167+
{"https://github.com/bitnami/charts/", convertToInt64(1), 1},
168+
{"https://gitlab.com/bitnami/charts/", convertToInt64(0), 0},
169+
{"https://gitlab.com/bitnami/charts/", nil, 1},
170+
}
171+
for i, tc := range testCases {
172+
err = vendir.AddDir(v1alpha1.AppFetch{
173+
Git: &v1alpha1.AppFetchGit{URL: tc.URL, Depth: tc.Depth},
174+
},
175+
"dirpath/0")
176+
assert.NoError(t, err)
177+
178+
vConf := vendir.Config()
179+
assert.Equal(t, i+1, len(vConf.Directories), "Failed on iteration %d", i)
180+
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)
181+
}
182+
}
183+
184+
func convertToInt64(x int64) *int64 {
185+
return &x
186+
}

0 commit comments

Comments
 (0)