Skip to content
Open
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
20 changes: 18 additions & 2 deletions reposerver/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,15 @@ func GenerateManifests(ctx context.Context, appPath, repoRoot, revision string,
return nil, fmt.Errorf("could not parse kubernetes version %s: %w", q.ApplicationSource.GetKubeVersionOrDefault(q.KubeVersion), err)
}
k := kustomize.NewKustomizeApp(repoRoot, appPath, q.Repo.GetGitCreds(gitCredsStore), repoURL, kustomizeBinary, q.Repo.Proxy, q.Repo.NoProxy)
targetObjs, _, commands, err = k.Build(q.ApplicationSource.Kustomize, q.KustomizeOptions, env, &kustomize.BuildOpts{
kustomizeOpts := q.KustomizeOptions
if kustomizeOpts != nil {
if effectiveBuildOptions := settings.GetKustomizeBuildOptions(kustomizeOpts, *q.ApplicationSource); effectiveBuildOptions != kustomizeOpts.BuildOptions {
optsCopy := *kustomizeOpts
optsCopy.BuildOptions = effectiveBuildOptions
kustomizeOpts = &optsCopy
}
}
Comment on lines +1716 to +1723
targetObjs, _, commands, err = k.Build(q.ApplicationSource.Kustomize, kustomizeOpts, env, &kustomize.BuildOpts{
KubeVersion: kubeVersion,
APIVersions: q.ApplicationSource.GetAPIVersionsOrDefault(q.ApiVersions),
})
Expand Down Expand Up @@ -2582,7 +2590,15 @@ func populateKustomizeAppDetails(res *apiclient.RepoAppDetailsResponse, q *apicl
ApplicationSource: q.Source,
}
env := newEnv(&fakeManifestRequest, reversion)
_, images, _, err := k.Build(q.Source.Kustomize, q.KustomizeOptions, env, nil)
kustomizeOpts := q.KustomizeOptions
if kustomizeOpts != nil {
if effectiveBuildOptions := settings.GetKustomizeBuildOptions(kustomizeOpts, *q.Source); effectiveBuildOptions != kustomizeOpts.BuildOptions {
optsCopy := *kustomizeOpts
optsCopy.BuildOptions = effectiveBuildOptions
kustomizeOpts = &optsCopy
}
}
_, images, _, err := k.Build(q.Source.Kustomize, kustomizeOpts, env, nil)
Comment on lines +2593 to +2601
if err != nil {
return err
}
Expand Down
17 changes: 17 additions & 0 deletions util/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,23 @@ func GetKustomizeBinaryPath(ks *v1alpha1.KustomizeOptions, source v1alpha1.Appli
return "", nil
}

// GetKustomizeBuildOptions returns the build options for the kustomize invocation based on the provided KustomizeOptions
// and ApplicationSource. If the source requests a specific kustomize version and that version defines per-version build
// options, those are returned. Otherwise, the global build options are returned.
func GetKustomizeBuildOptions(ks *v1alpha1.KustomizeOptions, source v1alpha1.ApplicationSource) string {
if ks == nil {
return ""
}
if source.Kustomize != nil && source.Kustomize.Version != "" {
for _, ver := range ks.Versions {
if ver.Name == source.Kustomize.Version && ver.BuildOptions != "" {
return ver.BuildOptions
}
}
}
return ks.BuildOptions
}

// Credentials for accessing a Git repository
type Repository struct {
// The URL to the repository
Expand Down
44 changes: 44 additions & 0 deletions util/settings/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,50 @@ func Test_GetKustomizeBinaryPath(t *testing.T) {
})
}

func Test_GetKustomizeBuildOptions(t *testing.T) {
ko := &v1alpha1.KustomizeOptions{
BuildOptions: "--opt1 val1",
Versions: []v1alpha1.KustomizeVersion{
{Name: "v1", Path: "path_v1"},
{Name: "v2", Path: "path_v2", BuildOptions: "--opt2 val2"},
{Name: "v3", Path: "path_v3", BuildOptions: "--opt3 val3"},
},
}

t.Run("NilOptions", func(t *testing.T) {
result := GetKustomizeBuildOptions(nil, v1alpha1.ApplicationSource{})
assert.Empty(t, result)
})

t.Run("NoVersionRequested", func(t *testing.T) {
result := GetKustomizeBuildOptions(ko, v1alpha1.ApplicationSource{})
assert.Equal(t, "--opt1 val1", result)
})

t.Run("VersionWithBuildOptions", func(t *testing.T) {
result := GetKustomizeBuildOptions(ko, v1alpha1.ApplicationSource{
Kustomize: &v1alpha1.ApplicationSourceKustomize{Version: "v2"},
})
assert.Equal(t, "--opt2 val2", result)
})

t.Run("VersionWithoutBuildOptions", func(t *testing.T) {
// v1 has no BuildOptions — should fall back to global
result := GetKustomizeBuildOptions(ko, v1alpha1.ApplicationSource{
Kustomize: &v1alpha1.ApplicationSourceKustomize{Version: "v1"},
})
assert.Equal(t, "--opt1 val1", result)
})

t.Run("UnknownVersion", func(t *testing.T) {
// unregistered version — falls back to global
result := GetKustomizeBuildOptions(ko, v1alpha1.ApplicationSource{
Kustomize: &v1alpha1.ApplicationSourceKustomize{Version: "v99"},
})
assert.Equal(t, "--opt1 val1", result)
})
}

func TestGetGoogleAnalytics(t *testing.T) {
_, settingsManager := fixtures(t.Context(), map[string]string{
"ga.trackingid": "123",
Expand Down
Loading