Skip to content

Commit f31d127

Browse files
author
OpenShift Bot
authored
Merge pull request #9256 from csrwng/cluster_up_log
Merged by openshift-bot
2 parents 9bb7cac + da05de1 commit f31d127

File tree

6 files changed

+57
-15
lines changed

6 files changed

+57
-15
lines changed

pkg/bootstrap/docker/dockerhelper/helper.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package dockerhelper
22

33
import (
4+
"bytes"
45
"encoding/json"
56
"errors"
67
"fmt"
78
"io"
89
"net"
910
"net/url"
11+
"strconv"
1012
"strings"
1113

1214
"github.com/blang/semver"
@@ -207,6 +209,22 @@ func (h *Helper) HostIP() string {
207209
return ""
208210
}
209211

212+
func (h *Helper) ContainerLog(container string, numLines int) string {
213+
output := &bytes.Buffer{}
214+
err := h.client.Logs(docker.LogsOptions{
215+
Container: container,
216+
Tail: strconv.Itoa(numLines),
217+
OutputStream: output,
218+
ErrorStream: output,
219+
Stdout: true,
220+
Stderr: true,
221+
})
222+
if err != nil {
223+
glog.V(1).Infof("Error getting container %q log: %v", container, err)
224+
}
225+
return output.String()
226+
}
227+
210228
func (h *Helper) StopAndRemoveContainer(container string) error {
211229
err := h.client.StopContainer(container, 10)
212230
if err != nil {

pkg/bootstrap/docker/errors/errors.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Error interface {
1515
error
1616
WithCause(error) Error
1717
WithSolution(string, ...interface{}) Error
18+
WithDetails(string) Error
1819
}
1920

2021
func NewError(msg string, args ...interface{}) Error {
@@ -42,6 +43,10 @@ func (e *internalError) Solution() string {
4243
return e.solution
4344
}
4445

46+
func (e *internalError) Details() string {
47+
return e.details
48+
}
49+
4550
func (e *internalError) WithCause(err error) Error {
4651
e.cause = err
4752
return e

pkg/bootstrap/docker/openshift/admin.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (h *Helper) InstallRegistry(kubeClient kclient.Interface, f *clientcmd.Fact
3535
return nil
3636
}
3737
if !apierrors.IsNotFound(err) {
38-
return errors.NewError("error retrieving docker registry service").WithCause(err)
38+
return errors.NewError("error retrieving docker registry service").WithCause(err).WithDetails(h.OriginLog())
3939
}
4040
imageTemplate := variable.NewDefaultImageTemplate()
4141
imageTemplate.Format = images
@@ -53,7 +53,10 @@ func (h *Helper) InstallRegistry(kubeClient kclient.Interface, f *clientcmd.Fact
5353
output := &bytes.Buffer{}
5454
err = registry.RunCmdRegistry(f, cmd, output, cfg, []string{})
5555
glog.V(4).Infof("Registry command output:\n%s", output.String())
56-
return err
56+
if err != nil {
57+
return errors.NewError("cannot install registry").WithCause(err).WithDetails(h.OriginLog())
58+
}
59+
return nil
5760
}
5861

5962
// InstallRouter installs a default router on the OpenShift server
@@ -63,6 +66,9 @@ func (h *Helper) InstallRouter(kubeClient kclient.Interface, f *clientcmd.Factor
6366
// Router service already exists, nothing to do
6467
return nil
6568
}
69+
if !apierrors.IsNotFound(err) {
70+
return errors.NewError("error retrieving router service").WithCause(err).WithDetails(h.OriginLog())
71+
}
6672

6773
masterDir := filepath.Join(configDir, "master")
6874

@@ -71,18 +77,18 @@ func (h *Helper) InstallRouter(kubeClient kclient.Interface, f *clientcmd.Factor
7177
routerSA.Name = "router"
7278
_, err = kubeClient.ServiceAccounts("default").Create(routerSA)
7379
if err != nil {
74-
return errors.NewError("cannot create router service account").WithCause(err)
80+
return errors.NewError("cannot create router service account").WithCause(err).WithDetails(h.OriginLog())
7581
}
7682

7783
// Add router SA to privileged SCC
7884
privilegedSCC, err := kubeClient.SecurityContextConstraints().Get("privileged")
7985
if err != nil {
80-
return errors.NewError("cannot retrieve privileged SCC").WithCause(err)
86+
return errors.NewError("cannot retrieve privileged SCC").WithCause(err).WithDetails(h.OriginLog())
8187
}
8288
privilegedSCC.Users = append(privilegedSCC.Users, serviceaccount.MakeUsername("default", "router"))
8389
_, err = kubeClient.SecurityContextConstraints().Update(privilegedSCC)
8490
if err != nil {
85-
return errors.NewError("cannot update privileged SCC").WithCause(err)
91+
return errors.NewError("cannot update privileged SCC").WithCause(err).WithDetails(h.OriginLog())
8692
}
8793

8894
// Create router cert
@@ -134,7 +140,10 @@ func (h *Helper) InstallRouter(kubeClient kclient.Interface, f *clientcmd.Factor
134140
cmd.SetOutput(output)
135141
err = router.RunCmdRouter(f, cmd, output, cfg, []string{})
136142
glog.V(4).Infof("Router command output:\n%s", output.String())
137-
return err
143+
if err != nil {
144+
return errors.NewError("cannot install router").WithCause(err).WithDetails(h.OriginLog())
145+
}
146+
return nil
138147
}
139148

140149
// catFiles concatenates multiple source files into a single destination file

pkg/bootstrap/docker/openshift/errors.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ package openshift
22

33
import (
44
"fmt"
5+
6+
"github.com/openshift/origin/pkg/bootstrap/docker/errors"
57
)
68

79
// ErrOpenShiftFailedToStart is thrown when the OpenShift server failed to start
8-
func ErrOpenShiftFailedToStart(container string) error {
9-
return fmt.Errorf("Could not start OpenShift container %q", container)
10+
func ErrOpenShiftFailedToStart(container string) errors.Error {
11+
return errors.NewError("could not start OpenShift container %q", container)
1012
}
1113

1214
// ErrTimedOutWaitingForStart is thrown when the OpenShift server can't be pinged after reasonable
1315
// amount of time.
14-
func ErrTimedOutWaitingForStart(container string) error {
15-
return fmt.Errorf("Could not start OpenShift container %q", container)
16+
func ErrTimedOutWaitingForStart(container string) errors.Error {
17+
return errors.NewError("timed out waiting for OpenShift container %q", container)
1618
}
1719

1820
type errPortsNotAvailable struct {

pkg/bootstrap/docker/openshift/helper.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,14 @@ func (h *Helper) Start(opt *StartOptions, out io.Writer) (string, error) {
268268
return "", errors.NewError("cannot get state of OpenShift container %s", h.containerName).WithCause(err)
269269
}
270270
if !running {
271-
return "", ErrOpenShiftFailedToStart(h.containerName)
271+
return "", ErrOpenShiftFailedToStart(h.containerName).WithDetails(h.OriginLog())
272272
}
273273

274274
// Wait until the API server is listening
275275
fmt.Fprintf(out, "Waiting for API server to start listening\n")
276276
masterHost := fmt.Sprintf("%s:8443", opt.ServerIP)
277277
if err = cmdutil.WaitForSuccessfulDial(true, "tcp", masterHost, 200*time.Millisecond, 1*time.Second, serverUpTimeout); err != nil {
278-
return "", ErrTimedOutWaitingForStart(h.containerName)
278+
return "", ErrTimedOutWaitingForStart(h.containerName).WithDetails(h.OriginLog())
279279
}
280280
// Check for healthz endpoint to be ready
281281
client, err := masterHTTPClient(configDir)
@@ -285,7 +285,7 @@ func (h *Helper) Start(opt *StartOptions, out io.Writer) (string, error) {
285285
for {
286286
resp, ierr := client.Get(h.healthzReadyURL(opt.ServerIP))
287287
if ierr != nil {
288-
return "", errors.NewError("cannot access master readiness URL %s", h.healthzReadyURL(opt.ServerIP)).WithCause(err)
288+
return "", errors.NewError("cannot access master readiness URL %s", h.healthzReadyURL(opt.ServerIP)).WithCause(err).WithDetails(h.OriginLog())
289289
}
290290
if resp.StatusCode == http.StatusOK {
291291
break
@@ -300,12 +300,20 @@ func (h *Helper) Start(opt *StartOptions, out io.Writer) (string, error) {
300300
if rerr == nil {
301301
responseBody = string(body)
302302
}
303-
return "", errors.NewError("server is not ready. Response (%d): %s", resp.StatusCode, responseBody).WithCause(ierr)
303+
return "", errors.NewError("server is not ready. Response (%d): %s", resp.StatusCode, responseBody).WithCause(ierr).WithDetails(h.OriginLog())
304304
}
305305
fmt.Fprintf(out, "OpenShift server started\n")
306306
return configDir, nil
307307
}
308308

309+
func (h *Helper) OriginLog() string {
310+
log := h.dockerHelper.ContainerLog(h.containerName, 10)
311+
if len(log) > 0 {
312+
return fmt.Sprintf("Last 10 lines of %q container log:\n%s\n", h.containerName, log)
313+
}
314+
return fmt.Sprintf("No log available from %q container\n", h.containerName)
315+
}
316+
309317
func (h *Helper) healthzReadyURL(ip string) string {
310318
return fmt.Sprintf("%s/healthz/ready", h.Master(ip))
311319
}

pkg/bootstrap/docker/up.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ func (c *ClientStartConfig) importObjects(out io.Writer, locations map[string]st
611611
glog.V(2).Infof("Importing %s from %s", name, location)
612612
err = openshift.ImportObjects(f, openShiftNamespace, location)
613613
if err != nil {
614-
return err
614+
return errors.NewError("cannot import %s", name).WithCause(err).WithDetails(c.OpenShiftHelper().OriginLog())
615615
}
616616
}
617617
return nil

0 commit comments

Comments
 (0)