@@ -66,6 +66,7 @@ type Deployer struct {
66
66
insecureRegistries map [string ]bool
67
67
labels map [string ]string
68
68
globalConfig string
69
+ hasKustomization func (string ) bool
69
70
kubeContext string
70
71
kubeConfig string
71
72
namespace string
@@ -82,6 +83,7 @@ func NewDeployer(cfg Config, labels map[string]string, d *latestV1.KptDeploy) *D
82
83
insecureRegistries : cfg .GetInsecureRegistries (),
83
84
labels : labels ,
84
85
globalConfig : cfg .GlobalConfig (),
86
+ hasKustomization : hasKustomization ,
85
87
kubeContext : cfg .GetKubeContext (),
86
88
kubeConfig : cfg .GetKubeConfig (),
87
89
namespace : cfg .GetKubeNamespace (),
@@ -112,8 +114,7 @@ func versionCheck(dir string, stdout io.Writer) error {
112
114
113
115
// Users can choose not to use kustomize in kpt deployer mode. We only check the kustomize
114
116
// 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 ) {
117
118
kustomizeCmd := exec .Command ("kustomize" , "version" )
118
119
out , err := util .RunCmdOut (kustomizeCmd )
119
120
if err != nil {
@@ -320,8 +321,6 @@ func (k *Deployer) renderManifests(ctx context.Context, builds []graph.Artifact)
320
321
// Note: kustomize cannot be used as a kpt fn yet and thus we run kustomize in a temp dir
321
322
// in the kpt pipeline:
322
323
// 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.
325
324
//
326
325
// Note: Optimally the user would be able to control the order in which kpt functions and
327
326
// 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)
352
351
}
353
352
354
353
// 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 ) {
356
355
cmd = exec .CommandContext (ctx , "kustomize" , append ([]string {"build" }, tmpKustomizeDir )... )
357
356
if buf , err = util .RunCmdOut (cmd ); err != nil {
358
357
return nil , fmt .Errorf ("kustomize build: %w" , err )
@@ -615,3 +614,8 @@ func (k *Deployer) getGlobalFlags() []string {
615
614
616
615
return flags
617
616
}
617
+
618
+ func hasKustomization (dir string ) bool {
619
+ _ , err := kustomize .FindKustomizationConfig (dir )
620
+ return err == nil
621
+ }
0 commit comments