Skip to content

Commit a585a17

Browse files
Merge pull request #18578 from deads2k/up-10-containerid
Automatic merge from submit-queue (batch tested with PRs 18237, 18586, 18578). return containerID from completed pod noisy part of #18536 @mfojtik I don't care if it merges here, but figured I'd give you the option or at least split it out so you can see it. I need the ability to download files from a completed container and to do that I need the containerId which wasn't exposed before.
2 parents 9d4b997 + 40447e0 commit a585a17

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

pkg/oc/bootstrap/docker/host/host.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func NewHostHelper(dockerHelper *dockerhelper.Helper, image, volumesDir, configD
6060

6161
// CanUseNsenterMounter returns true if the Docker host machine can execute findmnt through nsenter
6262
func (h *HostHelper) CanUseNsenterMounter() (bool, error) {
63-
rc, err := h.runner().
63+
_, rc, err := h.runner().
6464
Image(h.image).
6565
DiscardContainer().
6666
Privileged().
@@ -74,7 +74,7 @@ func (h *HostHelper) CanUseNsenterMounter() (bool, error) {
7474
// for OpenShift volumes
7575
func (h *HostHelper) EnsureVolumeShare() error {
7676
cmd := fmt.Sprintf(ensureVolumeShareCmd, h.volumesDir)
77-
rc, err := h.runner().
77+
_, rc, err := h.runner().
7878
Image(h.image).
7979
DiscardContainer().
8080
HostPid().
@@ -138,7 +138,7 @@ func (h *HostHelper) UploadFileToContainer(src, dst string) error {
138138

139139
// Hostname retrieves the FQDN of the Docker host machine
140140
func (h *HostHelper) Hostname() (string, error) {
141-
hostname, _, _, err := h.runner().
141+
_, hostname, _, _, err := h.runner().
142142
Image(h.image).
143143
HostNetwork().
144144
HostPid().
@@ -168,7 +168,7 @@ func (h *HostHelper) EnsureHostDirectories(createVolumeShare bool) error {
168168
}
169169
if len(dirs) > 0 {
170170
cmd := fmt.Sprintf(cmdEnsureHostDirs, strings.Join(dirs, " "))
171-
rc, err := h.runner().
171+
_, rc, err := h.runner().
172172
Image(h.image).
173173
DiscardContainer().
174174
Privileged().

pkg/oc/bootstrap/docker/openshift/cnetwork.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ exit 1
3131
// TestContainerNetworking launches a container that will check whether the container
3232
// can communicate with the master API and DNS endpoints.
3333
func (h *Helper) TestContainerNetworking(ip string) error {
34-
_, err := h.runHelper.New().Image(h.image).
34+
_, _, err := h.runHelper.New().Image(h.image).
3535
DiscardContainer().
3636
Env(fmt.Sprintf("MASTER_IP=%s", ip)).
3737
DNS("172.30.0.1").

pkg/oc/bootstrap/docker/openshift/helper.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func NewHelper(dockerHelper *dockerhelper.Helper, hostHelper *host.HostHelper, i
149149
}
150150

151151
func (h *Helper) TestPorts(ports []int) error {
152-
portData, _, _, err := h.runHelper.New().Image(h.image).
152+
_, portData, _, _, err := h.runHelper.New().Image(h.image).
153153
DiscardContainer().
154154
Privileged().
155155
HostNetwork().
@@ -208,7 +208,7 @@ func (h *Helper) TestForwardedIP(ip string) error {
208208
}
209209

210210
func (h *Helper) DetermineNodeHost(hostConfigDir string, names ...string) (string, error) {
211-
result, _, _, err := h.runHelper.New().Image(h.image).
211+
_, result, _, _, err := h.runHelper.New().Image(h.image).
212212
DiscardContainer().
213213
Privileged().
214214
HostNetwork().
@@ -226,7 +226,7 @@ func (h *Helper) ServerIP() (string, error) {
226226
if len(h.serverIP) > 0 {
227227
return h.serverIP, nil
228228
}
229-
result, _, _, err := h.runHelper.New().Image(h.image).
229+
_, result, _, _, err := h.runHelper.New().Image(h.image).
230230
DiscardContainer().
231231
Privileged().
232232
HostNetwork().
@@ -240,7 +240,7 @@ func (h *Helper) ServerIP() (string, error) {
240240

241241
// OtherIPs tries to find other IPs besides the argument IP for the Docker host
242242
func (h *Helper) OtherIPs(excludeIP string) ([]string, error) {
243-
result, _, _, err := h.runHelper.New().Image(h.image).
243+
_, result, _, _, err := h.runHelper.New().Image(h.image).
244244
DiscardContainer().
245245
Privileged().
246246
HostNetwork().
@@ -342,7 +342,7 @@ func (h *Helper) Start(opt *StartOptions, out io.Writer) (string, error) {
342342
fmt.Sprintf("--hostname=%s", defaultNodeName),
343343
fmt.Sprintf("--public-master=https://%s:8443", publicHost),
344344
}
345-
_, err := h.runHelper.New().Image(h.image).
345+
_, _, err := h.runHelper.New().Image(h.image).
346346
Privileged().
347347
DiscardContainer().
348348
HostNetwork().
@@ -651,7 +651,7 @@ func (h *Helper) ServerPrereleaseVersion() (semver.Version, error) {
651651
return *h.prereleaseVersion, nil
652652
}
653653

654-
versionText, _, _, err := h.runHelper.New().Image(h.image).
654+
_, versionText, _, _, err := h.runHelper.New().Image(h.image).
655655
Command("version").
656656
DiscardContainer().
657657
Output()
@@ -945,7 +945,7 @@ fi
945945
946946
kubelet --help | grep -- "--cgroup-driver"
947947
`
948-
rc, err := h.runHelper.New().Image(h.image).
948+
_, rc, err := h.runHelper.New().Image(h.image).
949949
DiscardContainer().
950950
Entrypoint("/bin/bash").
951951
Command("-c", script).

pkg/oc/bootstrap/docker/run/run.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,14 @@ func (h *Runner) Start() (string, error) {
158158
}
159159

160160
// Output starts the container, waits for it to finish and returns its output
161-
func (h *Runner) Output() (string, string, int, error) {
161+
func (h *Runner) Output() (string, string, string, int, error) {
162162
return h.runWithOutput()
163163
}
164164

165165
// Run executes the container and waits until it completes
166-
func (h *Runner) Run() (int, error) {
167-
_, _, rc, err := h.runWithOutput()
168-
return rc, err
166+
func (h *Runner) Run() (string, int, error) {
167+
containerId, _, _, rc, err := h.runWithOutput()
168+
return containerId, rc, err
169169
}
170170

171171
func (h *Runner) Create() (string, error) {
@@ -234,10 +234,10 @@ func (h *Runner) startContainer(id string) error {
234234
return nil
235235
}
236236

237-
func (h *Runner) runWithOutput() (string, string, int, error) {
237+
func (h *Runner) runWithOutput() (string, string, string, int, error) {
238238
id, err := h.Create()
239239
if err != nil {
240-
return "", "", 0, err
240+
return "", "", "", 0, err
241241
}
242242
if h.removeContainer {
243243
defer func() {
@@ -252,14 +252,14 @@ func (h *Runner) runWithOutput() (string, string, int, error) {
252252
err = h.startContainer(id)
253253
if err != nil {
254254
glog.V(2).Infof("Error occurred starting container %q: %v", id, err)
255-
return "", "", 0, err
255+
return "", "", "", 0, err
256256
}
257257

258258
glog.V(5).Infof("Waiting for container %q", id)
259259
rc, err := h.client.ContainerWait(id)
260260
if err != nil {
261261
glog.V(2).Infof("Error occurred waiting for container %q: %v", id, err)
262-
return "", "", 0, err
262+
return "", "", "", 0, err
263263
}
264264
glog.V(5).Infof("Done waiting for container %q, rc=%d", id, rc)
265265

@@ -272,17 +272,17 @@ func (h *Runner) runWithOutput() (string, string, int, error) {
272272
err = h.client.ContainerLogs(id, types.ContainerLogsOptions{ShowStdout: true, ShowStderr: true}, stdOut, stdErr)
273273
if err != nil {
274274
glog.V(2).Infof("Error occurred while reading logs: %v", err)
275-
return "", "", 0, err
275+
return "", "", "", 0, err
276276
}
277277
glog.V(5).Infof("Done reading logs from container %q", id)
278278

279279
glog.V(5).Infof("Stdout:\n%s", stdOut.String())
280280
glog.V(5).Infof("Stderr:\n%s", stdErr.String())
281281
if rc != 0 || err != nil {
282-
return stdOut.String(), stdErr.String(), rc, newRunError(rc, err, stdOut.String(), stdErr.String(), h.config)
282+
return id, stdOut.String(), stdErr.String(), rc, newRunError(rc, err, stdOut.String(), stdErr.String(), h.config)
283283
}
284284
glog.V(4).Infof("Container run successful\n")
285-
return stdOut.String(), stdErr.String(), rc, nil
285+
return id, stdOut.String(), stdErr.String(), rc, nil
286286
}
287287

288288
// printConfig prints out the relevant parts of a container's Docker config

0 commit comments

Comments
 (0)