Skip to content

Commit

Permalink
Adding depth in case of git config in fetch section of app/package
Browse files Browse the repository at this point in the history
Signed-off-by: Rohit Aggarwal <rohit.aggarwal@broadcom.com>
  • Loading branch information
rohitagg2020 committed Oct 8, 2024
1 parent 68347a9 commit eb3c198
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 154 deletions.
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
}
2 changes: 2 additions & 0 deletions test/e2e/kappcontroller/packageinstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,13 +624,15 @@ spec:
}

tmpl := cr.Spec.Template[0]

if tmpl.Ytt != nil && len(tmpl.Ytt.Paths) != 0 {
if tmpl.Ytt.Paths[0] != "file.yml" {
t.Fatalf("\nExpected App spec.template.ytt.paths to contain file.yml\nGot: %s", tmpl.Ytt.Paths[0])
}
} else {
t.Fatalf("\nExpected App spec.template.ytt.paths to contain file.yml\nGot: %s", tmpl)
}

})

logger.Section("Delete PackageInstall and expect App with same name to be deleted", func() {
Expand Down

0 comments on commit eb3c198

Please sign in to comment.