Skip to content

add logs at end of install for kubeadmin, consoleURL #806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ ignored = ["github.com/openshift/installer/tests*"]
[[constraint]]
branch = "master"
name = "github.com/openshift/api"

[[constraint]]
name = "github.com/openshift/client-go"
revision = "1fa528d3be060e4c7178eb69e76d37cf7e699e3c"
88 changes: 77 additions & 11 deletions cmd/openshift-install/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"fmt"
"io/ioutil"
"os/exec"
"path/filepath"
Expand All @@ -16,8 +17,10 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"

routeclient "github.com/openshift/client-go/route/clientset/versioned"
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/cluster"
"github.com/openshift/installer/pkg/asset/ignition/bootstrap"
Expand Down Expand Up @@ -89,11 +92,22 @@ var (
// FIXME: add longer descriptions for our commands with examples for better UX.
// Long: "",
PostRunE: func(_ *cobra.Command, _ []string) error {
err := destroyBootstrap(context.Background(), rootOpts.dir)
ctx := context.Background()
config, err := clientcmd.BuildConfigFromFlags("", filepath.Join(rootOpts.dir, "auth", "kubeconfig"))
if err != nil {
return errors.Wrap(err, "loading kubeconfig")
}

err = destroyBootstrap(ctx, config, rootOpts.dir)
if err != nil {
return err
}
consoleURL, err := waitForConsole(ctx, config, rootOpts.dir)
if err != nil {
return err
}
return logComplete(rootOpts.dir)

return logComplete(rootOpts.dir, consoleURL)
},
},
assets: []asset.WritableAsset{&cluster.TerraformVariables{}, &kubeconfig.Admin{}, &cluster.Cluster{}},
Expand Down Expand Up @@ -160,18 +174,13 @@ func runTargetCmd(targets ...asset.WritableAsset) func(cmd *cobra.Command, args

// FIXME: pulling the kubeconfig and metadata out of the root
// directory is a bit cludgy when we already have them in memory.
func destroyBootstrap(ctx context.Context, directory string) (err error) {
func destroyBootstrap(ctx context.Context, config *rest.Config, directory string) (err error) {
cleanup, err := setupFileHook(rootOpts.dir)
if err != nil {
return errors.Wrap(err, "failed to setup logging hook")
}
defer cleanup()

config, err := clientcmd.BuildConfigFromFlags("", filepath.Join(directory, "auth", "kubeconfig"))
if err != nil {
return errors.Wrap(err, "loading kubeconfig")
}

client, err := kubernetes.NewForConfig(config)
if err != nil {
return errors.Wrap(err, "creating a Kubernetes client")
Expand Down Expand Up @@ -262,8 +271,62 @@ func destroyBootstrap(ctx context.Context, directory string) (err error) {
return destroybootstrap.Destroy(rootOpts.dir)
}

// waitForconsole returns the console URL from the route 'console' in namespace openshift-console
func waitForConsole(ctx context.Context, config *rest.Config, directory string) (string, error) {
url := ""
// Need to keep these updated if they change
consoleNamespace := "openshift-console"
consoleRouteName := "console"
rc, err := routeclient.NewForConfig(config)
if err != nil {
return "", errors.Wrap(err, "creating a route client")
}

consoleRouteTimeout := 10 * time.Minute
logrus.Infof("Waiting %v for the openshift-console route to be created...", consoleRouteTimeout)
consoleRouteContext, cancel := context.WithTimeout(ctx, consoleRouteTimeout)
defer cancel()
// Poll quickly but only log when the response
// when we've seen 15 of the same errors or output of
// no route in a row (to show we're still alive).
logDownsample := 15
silenceRemaining := logDownsample
wait.Until(func() {
consoleRoutes, err := rc.RouteV1().Routes(consoleNamespace).List(metav1.ListOptions{})
if err == nil && len(consoleRoutes.Items) > 0 {
for _, route := range consoleRoutes.Items {
logrus.Debugf("Route found in openshift-console namespace: %s\n", route.Name)
if route.Name == consoleRouteName {
url = fmt.Sprintf("https://%s", route.Spec.Host)
}
}
logrus.Debug("OpenShift console route is created")
cancel()
} else if err != nil {
silenceRemaining--
if silenceRemaining == 0 {
logrus.Debugf("Still waiting for the console route: %v", err)
silenceRemaining = logDownsample
}
} else if len(consoleRoutes.Items) == 0 {
silenceRemaining--
if silenceRemaining == 0 {
logrus.Debug("Still waiting for the console route...")
silenceRemaining = logDownsample
}
}
}, 2*time.Second, consoleRouteContext.Done())
if err != nil {
return "", errors.Wrap(err, "waiting for console route to be created")
}
if url == "" {
return url, errors.Wrap(err, "could not obtain openshift-console URL from route")
}
return url, nil
}

// logComplete prints info upon completion
func logComplete(directory string) error {
func logComplete(directory, consoleURL string) error {
absDir, err := filepath.Abs(directory)
if err != nil {
return err
Expand All @@ -274,7 +337,10 @@ func logComplete(directory string) error {
if err != nil {
return err
}
logrus.Infof("kubeadmin user password: %s", pw)
logrus.Infof("Install complete! The kubeconfig is located here: %s", kubeconfig)
logrus.Info("Install complete!")
logrus.Infof("Run 'export KUBECONFIG=%s' to manage the cluster with 'oc', the OpenShift CLI.", kubeconfig)
logrus.Infof("The cluster is ready when 'oc login -u kubeadmin -p %s' succeeds (wait a few minutes).", pw)
logrus.Infof("Access the OpenShift web-console here: %s", consoleURL)
logrus.Infof("Login to the console with user: kubeadmin, password: %s", pw)
return nil
}
8 changes: 8 additions & 0 deletions vendor/github.com/openshift/api/route/v1/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading