@@ -473,7 +473,7 @@ func SyncMachineTaints(
473473 return toBeUpdated
474474}
475475
476- // machineCreateErrorHandler TODO
476+ // machineCreateErrorHandler handles errors when machine creation does not succeed
477477func (c * controller ) machineCreateErrorHandler (ctx context.Context , machine * v1alpha1.Machine , createMachineResponse * driver.CreateMachineResponse , err error ) (machineutils.RetryPeriod , error ) {
478478 var (
479479 retryRequired = machineutils .MediumRetry
@@ -491,7 +491,7 @@ func (c *controller) machineCreateErrorHandler(ctx context.Context, machine *v1a
491491 lastKnownState = createMachineResponse .LastKnownState
492492 }
493493
494- c .machineStatusUpdate (
494+ statusUpdErr := c .machineStatusUpdate (
495495 ctx ,
496496 machine ,
497497 v1alpha1.LastOperation {
@@ -507,8 +507,23 @@ func (c *controller) machineCreateErrorHandler(ctx context.Context, machine *v1a
507507 },
508508 lastKnownState ,
509509 )
510+ return retryRequired , statusUpdErr
511+ }
512+
513+ // adjustCreateRetryRequired adjusts the retry period if needed so that we don't have a case where the machine is reconciled after machineCreationTimeout
514+ // if the retry period is too large so that, it is adjusted so that it causes a reconcile at the machineCreationTimeout
515+ // if the machineCreationTimeout has already passed, return `ShortRetry` so that the machine is immediately reconciled
516+ func (c * controller ) adjustCreateRetryRequired (machine * v1alpha1.Machine , retryRequired machineutils.RetryPeriod ) machineutils.RetryPeriod {
517+ adjustedRetry := retryRequired
518+ machineCreationDeadline := machine .CreationTimestamp .Time .Add (c .getEffectiveCreationTimeout (machine ).Duration )
519+ if time .Now ().After (machineCreationDeadline ) {
520+ adjustedRetry = machineutils .ShortRetry
521+ } else if time .Now ().Add (time .Duration (retryRequired )).After (machineCreationDeadline ) {
522+ // Machine will reconcile after create deadline. Adapt RetryPeriod to reconcile machine at deadline
523+ adjustedRetry = machineutils .RetryPeriod (machineCreationDeadline .Sub (time .Now ()))
524+ }
510525
511- return retryRequired , nil
526+ return adjustedRetry
512527}
513528
514529func (c * controller ) machineStatusUpdate (
@@ -974,7 +989,7 @@ func isConditionEmpty(condition v1.NodeCondition) bool {
974989 return condition == v1.NodeCondition {}
975990}
976991
977- // initializes err and description with the passed string message
992+ // printLogInitError initializes err and description with the passed string message
978993func printLogInitError (s string , err * error , description * string , machine * v1alpha1.Machine ) {
979994 klog .Warningf (s + " machine: %q " , machine .Name )
980995 * err = fmt .Errorf (s + " %s" , machineutils .InitiateVMDeletion )
@@ -1304,7 +1319,7 @@ func (c *controller) getEffectiveHealthTimeout(machine *v1alpha1.Machine) *metav
13041319 return effectiveHealthTimeout
13051320}
13061321
1307- // getEffectiveHealthTimeout returns the creationTimeout set on the machine-object, otherwise returns the timeout set using the global-flag.
1322+ // getEffectiveCreationTimeout returns the creationTimeout set on the machine-object, otherwise returns the timeout set using the global-flag.
13081323func (c * controller ) getEffectiveCreationTimeout (machine * v1alpha1.Machine ) * metav1.Duration {
13091324 var effectiveCreationTimeout * metav1.Duration
13101325 if machine .Spec .MachineConfiguration != nil && machine .Spec .MachineConfiguration .MachineCreationTimeout != nil {
@@ -1326,6 +1341,11 @@ func (c *controller) getEffectiveNodeConditions(machine *v1alpha1.Machine) *stri
13261341 return effectiveNodeConditions
13271342}
13281343
1344+ func (c * controller ) getCreationContext (parentCtx context.Context , machine * v1alpha1.Machine ) (context.Context , context.CancelFunc ) {
1345+ timeOutDuration := c .getEffectiveCreationTimeout (machine ).Duration
1346+ return context .WithDeadline (parentCtx , machine .CreationTimestamp .Time .Add (timeOutDuration ))
1347+ }
1348+
13291349// UpdateNodeTerminationCondition updates termination condition on the node object
13301350func (c * controller ) UpdateNodeTerminationCondition (ctx context.Context , machine * v1alpha1.Machine ) error {
13311351 if machine .Status .CurrentStatus .Phase == "" || machine .Status .CurrentStatus .Phase == v1alpha1 .MachineCrashLoopBackOff {
0 commit comments