Skip to content

Commit bbd05e4

Browse files
committed
Merge pull request #1220 from timstclair/raw
Fix docker GetSpec to include image, labels, and env vars
2 parents 85c2a1c + 9790a0d commit bbd05e4

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

build/integration.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fi
2121
sudo -v || exit 1
2222

2323
echo ">> starting cAdvisor locally"
24-
sudo ./cadvisor &
24+
sudo ./cadvisor --docker_env_metadata_whitelist=TEST_VAR &
2525

2626
readonly TIMEOUT=120 # Timeout to wait for cAdvisor, in seconds.
2727
START=$(date +%s)

container/docker/handler.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,13 @@ func (self *dockerContainerHandler) needNet() bool {
229229

230230
func (self *dockerContainerHandler) GetSpec() (info.ContainerSpec, error) {
231231
hasFilesystem := !self.ignoreMetrics.Has(container.DiskUsageMetrics)
232-
return common.GetSpec(self.cgroupPaths, self.machineInfoFactory, self.needNet(), hasFilesystem)
232+
spec, err := common.GetSpec(self.cgroupPaths, self.machineInfoFactory, self.needNet(), hasFilesystem)
233+
234+
spec.Labels = self.labels
235+
spec.Envs = self.envs
236+
spec.Image = self.image
237+
238+
return spec, err
233239
}
234240

235241
func (self *dockerContainerHandler) getFsStats(stats *info.ContainerStats) error {

integration/runner/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func PushAndRunTests(host, testDir string) error {
113113
portStr := strconv.Itoa(*port)
114114
errChan := make(chan error)
115115
go func() {
116-
err = RunSshCommand("ssh", host, "--", fmt.Sprintf("sudo %s --port %s --logtostderr &> %s/log.txt", path.Join(testDir, cadvisorBinary), portStr, testDir))
116+
err = RunSshCommand("ssh", host, "--", fmt.Sprintf("sudo %s --port %s --logtostderr --docker_env_metadata_whitelist=TEST_VAR &> %s/log.txt", path.Join(testDir, cadvisorBinary), portStr, testDir))
117117
if err != nil {
118118
errChan <- fmt.Errorf("error running cAdvisor: %v", err)
119119
}

integration/tests/api/docker_test.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,27 @@ func TestDockerContainerSpec(t *testing.T) {
184184
fm := framework.New(t)
185185
defer fm.Cleanup()
186186

187-
cpuShares := uint64(2048)
188-
cpuMask := "0"
189-
memoryLimit := uint64(1 << 30) // 1GB
187+
var (
188+
cpuShares = uint64(2048)
189+
cpuMask = "0"
190+
memoryLimit = uint64(1 << 30) // 1GB
191+
image = "kubernetes/pause"
192+
env = map[string]string{"test_var": "FOO"}
193+
labels = map[string]string{"bar": "baz"}
194+
)
195+
190196
cpusetArg := "--cpuset"
191197
if getDockerMinorVersion(fm) >= 10 {
192198
cpusetArg = "--cpuset-cpus"
193199
}
194200
containerId := fm.Docker().Run(framework.DockerRunArgs{
195-
Image: "kubernetes/pause",
201+
Image: image,
196202
Args: []string{
197203
"--cpu-shares", strconv.FormatUint(cpuShares, 10),
198204
cpusetArg, cpuMask,
199205
"--memory", strconv.FormatUint(memoryLimit, 10),
206+
"--env", "TEST_VAR=FOO",
207+
"--label", "bar=baz",
200208
},
201209
})
202210

@@ -213,12 +221,16 @@ func TestDockerContainerSpec(t *testing.T) {
213221
assert := assert.New(t)
214222

215223
assert.True(containerInfo.Spec.HasCpu, "CPU should be isolated")
216-
assert.Equal(containerInfo.Spec.Cpu.Limit, cpuShares, "Container should have %d shares, has %d", cpuShares, containerInfo.Spec.Cpu.Limit)
217-
assert.Equal(containerInfo.Spec.Cpu.Mask, cpuMask, "Cpu mask should be %q, but is %q", cpuMask, containerInfo.Spec.Cpu.Mask)
224+
assert.Equal(cpuShares, containerInfo.Spec.Cpu.Limit, "Container should have %d shares, has %d", cpuShares, containerInfo.Spec.Cpu.Limit)
225+
assert.Equal(cpuMask, containerInfo.Spec.Cpu.Mask, "Cpu mask should be %q, but is %q", cpuMask, containerInfo.Spec.Cpu.Mask)
218226
assert.True(containerInfo.Spec.HasMemory, "Memory should be isolated")
219-
assert.Equal(containerInfo.Spec.Memory.Limit, memoryLimit, "Container should have memory limit of %d, has %d", memoryLimit, containerInfo.Spec.Memory.Limit)
227+
assert.Equal(memoryLimit, containerInfo.Spec.Memory.Limit, "Container should have memory limit of %d, has %d", memoryLimit, containerInfo.Spec.Memory.Limit)
220228
assert.True(containerInfo.Spec.HasNetwork, "Network should be isolated")
221229
assert.True(containerInfo.Spec.HasDiskIo, "Blkio should be isolated")
230+
231+
assert.Equal(image, containerInfo.Spec.Image, "Spec should include container image")
232+
assert.Equal(env, containerInfo.Spec.Envs, "Spec should include environment variables")
233+
assert.Equal(labels, containerInfo.Spec.Labels, "Spec should include labels")
222234
}
223235

224236
// Check the CPU ContainerStats.

0 commit comments

Comments
 (0)