Skip to content
This repository has been archived by the owner on Apr 7, 2020. It is now read-only.

Commit

Permalink
Correctly handle worker deletion process for hibernated shoots
Browse files Browse the repository at this point in the history
```improvement user
All worker controllers are now making sure that the machine-controller-manager is awake before deleting the machines (in case the shoot was hibernated before). Also, they now ensure that the required RBAC roles have been created before starting the deletion process.
```
  • Loading branch information
rfranzke committed May 30, 2019
1 parent d7af523 commit 3132353
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
17 changes: 17 additions & 0 deletions pkg/controller/worker/genericactuator/actuator_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import (

gardencorev1alpha1helper "github.com/gardener/gardener/pkg/apis/core/v1alpha1/helper"
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
kutil "github.com/gardener/gardener/pkg/utils/kubernetes"
machinev1alpha1 "github.com/gardener/machine-controller-manager/pkg/apis/machine/v1alpha1"
"github.com/pkg/errors"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
Expand All @@ -45,6 +47,21 @@ func (a *genericActuator) Delete(ctx context.Context, worker *extensionsv1alpha1
return errors.Wrapf(err, "could not instantiate actuator context")
}

// Make sure machine-controller-manager is awake before deleting the machines.
deployment := &appsv1.Deployment{}
if err := a.client.Get(ctx, kutil.Key(worker.Namespace, a.mcmName), deployment); err != nil {
return err
}
if err := util.ScaleDeployment(ctx, a.client, deployment, 1); err != nil {
return err
}

// Make sure that all RBAC roles required by the machine-controller-manager exist in the shoot cluster.
// This code can be removed as soon as the RBAC roles are managed by the gardener-resource-manager.
if err := a.applyMachineControllerManagerShootChart(ctx, workerDelegate, worker, cluster); err != nil {
return errors.Wrapf(err, "could not apply machine-controller-manager shoot chart")
}

// Mark all existing machines to become forcefully deleted.
a.logger.Info("Deleting all machines", "worker", fmt.Sprintf("%s/%s", worker.Namespace, worker.Name))
if err := a.markAllMachinesForcefulDeletion(ctx, worker.Namespace); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,27 @@ func (a *genericActuator) deployMachineControllerManager(ctx context.Context, wo
}

if !controller.IsHibernated(cluster.Shoot) {
shootClients, err := util.NewClientsForShoot(ctx, a.client, workerObj.Namespace, client.Options{})
if err != nil {
if err := a.applyMachineControllerManagerShootChart(ctx, workerDelegate, workerObj, cluster); err != nil {
return err
}
}

mcmShootValues, err := workerDelegate.GetMachineControllerManagerShootChartValues(ctx)
if err != nil {
return err
}
return nil
}

if err := a.mcmShootChart.Apply(ctx, shootClients.GardenerClientset(), shootClients.ChartApplier(), metav1.NamespaceSystem, cluster.Shoot, a.imageVector, nil, mcmShootValues); err != nil {
return errors.Wrapf(err, "could not apply MCM chart in seed for worker '%s'", util.ObjectName(workerObj))
}
func (a *genericActuator) applyMachineControllerManagerShootChart(ctx context.Context, workerDelegate WorkerDelegate, workerObj *extensionsv1alpha1.Worker, cluster *controller.Cluster) error {
shootClients, err := util.NewClientsForShoot(ctx, a.client, workerObj.Namespace, client.Options{})
if err != nil {
return err
}

mcmShootValues, err := workerDelegate.GetMachineControllerManagerShootChartValues(ctx)
if err != nil {
return err
}

if err := a.mcmShootChart.Apply(ctx, shootClients.GardenerClientset(), shootClients.ChartApplier(), metav1.NamespaceSystem, cluster.Shoot, a.imageVector, nil, mcmShootValues); err != nil {
return errors.Wrapf(err, "could not apply MCM chart in seed for worker '%s'", util.ObjectName(workerObj))
}

return nil
Expand Down

0 comments on commit 3132353

Please sign in to comment.