Skip to content

Commit

Permalink
Ensure machine-controller during install and upgrade
Browse files Browse the repository at this point in the history
Signed-off-by: Artiom Diomin <kron82@gmail.com>
  • Loading branch information
kron4eg committed Mar 22, 2019
1 parent 581d9e8 commit a6147b3
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 59 deletions.
4 changes: 3 additions & 1 deletion pkg/installer/installation/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/pkg/errors"

"github.com/kubermatic/kubeone/pkg/features"
"github.com/kubermatic/kubeone/pkg/templates/machinecontroller"
"github.com/kubermatic/kubeone/pkg/util"
)

Expand All @@ -43,7 +44,8 @@ func Install(ctx *util.Context) error {
{fn: util.BuildKubernetesClientset, errMsg: "unable to build kubernetes clientset"},
{fn: features.Activate, errMsg: "unable to activate features"},
{fn: applyCanalCNI, errMsg: "failed to install cni plugin canal"},
{fn: installMachineController, errMsg: "failed to install machine-controller"},
{fn: machinecontroller.EnsureMachineController, errMsg: "failed to install machine-controller"},
{fn: machinecontroller.WaitReady, errMsg: "failed to wait for machine-controller"},
{fn: createWorkerMachines, errMsg: "failed to create worker machines"},
}

Expand Down
41 changes: 0 additions & 41 deletions pkg/installer/installation/machine_controller.go

This file was deleted.

16 changes: 1 addition & 15 deletions pkg/installer/installation/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package installation

import (
"time"

"github.com/pkg/errors"

"github.com/kubermatic/kubeone/pkg/templates/machinecontroller"
Expand All @@ -30,18 +28,6 @@ func createWorkerMachines(ctx *util.Context) error {
return nil
}

ctx.Logger.Infoln("Waiting for machine-controller to come up…")
if err := machinecontroller.WaitForWebhook(ctx.DynamicClient); err != nil {
return errors.Wrap(err, "machine-controller-webhook did not come up")
}

if err := machinecontroller.WaitForMachineController(ctx.DynamicClient); err != nil {
return errors.Wrap(err, "machine-controller did not come up")
}

// it can still take a bit before the MC is actually ready
time.Sleep(10 * time.Second)

ctx.Logger.Infoln("Creating worker machines…")
return machinecontroller.DeployMachineDeployments(ctx)
return errors.Wrap(machinecontroller.DeployMachineDeployments(ctx), "failed to deploy Machines")
}
12 changes: 11 additions & 1 deletion pkg/templates/machinecontroller/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,17 @@ func WaitForMachineController(client dynclient.Client) error {
return false, nil
}

return machineControllerPods.Items[0].Status.Phase == corev1.PodRunning, nil
mcpod := machineControllerPods.Items[0]

if mcpod.Status.Phase == corev1.PodRunning {
for _, podcond := range mcpod.Status.Conditions {
if podcond.Type == corev1.PodReady && podcond.Status == corev1.ConditionTrue {
return true, nil
}
}
}

return false, nil
})
}

Expand Down
42 changes: 42 additions & 0 deletions pkg/templates/machinecontroller/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ package machinecontroller

import (
"context"
"time"

"github.com/pkg/errors"

"github.com/kubermatic/kubeone/pkg/util"

"k8s.io/apimachinery/pkg/runtime"
dynclient "sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -29,3 +34,40 @@ func simpleCreateOrUpdate(ctx context.Context, client dynclient.Client, obj runt
_, err := controllerutil.CreateOrUpdate(ctx, client, obj, okFunc)
return err
}

// EnsureMachineController install/update machine-controller
func EnsureMachineController(ctx *util.Context) error {
if !*ctx.Cluster.MachineController.Deploy {
ctx.Logger.Info("Skipping machine-controller deployment because it was disabled in configuration.")
return nil
}

ctx.Logger.Infoln("Installing machine-controller…")
if err := Deploy(ctx); err != nil {
return errors.Wrap(err, "failed to deploy machine-controller")
}

ctx.Logger.Infoln("Installing machine-controller webhooks…")
if err := DeployWebhookConfiguration(ctx); err != nil {
return errors.Wrap(err, "failed to deploy machine-controller webhook configuration")
}

return nil
}

// WaitReady waits for machine-controller and its webhook to became ready
func WaitReady(ctx *util.Context) error {
ctx.Logger.Infoln("Waiting for machine-controller to come up…")

// Wait a bit to let scheduler to react
time.Sleep(10 * time.Second)

if err := WaitForWebhook(ctx.DynamicClient); err != nil {
return errors.Wrap(err, "machine-controller-webhook did not come up")
}

if err := WaitForMachineController(ctx.DynamicClient); err != nil {
return errors.Wrap(err, "machine-controller did not come up")
}
return nil
}
12 changes: 11 additions & 1 deletion pkg/templates/machinecontroller/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,17 @@ func WaitForWebhook(client dynclient.Client) error {
return false, nil
}

return webhookPods.Items[0].Status.Phase == corev1.PodRunning, nil
whpod := webhookPods.Items[0]

if whpod.Status.Phase == corev1.PodRunning {
for _, podcond := range whpod.Status.Conditions {
if podcond.Type == corev1.PodReady && podcond.Status == corev1.ConditionTrue {
return true, nil
}
}
}

return false, nil
})
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/upgrader/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/pkg/errors"

"github.com/kubermatic/kubeone/pkg/features"
"github.com/kubermatic/kubeone/pkg/templates/machinecontroller"
"github.com/kubermatic/kubeone/pkg/util"
)

Expand All @@ -43,6 +44,8 @@ func Upgrade(ctx *util.Context) error {
{fn: upgradeLeader, errMsg: "unable to upgrade leader control plane"},
{fn: upgradeFollower, errMsg: "unable to upgrade follower control plane"},
{fn: features.Activate, errMsg: "unable to activate features"},
{fn: machinecontroller.EnsureMachineController, errMsg: "failed to update machine-controller"},
{fn: machinecontroller.WaitReady, errMsg: "failed to wait for machine-controller"},
{fn: upgradeMachineDeployments, errMsg: "unable to upgrade MachineDeployments"},
}

Expand Down

0 comments on commit a6147b3

Please sign in to comment.