Skip to content

Commit 7b25d00

Browse files
author
Mattias Öhrn
committed
Fixing tests and comments
1 parent 5eeae9d commit 7b25d00

File tree

2 files changed

+105
-79
lines changed

2 files changed

+105
-79
lines changed

pkg/skaffold/deploy/kpt/kpt.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ type Deployer struct {
6666
insecureRegistries map[string]bool
6767
labels map[string]string
6868
globalConfig string
69+
hasKustomization func(string) bool
6970
kubeContext string
7071
kubeConfig string
7172
namespace string
@@ -82,6 +83,7 @@ func NewDeployer(cfg Config, labels map[string]string, d *latestV1.KptDeploy) *D
8283
insecureRegistries: cfg.GetInsecureRegistries(),
8384
labels: labels,
8485
globalConfig: cfg.GlobalConfig(),
86+
hasKustomization: hasKustomization,
8587
kubeContext: cfg.GetKubeContext(),
8688
kubeConfig: cfg.GetKubeConfig(),
8789
namespace: cfg.GetKubeNamespace(),
@@ -112,8 +114,7 @@ func versionCheck(dir string, stdout io.Writer) error {
112114

113115
// Users can choose not to use kustomize in kpt deployer mode. We only check the kustomize
114116
// version when kustomization.yaml config is directed under .deploy.kpt.dir path.
115-
_, err = kustomize.FindKustomizationConfig(dir)
116-
if err == nil {
117+
if hasKustomization(dir) {
117118
kustomizeCmd := exec.Command("kustomize", "version")
118119
out, err := util.RunCmdOut(kustomizeCmd)
119120
if err != nil {
@@ -320,8 +321,6 @@ func (k *Deployer) renderManifests(ctx context.Context, builds []graph.Artifact)
320321
// Note: kustomize cannot be used as a kpt fn yet and thus we run kustomize in a temp dir
321322
// in the kpt pipeline:
322323
// kpt source --> kpt run --> (workaround if kustomization exists) kustomize build --> kpt sink.
323-
// Once the unified kpt/kustomize is done, kustomize can be run as a kpt fn step and
324-
// this additional directory creation/deletion will no longer be needed.
325324
//
326325
// Note: Optimally the user would be able to control the order in which kpt functions and
327326
// Kustomize build happens, and even have Kustomize build happen between Kpt fn invocations.
@@ -352,7 +351,7 @@ func (k *Deployer) renderManifests(ctx context.Context, builds []graph.Artifact)
352351
}
353352

354353
// Only run kustomize if kustomization.yaml is found in the output from the kpt functions.
355-
if _, err = kustomize.FindKustomizationConfig(tmpKustomizeDir); err == nil {
354+
if k.hasKustomization(tmpKustomizeDir) {
356355
cmd = exec.CommandContext(ctx, "kustomize", append([]string{"build"}, tmpKustomizeDir)...)
357356
if buf, err = util.RunCmdOut(cmd); err != nil {
358357
return nil, fmt.Errorf("kustomize build: %w", err)
@@ -615,3 +614,8 @@ func (k *Deployer) getGlobalFlags() []string {
615614

616615
return flags
617616
}
617+
618+
func hasKustomization(dir string) bool {
619+
_, err := kustomize.FindKustomizationConfig(dir)
620+
return err == nil
621+
}

0 commit comments

Comments
 (0)