Skip to content

Commit 195aebb

Browse files
committed
Fix machineDeploymentStrategy
1 parent e4cee5c commit 195aebb

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

pkg/controller/worker/machines.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ import (
2626
"github.com/gardener/gardener/extensions/pkg/controller/worker"
2727
genericworkeractuator "github.com/gardener/gardener/extensions/pkg/controller/worker/genericactuator"
2828
corev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
29+
gardencorev1beta1helper "github.com/gardener/gardener/pkg/apis/core/v1beta1/helper"
2930
"github.com/gardener/gardener/pkg/client/kubernetes"
31+
machinev1alpha1 "github.com/gardener/machine-controller-manager/pkg/apis/machine/v1alpha1"
3032
mcmv1alpha1 "github.com/gardener/machine-controller-manager/pkg/apis/machine/v1alpha1"
3133
corev1 "k8s.io/api/core/v1"
34+
"k8s.io/utils/ptr"
3235
"sigs.k8s.io/controller-runtime/pkg/client"
3336

3437
"github.com/23technologies/gardener-extension-provider-hcloud/charts"
@@ -147,6 +150,8 @@ func (w *workerDelegate) generateMachineConfig(ctx context.Context) error {
147150
}
148151

149152
for _, pool := range w.worker.Spec.Pools {
153+
zoneLen := int32(len(pool.Zones)) // #nosec: G115 - We validate if num pool zones exceeds max_int32.
154+
150155
workerPoolHash, err := worker.WorkerPoolHash(pool, w.cluster, nil, nil)
151156
if err != nil {
152157
return err
@@ -167,8 +172,8 @@ func (w *workerDelegate) generateMachineConfig(ctx context.Context) error {
167172
return err
168173
}
169174

170-
for _, zone := range pool.Zones {
171-
175+
for zoneIndex, zone := range pool.Zones {
176+
zoneIdx := int32(zoneIndex) // #nosec: G115 - We validate if num pool zones exceeds max_int32.
172177
secretMap := map[string]interface{}{
173178
"userData": string(userData),
174179
}
@@ -213,12 +218,39 @@ func (w *workerDelegate) generateMachineConfig(ctx context.Context) error {
213218
deploymentName := fmt.Sprintf("%s-%s-%s", w.worker.Namespace, pool.Name, zone)
214219
className := fmt.Sprintf("%s-%s", deploymentName, workerPoolHash)
215220

221+
updateConfiguration := machinev1alpha1.UpdateConfiguration{
222+
MaxUnavailable: ptr.To(worker.DistributePositiveIntOrPercent(zoneIdx, pool.MaxUnavailable, zoneLen, pool.Minimum)),
223+
MaxSurge: ptr.To(worker.DistributePositiveIntOrPercent(zoneIdx, pool.MaxSurge, zoneLen, pool.Maximum)),
224+
}
225+
226+
machineDeploymentStrategy := machinev1alpha1.MachineDeploymentStrategy{
227+
Type: machinev1alpha1.RollingUpdateMachineDeploymentStrategyType,
228+
RollingUpdate: &machinev1alpha1.RollingUpdateMachineDeployment{
229+
UpdateConfiguration: updateConfiguration,
230+
},
231+
}
232+
233+
if gardencorev1beta1helper.IsUpdateStrategyInPlace(pool.UpdateStrategy) {
234+
machineDeploymentStrategy = machinev1alpha1.MachineDeploymentStrategy{
235+
Type: machinev1alpha1.InPlaceUpdateMachineDeploymentStrategyType,
236+
InPlaceUpdate: &machinev1alpha1.InPlaceUpdateMachineDeployment{
237+
UpdateConfiguration: updateConfiguration,
238+
OrchestrationType: machinev1alpha1.OrchestrationTypeAuto,
239+
},
240+
}
241+
242+
if gardencorev1beta1helper.IsUpdateStrategyManualInPlace(pool.UpdateStrategy) {
243+
machineDeploymentStrategy.InPlaceUpdate.OrchestrationType = machinev1alpha1.OrchestrationTypeManual
244+
}
245+
}
246+
216247
machineDeployments = append(machineDeployments, worker.MachineDeployment{
217248
Name: deploymentName,
218249
ClassName: className,
219250
SecretName: className,
220251
Minimum: pool.Minimum,
221252
Maximum: pool.Maximum,
253+
Strategy: machineDeploymentStrategy,
222254
Labels: pool.Labels,
223255
Annotations: pool.Annotations,
224256
Taints: pool.Taints,

0 commit comments

Comments
 (0)