Skip to content

Commit 0c1ba92

Browse files
author
Mattias Öhrn
committed
Fixing tests and comments
1 parent 449fa84 commit 0c1ba92

File tree

2 files changed

+101
-77
lines changed

2 files changed

+101
-77
lines changed

pkg/skaffold/deploy/kpt/kpt.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type Deployer struct {
6565
insecureRegistries map[string]bool
6666
labels map[string]string
6767
globalConfig string
68+
hasKustomization func(string) bool
6869
}
6970

7071
// 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
7475
insecureRegistries: cfg.GetInsecureRegistries(),
7576
labels: labels,
7677
globalConfig: cfg.GlobalConfig(),
78+
hasKustomization: hasKustomization,
7779
}
7880
}
7981

@@ -101,8 +103,7 @@ func versionCheck(dir string, stdout io.Writer) error {
101103

102104
// Users can choose not to use kustomize in kpt deployer mode. We only check the kustomize
103105
// 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) {
106107
kustomizeCmd := exec.Command("kustomize", "version")
107108
out, err := util.RunCmdOut(kustomizeCmd)
108109
if err != nil {
@@ -272,8 +273,6 @@ func (k *Deployer) renderManifests(ctx context.Context, builds []graph.Artifact)
272273
// Note: kustomize cannot be used as a kpt fn yet and thus we run kustomize in a temp dir
273274
// in the kpt pipeline:
274275
// 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.
277276
//
278277
// Note: Optimally the user would be able to control the order in which kpt functions and
279278
// 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)
304303
}
305304

306305
// 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) {
308307
cmd = exec.CommandContext(ctx, "kustomize", append([]string{"build"}, tmpKustomizeDir)...)
309308
if buf, err = util.RunCmdOut(cmd); err != nil {
310309
return nil, fmt.Errorf("kustomize build: %w", err)
@@ -551,3 +550,8 @@ func (k *Deployer) getKptLiveInitArgs() []string {
551550

552551
return flags
553552
}
553+
554+
func hasKustomization(dir string) bool {
555+
_, err := kustomize.FindKustomizationConfig(dir)
556+
return err == nil
557+
}

0 commit comments

Comments
 (0)