Skip to content

Commit

Permalink
check status of router, registry, metrics, logging, imagestreams in o…
Browse files Browse the repository at this point in the history
…c cluster status
  • Loading branch information
Jim Minter committed Jun 6, 2017
1 parent 375c727 commit 19f0fce
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/bootstrap/docker/openshift/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func metricsDeployerJob(hostName, imagePrefix, imageVersion string) *kbatch.Job

func MetricsHost(routingSuffix, serverIP string) string {
if len(routingSuffix) > 0 {
return fmt.Sprintf("metrics-openshift-infra.%s", routingSuffix)
return fmt.Sprintf("hawkular-metrics-openshift-infra.%s", routingSuffix)
}
return fmt.Sprintf("metrics-openshift-infra.%s.nip.io", serverIP)
return fmt.Sprintf("hawkular-metrics-openshift-infra.%s.nip.io", serverIP)
}
83 changes: 81 additions & 2 deletions pkg/bootstrap/docker/status.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package docker

import (
"crypto/tls"
"fmt"
"io"
"net/http"
"os"
"strings"
"time"
Expand All @@ -13,6 +15,7 @@ import (

"github.com/openshift/origin/pkg/bootstrap/docker/dockerhelper"
"github.com/openshift/origin/pkg/bootstrap/docker/errors"
"github.com/openshift/origin/pkg/bootstrap/docker/exec"
"github.com/openshift/origin/pkg/bootstrap/docker/openshift"
"github.com/openshift/origin/pkg/cmd/server/api"
"github.com/openshift/origin/pkg/cmd/templates"
Expand Down Expand Up @@ -48,7 +51,9 @@ func NewCmdStatus(name, fullName string, f *clientcmd.Factory, out io.Writer) *c
Run: func(c *cobra.Command, args []string) {
err := config.Status(f, out)
if err != nil {
PrintError(err, out)
if err.Error() != "" {
PrintError(err, out)
}
os.Exit(1)
}
},
Expand Down Expand Up @@ -92,7 +97,80 @@ func (c *ClientStatusConfig) Status(f *clientcmd.Factory, out io.Writer) error {
return err
}

fmt.Print(status(container, config))
fmt.Fprint(out, status(container, config))

notReady := 0

eh := exec.NewExecHelper(dockerClient, openshift.OpenShiftContainer)

stdout, _, _ := eh.Command(strings.Split("oc get dc docker-registry -n default -o template --template {{.status.availableReplicas}}", " ")...).Output()
if stdout != "1" {
fmt.Fprintln(out, "Notice: Docker registry is not yet ready")
notReady++
}

stdout, _, _ = eh.Command(strings.Split("oc get dc router -n default -o template --template {{.status.availableReplicas}}", " ")...).Output()
if stdout != "1" {
fmt.Fprintln(out, "Notice: Router is not yet ready")
notReady++
}

stdout, _, _ = eh.Command("oc", "get", "job", "persistent-volume-setup", "-n", "default", "-o", "template", "--template", "{{.status.succeeded}}").Output()
if stdout != "1" {
fmt.Fprintln(out, "Notice: Persistent volumes are not yet ready")
notReady++
}

stdout, _, _ = eh.Command("oc", "get", "is", "-n", "openshift", "-o", "template", "--template", `{{range .items}}{{if not .status.tags}}notready{{end}}{{end}}`).Output()
if len(stdout) > 0 {
fmt.Fprintln(out, "Notice: Imagestreams are not yet ready")
notReady++
}

insecureCli := http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
Timeout: 10 * time.Second,
}

ch := make(chan string)
go func() {
notice := ""
if config.AssetConfig.LoggingPublicURL != "" {
resp, _ := insecureCli.Get(config.AssetConfig.LoggingPublicURL)
if resp == nil || resp.StatusCode != http.StatusFound {
notice = "Notice: Logging component is not yet ready"
}
}
ch <- notice
}()

go func() {
notice := ""
if config.AssetConfig.MetricsPublicURL != "" {
resp, _ := insecureCli.Get(config.AssetConfig.MetricsPublicURL + "/status")
if resp == nil || resp.StatusCode != http.StatusOK {
notice = "Notice: Metrics component is not yet ready"
}
}
ch <- notice
}()

for i := 0; i < 2; i++ {
notice := <-ch
if notice != "" {
fmt.Fprintln(out, notice)
notReady++
}
}

if notReady > 0 {
fmt.Fprintf(out, "\nNotice: %d OpenShift component(s) are not yet ready (see above)\n", notReady)
return fmt.Errorf("")
}

return nil
}
Expand Down Expand Up @@ -145,6 +223,7 @@ func status(container *docker.Container, config *api.MasterConfig) string {
} else {
status = status + fmt.Sprintf("Data will be discarded when cluster is destroyed\n")
}
status = status + fmt.Sprintf("\n")

return status
}
2 changes: 1 addition & 1 deletion pkg/bootstrap/docker/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ func (c *ClientStartConfig) ServerInfo(out io.Writer) error {
metricsInfo := ""
if c.ShouldInstallMetrics && c.ShouldInitializeData() {
metricsInfo = fmt.Sprintf("The metrics service is available at:\n"+
" https://%s\n\n", openshift.MetricsHost(c.RoutingSuffix, c.ServerIP))
" https://%s/hawkular/metrics\n\n", openshift.MetricsHost(c.RoutingSuffix, c.ServerIP))
}
loggingInfo := ""
if c.ShouldInstallLogging && c.ShouldInitializeData() {
Expand Down

0 comments on commit 19f0fce

Please sign in to comment.