Skip to content

Commit

Permalink
get route from cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
sallyom committed Dec 7, 2018
1 parent 22c1b5b commit 7ab642c
Showing 1 changed file with 67 additions and 16 deletions.
83 changes: 67 additions & 16 deletions cmd/openshift-install/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package main

import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
Expand All @@ -20,6 +19,7 @@ import (
"k8s.io/client-go/kubernetes"
"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 @@ -95,7 +95,13 @@ var (
if err != nil {
return err
}
return logComplete(rootOpts.dir)
logrus.Info("Waiting for openshift-console route to be created...")
consoleURL, err := waitForConsole(context.Background(), rootOpts.dir)
if err != nil {
return err
}

return logComplete(rootOpts.dir, consoleURL)
},
},
assets: []asset.WritableAsset{&cluster.TerraformVariables{}, &kubeconfig.Admin{}, &cluster.Cluster{}},
Expand Down Expand Up @@ -264,23 +270,68 @@ func destroyBootstrap(ctx context.Context, directory string) (err error) {
return destroybootstrap.Destroy(rootOpts.dir)
}

// logComplete prints info upon completion
func logComplete(directory string) error {
absDir, err := filepath.Abs(directory)
// waitForconsole
func waitForConsole(ctx context.Context, directory string) (string, error) {
url := ""
// Need to keep these updated if they change
consoleNamespace := "openshift-console"
consoleRouteName := "console"
config, err := clientcmd.BuildConfigFromFlags("", filepath.Join(directory, "auth", "kubeconfig"))
if err != nil {
return err
return "", errors.Wrap(err, "loading kubeconfig")
}

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.Debug("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")
}
tfvarsFile := filepath.Join(absDir, cluster.TfVarsFileName)
f, err := os.Open(tfvarsFile)
return url, nil
}

// logComplete prints info upon completion
func logComplete(directory, consoleURL string) error {
absDir, err := filepath.Abs(directory)
if err != nil {
return err
}
defer f.Close()
tfVars, _ := ioutil.ReadAll(f)
var result map[string]interface{}
json.Unmarshal([]byte(tfVars), &result)
clusterName := result["cluster_name"]
baseDomain := result["base_domain"]
kubeconfig := filepath.Join(absDir, "auth", "kubeconfig")
pwFile := filepath.Join(absDir, "auth", "kubeadmin-password")
pw, err := ioutil.ReadFile(pwFile)
Expand All @@ -290,6 +341,6 @@ func logComplete(directory string) error {
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 'https://console-openshift-console.apps.%s.%s' with user: kubeadmin, password: %s", clusterName, baseDomain, pw)
logrus.Infof("Access the OpenShift web-console '%s' with user: kubeadmin, password: %s", consoleURL, pw)
return nil
}

0 comments on commit 7ab642c

Please sign in to comment.