@@ -107,7 +107,7 @@ func (k *kustomize) getBinaryPath() string {
107107// https://github.com/kubernetes-sigs/kustomize/commit/b214fa7d5aa51d7c2ae306ec15115bf1c044fed8#diff-0328c59bcd29799e365ff0647653b886f17c8853df008cd54e7981db882c1b36
108108func mapToEditAddArgs (val map [string ]string ) []string {
109109 var args []string
110- if getSemverSafe ().LessThan (semver .MustParse ("v3.8.5" )) {
110+ if getSemverSafe (& kustomize {} ).LessThan (semver .MustParse ("v3.8.5" )) {
111111 arg := ""
112112 for labelName , labelValue := range val {
113113 if arg != "" {
@@ -338,7 +338,7 @@ func (k *kustomize) Build(opts *v1alpha1.ApplicationSourceKustomize, kustomizeOp
338338 if len (opts .Components ) > 0 {
339339 // components only supported in kustomize >= v3.7.0
340340 // https://github.com/kubernetes-sigs/kustomize/blob/master/examples/components.md
341- if getSemverSafe ().LessThan (semver .MustParse ("v3.7.0" )) {
341+ if getSemverSafe (k ).LessThan (semver .MustParse ("v3.7.0" )) {
342342 return nil , nil , nil , errors .New ("kustomize components require kustomize v3.7.0 and above" )
343343 }
344344
@@ -374,7 +374,7 @@ func (k *kustomize) Build(opts *v1alpha1.ApplicationSourceKustomize, kustomizeOp
374374
375375 var cmd * exec.Cmd
376376 if kustomizeOptions != nil && kustomizeOptions .BuildOptions != "" {
377- params := parseKustomizeBuildOptions (k . path , kustomizeOptions .BuildOptions , buildOpts )
377+ params := parseKustomizeBuildOptions (k , kustomizeOptions .BuildOptions , buildOpts )
378378 cmd = exec .Command (k .getBinaryPath (), params ... )
379379 } else {
380380 cmd = exec .Command (k .getBinaryPath (), "build" , k .path )
@@ -401,10 +401,10 @@ func (k *kustomize) Build(opts *v1alpha1.ApplicationSourceKustomize, kustomizeOp
401401 return objs , getImageParameters (objs ), redactedCommands , nil
402402}
403403
404- func parseKustomizeBuildOptions (path string , buildOptions string , buildOpts * BuildOpts ) []string {
405- buildOptsParams := append ([]string {"build" , path }, strings .Fields (buildOptions )... )
404+ func parseKustomizeBuildOptions (k * kustomize , buildOptions string , buildOpts * BuildOpts ) []string {
405+ buildOptsParams := append ([]string {"build" , k . path }, strings .Fields (buildOptions )... )
406406
407- if buildOpts != nil && ! getSemverSafe ().LessThan (semver .MustParse ("v5.3.0" )) && isHelmEnabled (buildOptions ) {
407+ if buildOpts != nil && ! getSemverSafe (k ).LessThan (semver .MustParse ("v5.3.0" )) && isHelmEnabled (buildOptions ) {
408408 if buildOpts .KubeVersion != "" {
409409 buildOptsParams = append (buildOptsParams , "--helm-kube-version" , buildOpts .KubeVersion )
410410 }
@@ -435,8 +435,8 @@ var (
435435)
436436
437437// getSemver returns parsed kustomize version
438- func getSemver () (* semver.Version , error ) {
439- verStr , err := Version ( )
438+ func getSemver (k * kustomize ) (* semver.Version , error ) {
439+ verStr , err := versionWithBinaryPath ( k )
440440 if err != nil {
441441 return nil , err
442442 }
@@ -452,12 +452,12 @@ func getSemver() (*semver.Version, error) {
452452// getSemverSafe returns parsed kustomize version;
453453// if version cannot be parsed assumes that "kustomize version" output format changed again
454454// and fallback to latest ( v99.99.99 )
455- func getSemverSafe () * semver.Version {
455+ func getSemverSafe (k * kustomize ) * semver.Version {
456456 if semVer == nil {
457457 semVerLock .Lock ()
458458 defer semVerLock .Unlock ()
459459
460- if ver , err := getSemver (); err != nil {
460+ if ver , err := getSemver (k ); err != nil {
461461 semVer = unknownVersion
462462 log .Warnf ("Failed to parse kustomize version: %v" , err )
463463 } else {
@@ -468,7 +468,12 @@ func getSemverSafe() *semver.Version {
468468}
469469
470470func Version () (string , error ) {
471- cmd := exec .Command ("kustomize" , "version" , "--short" )
471+ return versionWithBinaryPath (& kustomize {})
472+ }
473+
474+ func versionWithBinaryPath (k * kustomize ) (string , error ) {
475+ executable := k .getBinaryPath ()
476+ cmd := exec .Command (executable , "version" , "--short" )
472477 // example version output:
473478 // short: "{kustomize/v3.8.1 2020-07-16T00:58:46Z }"
474479 version , err := executil .Run (cmd )
0 commit comments