Skip to content

Commit 93d81cb

Browse files
committed
Propagate useIsolatedEnv through to cpi_cmd_runner.go;
1 parent 035c1f8 commit 93d81cb

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

cloud/cpi_cmd_runner.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"fmt"
77
"os"
8-
"strconv"
98

109
bosherr "github.com/cloudfoundry/bosh-utils/errors"
1110
boshlog "github.com/cloudfoundry/bosh-utils/logger"
@@ -68,21 +67,24 @@ type CPICmdRunner interface {
6867

6968
type cpiCmdRunner struct {
7069
cmdRunner boshsys.CmdRunner
71-
cpi CPI
72-
logger boshlog.Logger
73-
logTag string
70+
cpi CPI
71+
logger boshlog.Logger
72+
logTag string
73+
useIsolatedEnv bool
7474
}
7575

7676
func NewCPICmdRunner(
7777
cmdRunner boshsys.CmdRunner,
7878
cpi CPI,
7979
logger boshlog.Logger,
80+
useIsolatedEnv bool,
8081
) CPICmdRunner {
8182
return &cpiCmdRunner{
8283
cmdRunner: cmdRunner,
8384
cpi: cpi,
8485
logger: logger,
8586
logTag: "cpiCmdRunner",
87+
useIsolatedEnv: useIsolatedEnv,
8688
}
8789
}
8890

@@ -100,14 +102,6 @@ func (r *cpiCmdRunner) Run(context CmdContext, method string, apiVersion int, ar
100102
if err != nil {
101103
return CmdOutput{}, bosherr.WrapErrorf(err, "Marshalling external CPI command input %#v", cmdInput)
102104
}
103-
useIsolatedEnv := true
104-
value, present := os.LookupEnv("BOSH_CPI_USE_ISOLATED_ENV")
105-
if present {
106-
useIsolatedEnv, err = strconv.ParseBool(value)
107-
if err != nil {
108-
return CmdOutput{}, bosherr.WrapErrorf(err, "Parsing $BOSH_CPI_USE_ISOLATED_ENV error, could not parse value: %v", value)
109-
}
110-
}
111105

112106
cmdPath := r.cpi.ExecutablePath()
113107
cmd := boshsys.Command{
@@ -117,11 +111,11 @@ func (r *cpiCmdRunner) Run(context CmdContext, method string, apiVersion int, ar
117111
"BOSH_JOBS_DIR": r.cpi.JobsDir,
118112
"PATH": os.Getenv("PATH"),
119113
},
120-
// 🚧 To-do: Make this configurable via cli-flag or use everywhere the environment-variable
121-
// “BOSH_CPI_USE_ISOLATED_ENV” as in cpi_cmd_runner.go, see <https://github.com/cloudfoundry/bosh-cli/issues/660>.
122-
UseIsolatedEnv: useIsolatedEnv,
114+
UseIsolatedEnv: r.useIsolatedEnv,
123115
Stdin: bytes.NewReader(inputBytes),
124116
}
117+
fmt.Printf("cpi_cmd_runner.go: UseIsolatedEnv = %t\n", cmd.UseIsolatedEnv) // 🚧 To-do: Debug-code
118+
125119
stdout, stderr, exitCode, err := r.cmdRunner.RunComplexCommand(cmd)
126120
r.logger.Debug(r.logTag, "Exit Code %d when executing external CPI command '%s'\nSTDIN: '%s'\nSTDOUT: '%s'\nSTDERR: '%s'", exitCode, cmdPath, string(inputBytes), stdout, stderr)
127121
if err != nil {

cloud/factory.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,23 @@ type Factory interface {
1212
}
1313

1414
type factory struct {
15-
fs boshsys.FileSystem
16-
cmdRunner boshsys.CmdRunner
17-
logger boshlog.Logger
15+
fs boshsys.FileSystem
16+
cmdRunner boshsys.CmdRunner
17+
logger boshlog.Logger
18+
useIsolatedEnv bool
1819
}
1920

2021
func NewFactory(
2122
fs boshsys.FileSystem,
2223
cmdRunner boshsys.CmdRunner,
2324
logger boshlog.Logger,
25+
useIsolatedEnv bool,
2426
) Factory {
2527
return &factory{
26-
fs: fs,
27-
cmdRunner: cmdRunner,
28-
logger: logger,
28+
fs: fs,
29+
cmdRunner: cmdRunner,
30+
logger: logger,
31+
useIsolatedEnv: useIsolatedEnv,
2932
}
3033
}
3134

@@ -43,6 +46,6 @@ func (f *factory) NewCloud(installation biinstall.Installation, directorID strin
4346
return nil, bosherr.Errorf("Installed CPI job '%s' does not contain the required executable '%s'", cpiJob.Name, cmdPath)
4447
}
4548

46-
cpiCmdRunner := NewCPICmdRunner(f.cmdRunner, cpi, f.logger)
49+
cpiCmdRunner := NewCPICmdRunner(f.cmdRunner, cpi, f.logger, f.useIsolatedEnv)
4750
return NewCloud(cpiCmdRunner, directorID, stemcellApiVersion, f.logger), nil
4851
}

cmd/env_factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func NewEnvFactory(
150150
f.blobstoreFactory = biblobstore.NewBlobstoreFactory(deps.UUIDGen, deps.FS, deps.Logger)
151151
f.deploymentFactory = bidepl.NewFactory(10*time.Second, 500*time.Millisecond)
152152
f.agentClientFactory = bihttpagent.NewAgentClientFactory(1*time.Second, deps.Logger)
153-
f.cloudFactory = bicloud.NewFactory(deps.FS, deps.CmdRunner, deps.Logger)
153+
f.cloudFactory = bicloud.NewFactory(deps.FS, deps.CmdRunner, deps.Logger, useIsolatedEnv)
154154
}
155155

156156
{

cmd/opts/opts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ type CreateEnvOpts struct {
197197
StatePath string `long:"state" value-name:"PATH" description:"State file path"`
198198
Recreate bool `long:"recreate" description:"Recreate VM in deployment"`
199199
RecreatePersistentDisks bool `long:"recreate-persistent-disks" description:"Recreate persistent disks in the deployment"`
200-
AvoidIsolatedEnv bool `long:"avoid-isolated-environment" short:"I" description:"Compile and run cpi-commands in a clean environment or not"`
200+
AvoidIsolatedEnv bool `long:"avoid-isolated-environment" short:"I" description:"Compile and run cpi-commands in a clean environment or not"`
201201
cmd
202202
}
203203

installation/pkg/compiler.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package pkg
22

33
import (
4+
"fmt"
45
"os"
56
"path/filepath"
67

@@ -110,6 +111,8 @@ func (c *compiler) Compile(pkg birelpkg.Compilable) (bistatepkg.CompiledPackageR
110111
WorkingDir: packageSrcDir,
111112
}
112113

114+
fmt.Printf("compiler.go: UseIsolatedEnv = %t\n", cmd.UseIsolatedEnv) // 🚧 To-do: Debug-code
115+
113116
_, _, _, err = c.runner.RunComplexCommand(cmd)
114117
if err != nil {
115118
return record, isCompiledPackage, bosherr.WrapError(err, "Compiling package")

0 commit comments

Comments
 (0)