-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jim Minter
committed
Sep 30, 2016
1 parent
b6ba8ec
commit 8ce8f13
Showing
8 changed files
with
299 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package docker | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" | ||
|
||
"github.com/openshift/origin/pkg/bootstrap/docker/dockerhelper" | ||
"github.com/openshift/origin/pkg/bootstrap/docker/errors" | ||
"github.com/openshift/origin/pkg/cmd/util/clientcmd" | ||
) | ||
|
||
const ( | ||
// CmdStatusRecommendedName is the recommended command name | ||
CmdStatusRecommendedName = "status" | ||
|
||
cmdStatusLong = ` | ||
Show the status of the local OpenShift cluster. | ||
If you started your OpenShift with a specific docker-machine, you need to specify the | ||
same machine using the --docker-machine argument. | ||
` | ||
cmdStatusExample = ` | ||
# See status of local OpenShift cluster | ||
%[1]s | ||
# See status of OpenShift cluster running on Docker machine 'mymachine' | ||
%[1]s --docker-machine=mymachine | ||
` | ||
) | ||
|
||
// NewCmdStatus implements the OpenShift cluster status command. | ||
func NewCmdStatus(name, fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command { | ||
config := &ClientStatusConfig{} | ||
cmd := &cobra.Command{ | ||
Use: name, | ||
Short: "Show OpenShift on Docker status", | ||
Long: cmdStatusLong, | ||
Example: fmt.Sprintf(cmdStatusExample, fullName), | ||
Run: func(c *cobra.Command, args []string) { | ||
kcmdutil.CheckErr(config.Status(f, out)) | ||
}, | ||
} | ||
cmd.Flags().StringVar(&config.DockerMachine, "docker-machine", "", "Specify the Docker machine to use") | ||
return cmd | ||
} | ||
|
||
// ClientStatusConfig is the configuration for the client status command | ||
type ClientStatusConfig struct { | ||
DockerMachine string | ||
} | ||
|
||
// Status prints the developer cluster status | ||
func (c *ClientStatusConfig) Status(f *clientcmd.Factory, out io.Writer) error { | ||
dockerClient, _, err := getDockerClient(out, c.DockerMachine, false) | ||
if err != nil { | ||
return errors.ErrNoDockerClient(err) | ||
} | ||
helper := dockerhelper.NewHelper(dockerClient, nil) | ||
|
||
_, running, err := helper.GetContainerState(openShiftContainer) | ||
if err != nil { | ||
return errors.NewError("cannot get state of OpenShift container %s", openShiftContainer).WithCause(err) | ||
} | ||
|
||
if running { | ||
client, _, err := f.Clients() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var statusCode int | ||
client.Client.Timeout = 10 * time.Second | ||
client.Get().AbsPath("/healthz").Do().StatusCode(&statusCode) | ||
if statusCode == 200 { | ||
fmt.Fprintf(out, "success: OpenShift cluster is running\n") | ||
return nil | ||
} | ||
} | ||
|
||
return errors.NewError("OpenShift cluster is not running") | ||
} |
Oops, something went wrong.