Skip to content

Commit

Permalink
Merge pull request #1132 from staebler/wait_for_clusterversion
Browse files Browse the repository at this point in the history
cmd: wait for the cluster to be initialized
  • Loading branch information
openshift-merge-robot committed Jan 31, 2019
2 parents c69f25c + e17ba3c commit 9f73958
Show file tree
Hide file tree
Showing 52 changed files with 4,777 additions and 694 deletions.
28 changes: 23 additions & 5 deletions Gopkg.lock

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

8 changes: 0 additions & 8 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,6 @@ ignored = [
name = "github.com/gophercloud/utils"
revision = "34f5991525d116b3832e0d9409492274f1c06bda"

[[constraint]]
name = "github.com/openshift/api"
revision = "aab033bae2a129607f4fb277c3777b2eabb08601"

[[constraint]]
name = "github.com/openshift/client-go"
revision = "1fa528d3be060e4c7178eb69e76d37cf7e699e3c"

[[constraint]]
branch = "master"
name = "github.com/gophercloud/gophercloud"
Expand Down
55 changes: 54 additions & 1 deletion cmd/openshift-install/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ import (
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"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/cache"
"k8s.io/client-go/tools/clientcmd"
clientwatch "k8s.io/client-go/tools/watch"

configv1 "github.com/openshift/api/config/v1"
configclient "github.com/openshift/client-go/config/clientset/versioned"
routeclient "github.com/openshift/client-go/route/clientset/versioned"
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/cluster"
Expand All @@ -30,6 +35,7 @@ import (
"github.com/openshift/installer/pkg/asset/templates"
"github.com/openshift/installer/pkg/asset/tls"
destroybootstrap "github.com/openshift/installer/pkg/destroy/bootstrap"
cov1helpers "github.com/openshift/library-go/pkg/config/clusteroperator/v1helpers"
)

type target struct {
Expand Down Expand Up @@ -107,6 +113,10 @@ var (
logrus.Fatal(err)
}

if err := waitForInitializedCluster(ctx, config); err != nil {
logrus.Fatal(err)
}

consoleURL, err := waitForConsole(ctx, config, rootOpts.dir)
if err != nil {
logrus.Fatal(err)
Expand Down Expand Up @@ -279,7 +289,50 @@ func destroyBootstrap(ctx context.Context, config *rest.Config, directory string
return destroybootstrap.Destroy(rootOpts.dir)
}

// waitForconsole returns the console URL from the route 'console' in namespace openshift-console
// waitForInitializedCluster watches the ClusterVersion waiting for confirmation
// that the cluster has been initialized.
func waitForInitializedCluster(ctx context.Context, config *rest.Config) error {
timeout := 30 * time.Minute
logrus.Infof("Waiting up to %v for the cluster to initialize...", timeout)
cc, err := configclient.NewForConfig(config)
if err != nil {
return errors.Wrap(err, "failed to create a config client")
}
clusterVersionContext, cancel := context.WithTimeout(ctx, timeout)
defer cancel()

_, err = clientwatch.UntilWithSync(
clusterVersionContext,
cache.NewListWatchFromClient(cc.ConfigV1().RESTClient(), "clusterversions", "", fields.OneTermEqualSelector("metadata.name", "version")),
&configv1.ClusterVersion{},
nil,
func(event watch.Event) (bool, error) {
switch event.Type {
case watch.Added, watch.Modified:
cv, ok := event.Object.(*configv1.ClusterVersion)
if !ok {
logrus.Warnf("Expected a ClusterVersion object but got a %q object instead", event.Object.GetObjectKind().GroupVersionKind())
return false, nil
}
if cov1helpers.IsStatusConditionTrue(cv.Status.Conditions, configv1.OperatorAvailable) {
logrus.Debug("Cluster is initialized")
return true, nil
}
if cov1helpers.IsStatusConditionTrue(cv.Status.Conditions, configv1.OperatorFailing) {
logrus.Debugf("Still waiting for the cluster to initialize: %v",
cov1helpers.FindStatusCondition(cv.Status.Conditions, configv1.OperatorFailing).Message)
return false, nil
}
}
logrus.Debug("Still waiting for the cluster to initialize...")
return false, nil
},
)

return errors.Wrap(err, "failed to initialize the cluster")
}

// 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
Expand Down
6 changes: 4 additions & 2 deletions vendor/github.com/openshift/api/config/v1/register.go

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

23 changes: 15 additions & 8 deletions vendor/github.com/openshift/api/config/v1/types.go

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

73 changes: 73 additions & 0 deletions vendor/github.com/openshift/api/config/v1/types_apiserver.go

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

Loading

0 comments on commit 9f73958

Please sign in to comment.