@@ -65,6 +65,7 @@ type Deployer struct {
65
65
insecureRegistries map [string ]bool
66
66
labels map [string ]string
67
67
globalConfig string
68
+ hasKustomization func (string ) bool
68
69
}
69
70
70
71
// NewDeployer generates a new Deployer object contains the kptDeploy schema.
@@ -74,6 +75,7 @@ func NewDeployer(cfg types.Config, labels map[string]string, d *latestV1.KptDepl
74
75
insecureRegistries : cfg .GetInsecureRegistries (),
75
76
labels : labels ,
76
77
globalConfig : cfg .GlobalConfig (),
78
+ hasKustomization : hasKustomization ,
77
79
}
78
80
}
79
81
@@ -101,8 +103,7 @@ func versionCheck(dir string, stdout io.Writer) error {
101
103
102
104
// Users can choose not to use kustomize in kpt deployer mode. We only check the kustomize
103
105
// version when kustomization.yaml config is directed under .deploy.kpt.dir path.
104
- _ , err = kustomize .FindKustomizationConfig (dir )
105
- if err == nil {
106
+ if hasKustomization (dir ) {
106
107
kustomizeCmd := exec .Command ("kustomize" , "version" )
107
108
out , err := util .RunCmdOut (kustomizeCmd )
108
109
if err != nil {
@@ -272,8 +273,6 @@ func (k *Deployer) renderManifests(ctx context.Context, builds []graph.Artifact)
272
273
// Note: kustomize cannot be used as a kpt fn yet and thus we run kustomize in a temp dir
273
274
// in the kpt pipeline:
274
275
// kpt source --> kpt run --> (workaround if kustomization exists) kustomize build --> kpt sink.
275
- // Once the unified kpt/kustomize is done, kustomize can be run as a kpt fn step and
276
- // this additional directory creation/deletion will no longer be needed.
277
276
//
278
277
// Note: Optimally the user would be able to control the order in which kpt functions and
279
278
// Kustomize build happens, and even have Kustomize build happen between Kpt fn invocations.
@@ -304,7 +303,7 @@ func (k *Deployer) renderManifests(ctx context.Context, builds []graph.Artifact)
304
303
}
305
304
306
305
// Only run kustomize if kustomization.yaml is found in the output from the kpt functions.
307
- if _ , err = kustomize . FindKustomizationConfig (tmpKustomizeDir ); err == nil {
306
+ if k . hasKustomization (tmpKustomizeDir ) {
308
307
cmd = exec .CommandContext (ctx , "kustomize" , append ([]string {"build" }, tmpKustomizeDir )... )
309
308
if buf , err = util .RunCmdOut (cmd ); err != nil {
310
309
return nil , fmt .Errorf ("kustomize build: %w" , err )
@@ -551,3 +550,8 @@ func (k *Deployer) getKptLiveInitArgs() []string {
551
550
552
551
return flags
553
552
}
553
+
554
+ func hasKustomization (dir string ) bool {
555
+ _ , err := kustomize .FindKustomizationConfig (dir )
556
+ return err == nil
557
+ }
0 commit comments