Skip to content

Commit 49128cd

Browse files
author
Joseph Palermo
authored
Merge pull request #673 from fmoehler/optional_isolated_environment
Remove isolated environment from cpi and compiler cmd
2 parents 63e1bcb + 8bfb6a6 commit 49128cd

File tree

4 files changed

+4
-62
lines changed

4 files changed

+4
-62
lines changed

cloud/cpi_cmd_runner.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7-
"os"
8-
"strconv"
97

108
bosherr "github.com/cloudfoundry/bosh-utils/errors"
119
boshlog "github.com/cloudfoundry/bosh-utils/logger"
@@ -100,26 +98,17 @@ func (r *cpiCmdRunner) Run(context CmdContext, method string, apiVersion int, ar
10098
if err != nil {
10199
return CmdOutput{}, bosherr.WrapErrorf(err, "Marshalling external CPI command input %#v", cmdInput)
102100
}
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-
}
111101

112102
cmdPath := r.cpi.ExecutablePath()
113103
cmd := boshsys.Command{
114104
Name: cmdPath,
115105
Env: map[string]string{
116106
"BOSH_PACKAGES_DIR": r.cpi.PackagesDir,
117107
"BOSH_JOBS_DIR": r.cpi.JobsDir,
118-
"PATH": "/usr/local/bin:/usr/bin:/bin:/sbin",
119108
},
120-
UseIsolatedEnv: useIsolatedEnv,
121-
Stdin: bytes.NewReader(inputBytes),
109+
Stdin: bytes.NewReader(inputBytes),
122110
}
111+
123112
stdout, stderr, exitCode, err := r.cmdRunner.RunComplexCommand(cmd)
124113
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)
125114
if err != nil {

cloud/cpi_cmd_runner_test.go

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"errors"
66
"io"
7-
"os"
87

98
boshlog "github.com/cloudfoundry/bosh-utils/logger"
109
fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
@@ -63,9 +62,7 @@ var _ = Describe("CpiCmdRunner", func() {
6362
Expect(actualCmd.Env).To(Equal(map[string]string{
6463
"BOSH_PACKAGES_DIR": cpi.PackagesDir,
6564
"BOSH_JOBS_DIR": cpi.JobsDir,
66-
"PATH": "/usr/local/bin:/usr/bin:/bin:/sbin",
6765
}))
68-
Expect(actualCmd.UseIsolatedEnv).To(BeTrue())
6966
bytes, err := io.ReadAll(actualCmd.Stdin)
7067
Expect(err).NotTo(HaveOccurred())
7168
Expect(string(bytes)).To(Equal(
@@ -89,41 +86,6 @@ var _ = Describe("CpiCmdRunner", func() {
8986
apiVersion = 2
9087
})
9188

92-
AfterEach(func() {
93-
os.Unsetenv("BOSH_CPI_USE_ISOLATED_ENV")
94-
})
95-
It("creates correct command with UseIsolatedEnv false if BOSH_CPI_USE_ISOLATED_ENV is set", func() {
96-
os.Setenv("BOSH_CPI_USE_ISOLATED_ENV", "false")
97-
cmdOutput := CmdOutput{}
98-
outputBytes, err := json.Marshal(cmdOutput)
99-
Expect(err).NotTo(HaveOccurred())
100-
101-
result := fakesys.FakeCmdResult{
102-
Stdout: string(outputBytes),
103-
ExitStatus: 0,
104-
}
105-
cmdRunner.AddCmdResult("/jobs/cpi/bin/cpi", result)
106-
_, err = cpiCmdRunner.Run(context, "fake-method", apiVersion, "fake-argument-1", "fake-argument-2")
107-
Expect(err).NotTo(HaveOccurred())
108-
actualCmd := cmdRunner.RunComplexCommands[0]
109-
Expect(actualCmd.UseIsolatedEnv).To(BeFalse())
110-
111-
})
112-
It("throws helpful error if the value of BOSH_CPI_USE_ISOLATED_ENV cannot be parsed into a bool", func() {
113-
os.Setenv("BOSH_CPI_USE_ISOLATED_ENV", "falasdse")
114-
cmdOutput := CmdOutput{}
115-
outputBytes, err := json.Marshal(cmdOutput)
116-
Expect(err).NotTo(HaveOccurred())
117-
118-
result := fakesys.FakeCmdResult{
119-
Stdout: string(outputBytes),
120-
ExitStatus: 0,
121-
}
122-
cmdRunner.AddCmdResult("/jobs/cpi/bin/cpi", result)
123-
_, err = cpiCmdRunner.Run(context, "fake-method", apiVersion, "fake-argument-1", "fake-argument-2")
124-
Expect(err).To(HaveOccurred())
125-
Expect(MatchRegexp("BOSH_CPI_USE_ISOLATED_ENV cannot be parsed", err))
126-
})
12789
It("creates correct command with stemcell api_version in context", func() {
12890
cmdOutput := CmdOutput{}
12991
outputBytes, err := json.Marshal(cmdOutput)
@@ -145,9 +107,7 @@ var _ = Describe("CpiCmdRunner", func() {
145107
Expect(actualCmd.Env).To(Equal(map[string]string{
146108
"BOSH_PACKAGES_DIR": cpi.PackagesDir,
147109
"BOSH_JOBS_DIR": cpi.JobsDir,
148-
"PATH": "/usr/local/bin:/usr/bin:/bin:/sbin",
149110
}))
150-
Expect(actualCmd.UseIsolatedEnv).To(BeTrue())
151111
bytes, err := io.ReadAll(actualCmd.Stdin)
152112
Expect(err).NotTo(HaveOccurred())
153113
Expect(string(bytes)).To(Equal(

installation/pkg/compiler.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,8 @@ func (c *compiler) Compile(pkg birelpkg.Compilable) (bistatepkg.CompiledPackageR
102102
"BOSH_INSTALL_TARGET": installDir,
103103
"BOSH_PACKAGE_NAME": pkg.Name(),
104104
"BOSH_PACKAGES_DIR": c.packagesDir,
105-
"PATH": os.Getenv("PATH"),
106-
"LD_LIBRARY_PATH": os.Getenv("LD_LIBRARY_PATH"),
107105
},
108-
UseIsolatedEnv: true,
109-
WorkingDir: packageSrcDir,
106+
WorkingDir: packageSrcDir,
110107
}
111108

112109
_, _, _, err = c.runner.RunComplexCommand(cmd)

installation/pkg/compiler_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package pkg_test
22

33
import (
44
"errors"
5-
"os"
65
"path/filepath"
76

87
fakeblobstore "github.com/cloudfoundry/bosh-utils/blobstore/fakes"
@@ -175,11 +174,8 @@ var _ = Describe("PackageCompiler", func() {
175174
"BOSH_INSTALL_TARGET": installPath,
176175
"BOSH_PACKAGE_NAME": "pkg1-name",
177176
"BOSH_PACKAGES_DIR": packagesDir,
178-
"PATH": os.Getenv("PATH"),
179-
"LD_LIBRARY_PATH": os.Getenv("LD_LIBRARY_PATH"),
180177
},
181-
UseIsolatedEnv: true,
182-
WorkingDir: "/pkg-dir",
178+
WorkingDir: "/pkg-dir",
183179
}
184180

185181
Expect(runner.RunComplexCommands).To(HaveLen(1))

0 commit comments

Comments
 (0)