Skip to content

Commit

Permalink
Fixed creating clusters in different namespaces when pivoting
Browse files Browse the repository at this point in the history
There was a bug that prevented pivoting because a desired namespace was specified
in the cluster.yaml file.  It needs to ensure the the namespace on the target
cluster before pivoting.  Also, ensuring namespace after getting the target cluster
kubeconfig requires a loop with exp backoff in some environments.

Fixes #735
  • Loading branch information
sflxn committed Feb 7, 2019
1 parent 9153bcf commit db673d8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions cmd/clusterctl/clusterdeployer/clusterdeployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"sigs.k8s.io/cluster-api/cmd/clusterctl/clusterdeployer/provider"
"sigs.k8s.io/cluster-api/cmd/clusterctl/phases"
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
"sigs.k8s.io/cluster-api/pkg/util"
)

type ClusterDeployer struct {
Expand Down Expand Up @@ -102,6 +103,20 @@ func (d *ClusterDeployer) Create(cluster *clusterv1.Cluster, machines []*cluster
}
defer closeClient(targetClient, "target")

klog.Info("Creating namespace on target cluster")
addNamespaceToTarget := func() (bool, error) {
err = targetClient.EnsureNamespace(cluster.Namespace)
if err != nil {
return false, nil
}
return true, nil
}

err = util.Retry(addNamespaceToTarget, 0)
if err != nil {
return errors.Wrapf(err, "unable to ensure namespace %q in targetCluster", cluster.Namespace)
}

if d.addonComponents != "" {
if err := phases.ApplyAddons(targetClient, d.addonComponents); err != nil {
return errors.Wrap(err, "unable to apply addons to target cluster")
Expand All @@ -119,11 +134,6 @@ func (d *ClusterDeployer) Create(cluster *clusterv1.Cluster, machines []*cluster
return errors.Wrap(err, "unable to save provider components to target cluster")
}

err = targetClient.EnsureNamespace(cluster.Namespace)
if err != nil {
return errors.Wrapf(err, "unable to ensure namespace %q in targetCluster", cluster.Namespace)
}

// For some reason, endpoint doesn't get updated in bootstrap cluster sometimes. So we
// update the target cluster endpoint as well to be sure.
klog.Infof("Updating target cluster object with control plane endpoint running on %s", controlPlaneMachine.Name)
Expand Down

0 comments on commit db673d8

Please sign in to comment.