Skip to content

Commit 3cfd06c

Browse files
Fix(tinkerbell): Use cluster spec for worker maxSurge validation instead of generated CAPI object (#10465)
Co-authored-by: rajeshvenkata <rajesh.venkat.p@gmail.com>
1 parent 2039faa commit 3cfd06c

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

pkg/providers/tinkerbell/reconciler/reconciler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,9 @@ func (r *Reconciler) validateHardwareReqForMachineDeployments(ctx context.Contex
441441
}
442442
}
443443
if currentMachineDeployment != nil && currentMachineDeployment.Spec.Template.Spec.InfrastructureRef.Name != wg.MachineDeployment.Spec.Template.Spec.InfrastructureRef.Name {
444-
upgradeStrategy := wg.MachineDeployment.Spec.Strategy
445-
if upgradeStrategy != nil && upgradeStrategy.Type == clusterv1.RollingUpdateMachineDeploymentStrategyType {
446-
maxSurge = int(upgradeStrategy.RollingUpdate.MaxSurge.IntVal)
444+
upgradeStrategy := workerNodeGroup.UpgradeRolloutStrategy
445+
if upgradeStrategy != nil && upgradeStrategy.Type == anywherev1.RollingUpdateStrategyType {
446+
maxSurge = upgradeStrategy.RollingUpdate.MaxSurge
447447
}
448448
if err := requirements.Add(tinkerbellClusterSpec.WorkerNodeGroupMachineConfig(workerNodeGroup).Spec.HardwareSelector, maxSurge); err != nil {
449449
return nil, err

pkg/providers/tinkerbell/reconciler/reconciler_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,3 +1857,51 @@ func tinkWorker(clusterName string, opts ...workerOpt) *tinkerbell.Workers {
18571857
}
18581858
return w
18591859
}
1860+
1861+
func TestReconcilerValidateHardwareWorkerRollingUpdateMaxSurgeRespected(t *testing.T) {
1862+
tt := newReconcilerTest(t)
1863+
1864+
tt.eksaSupportObjs = append(tt.eksaSupportObjs, tt.kcp)
1865+
1866+
// Create existing MachineDeployment with a DIFFERENT InfrastructureRef name
1867+
// to simulate a template change (e.g., from a previous version)
1868+
worker := tinkWorker(tt.cluster.Name, func(w *tinkerbell.Workers) {
1869+
w.Groups[0].MachineDeployment.Name = "workload-cluster-md-0"
1870+
w.Groups[0].MachineDeployment.Spec.Template.Spec.InfrastructureRef.Name = "workload-cluster-md-0-0"
1871+
w.Groups[0].ProviderMachineTemplate.Name = "workload-cluster-md-0-0"
1872+
})
1873+
tt.eksaSupportObjs = append(tt.eksaSupportObjs, worker.Groups[0].MachineDeployment)
1874+
tt.eksaSupportObjs = append(tt.eksaSupportObjs, worker.Groups[0].ProviderMachineTemplate)
1875+
1876+
tt.eksaSupportObjs = append(tt.eksaSupportObjs, tinkHardware("hw1", "worker"))
1877+
tt.eksaSupportObjs = append(tt.eksaSupportObjs, tinkHardware("hw-cp", "cp"))
1878+
1879+
tt.withFakeClient()
1880+
1881+
logger := test.NewNullLogger()
1882+
scope := tt.buildScope()
1883+
1884+
scope.ClusterSpec.Config.Cluster.Spec.WorkerNodeGroupConfigurations[0].UpgradeRolloutStrategy = &anywherev1.WorkerNodesUpgradeRolloutStrategy{
1885+
Type: anywherev1.RollingUpdateStrategyType,
1886+
RollingUpdate: &anywherev1.WorkerNodesRollingUpdateParams{
1887+
MaxSurge: 3,
1888+
MaxUnavailable: 0,
1889+
},
1890+
}
1891+
1892+
wngRef := scope.ClusterSpec.Config.Cluster.Spec.WorkerNodeGroupConfigurations[0].MachineGroupRef.Name
1893+
scope.ClusterSpec.Config.TinkerbellMachineConfigs[wngRef].Spec.OSImageURL = "new-os-image"
1894+
1895+
_, err := tt.reconciler().GenerateSpec(tt.ctx, logger, scope)
1896+
tt.Expect(err).NotTo(HaveOccurred())
1897+
1898+
_, err = tt.reconciler().DetectOperation(tt.ctx, logger, scope)
1899+
tt.Expect(err).NotTo(HaveOccurred())
1900+
1901+
result, err := tt.reconciler().ValidateHardware(tt.ctx, logger, scope)
1902+
1903+
tt.Expect(err).ToNot(BeNil())
1904+
tt.Expect(result).To(Equal(controller.Result{}))
1905+
tt.Expect(*tt.cluster.Status.FailureMessage).To(ContainSubstring("minimum hardware count not met for selector"))
1906+
tt.Expect(tt.cluster.Status.FailureReason).To(HaveValue(Equal(anywherev1.HardwareInvalidReason)))
1907+
}

0 commit comments

Comments
 (0)