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

fix(kustomize): set build dir (#15057) #16229

Closed
Closed
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
8 changes: 4 additions & 4 deletions reposerver/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ func GenerateManifests(ctx context.Context, appPath, repoRoot, revision string,
if q.KustomizeOptions != nil {
kustomizeBinary = q.KustomizeOptions.BinaryPath
}
k := kustomize.NewKustomizeApp(appPath, q.Repo.GetGitCreds(gitCredsStore), repoURL, kustomizeBinary)
k := kustomize.NewKustomizeApp(repoRoot, appPath, q.Repo.GetGitCreds(gitCredsStore), repoURL, kustomizeBinary)
targetObjs, _, err = k.Build(q.ApplicationSource.Kustomize, q.KustomizeOptions, env)
case v1alpha1.ApplicationSourceTypePlugin:
pluginName := ""
Expand Down Expand Up @@ -1976,7 +1976,7 @@ func (s *Service) GetAppDetails(ctx context.Context, q *apiclient.RepoServerAppD
return err
}
case v1alpha1.ApplicationSourceTypeKustomize:
if err := populateKustomizeAppDetails(res, q, opContext.appPath, commitSHA, s.gitCredsStore); err != nil {
if err := populateKustomizeAppDetails(res, q, repoRoot, opContext.appPath, commitSHA, s.gitCredsStore); err != nil {
return err
}
case v1alpha1.ApplicationSourceTypePlugin:
Expand Down Expand Up @@ -2117,13 +2117,13 @@ func walkHelmValueFilesInPath(root string, valueFiles *[]string) filepath.WalkFu
}
}

func populateKustomizeAppDetails(res *apiclient.RepoAppDetailsResponse, q *apiclient.RepoServerAppDetailsQuery, appPath string, reversion string, credsStore git.CredsStore) error {
func populateKustomizeAppDetails(res *apiclient.RepoAppDetailsResponse, q *apiclient.RepoServerAppDetailsQuery, repoRoot string, appPath string, reversion string, credsStore git.CredsStore) error {
res.Kustomize = &apiclient.KustomizeAppSpec{}
kustomizeBinary := ""
if q.KustomizeOptions != nil {
kustomizeBinary = q.KustomizeOptions.BinaryPath
}
k := kustomize.NewKustomizeApp(appPath, q.Repo.GetGitCreds(credsStore), q.Repo.Repo, kustomizeBinary)
k := kustomize.NewKustomizeApp(repoRoot, appPath, q.Repo.GetGitCreds(credsStore), q.Repo.Repo, kustomizeBinary)
fakeManifestRequest := apiclient.ManifestRequest{
AppName: q.AppName,
Namespace: "", // FIXME: omit it for now
Expand Down
6 changes: 5 additions & 1 deletion util/kustomize/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ type Kustomize interface {
}

// NewKustomizeApp create a new wrapper to run commands on the `kustomize` command-line tool.
func NewKustomizeApp(path string, creds git.Creds, fromRepo string, binaryPath string) Kustomize {
func NewKustomizeApp(repoRoot string, path string, creds git.Creds, fromRepo string, binaryPath string) Kustomize {
return &kustomize{
repoRoot: repoRoot,
path: path,
creds: creds,
repo: fromRepo,
Expand All @@ -45,6 +46,8 @@ func NewKustomizeApp(path string, creds git.Creds, fromRepo string, binaryPath s
}

type kustomize struct {
// path to the Git repository root
repoRoot string
// path inside the checked out tree
path string
// creds structure
Expand Down Expand Up @@ -301,6 +304,7 @@ func (k *kustomize) Build(opts *v1alpha1.ApplicationSourceKustomize, kustomizeOp
cmd = exec.Command(k.getBinaryPath(), "build", k.path)
}
cmd.Env = env
cmd.Dir = k.repoRoot
out, err := executil.Run(cmd)
if err != nil {
return nil, nil, err
Expand Down
12 changes: 6 additions & 6 deletions util/kustomize/kustomize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
namePrefix := "namePrefix-"
nameSuffix := "-nameSuffix"
namespace := "custom-namespace"
kustomize := NewKustomizeApp(appPath, git.NopCreds{}, "", "")
kustomize := NewKustomizeApp(appPath, appPath, git.NopCreds{}, "", "")
env := &v1alpha1.Env{
&v1alpha1.EnvEntry{Name: "ARGOCD_APP_NAME", Value: "argo-cd-tests"},
}
Expand Down Expand Up @@ -123,7 +123,7 @@
func TestFailKustomizeBuild(t *testing.T) {
appPath, err := testDataDir(t, kustomization1)
assert.Nil(t, err)
kustomize := NewKustomizeApp(appPath, git.NopCreds{}, "", "")
kustomize := NewKustomizeApp(appPath, appPath, git.NopCreds{}, "", "")
kustomizeSource := v1alpha1.ApplicationSourceKustomize{
Replicas: []v1alpha1.KustomizeReplica{
{
Expand Down Expand Up @@ -222,7 +222,7 @@
for _, tc := range testCases {
appPath, err := testDataDir(t, tc.TestData)
assert.Nil(t, err)
kustomize := NewKustomizeApp(appPath, git.NopCreds{}, "", "")
kustomize := NewKustomizeApp(appPath, appPath, git.NopCreds{}, "", "")
objs, _, err := kustomize.Build(&tc.KustomizeSource, nil, tc.Env)
switch tc.ExpectErr {
case true:
Expand Down Expand Up @@ -314,7 +314,7 @@
for _, tc := range testCases {
appPath, err := testDataDir(t, tc.TestData)
assert.Nil(t, err)
kustomize := NewKustomizeApp(appPath, git.NopCreds{}, "", "")
kustomize := NewKustomizeApp(appPath, appPath, git.NopCreds{}, "", "")
objs, _, err := kustomize.Build(&tc.KustomizeSource, nil, tc.Env)
switch tc.ExpectErr {
case true:
Expand All @@ -334,7 +334,7 @@
kustomizePath, err := testDataDir(t, kustomization4)
assert.Nil(t, err)
envOutputFile := kustomizePath + "/env_output"
kustomize := NewKustomizeApp(appPath, git.NopCreds{}, "", kustomizePath+"/kustomize.special")
kustomize := NewKustomizeApp(appPath, appPath, git.NopCreds{}, "", kustomizePath+"/kustomize.special")
kustomizeSource := v1alpha1.ApplicationSourceKustomize{
Version: "special",
}
Expand All @@ -356,7 +356,7 @@
func TestKustomizeBuildComponents(t *testing.T) {
appPath, err := testDataDir(t, kustomization6)
assert.Nil(t, err)
kustomize := NewKustomizeApp(appPath, git.NopCreds{}, "", "")

Check failure on line 359 in util/kustomize/kustomize_test.go

View workflow job for this annotation

GitHub Actions / Run unit tests with -race for Go packages

not enough arguments in call to NewKustomizeApp

Check failure on line 359 in util/kustomize/kustomize_test.go

View workflow job for this annotation

GitHub Actions / Run unit tests with -race for Go packages

not enough arguments in call to NewKustomizeApp

Check failure on line 359 in util/kustomize/kustomize_test.go

View workflow job for this annotation

GitHub Actions / Run unit tests for Go packages

not enough arguments in call to NewKustomizeApp

Check failure on line 359 in util/kustomize/kustomize_test.go

View workflow job for this annotation

GitHub Actions / Run unit tests for Go packages

not enough arguments in call to NewKustomizeApp

kustomizeSource := v1alpha1.ApplicationSourceKustomize{
Components: []string{"./components"},
Expand All @@ -377,7 +377,7 @@
func TestKustomizeBuildPatches(t *testing.T) {
appPath, err := testDataDir(t, kustomization5)
assert.Nil(t, err)
kustomize := NewKustomizeApp(appPath, git.NopCreds{}, "", "")
kustomize := NewKustomizeApp(appPath, appPath, git.NopCreds{}, "", "")

kustomizeSource := v1alpha1.ApplicationSourceKustomize{
Patches: []v1alpha1.KustomizePatch{
Expand Down
Loading