Skip to content

Commit 6f84df9

Browse files
authored
Merge pull request #1173 from apricote/release-0.5-cherry-pick-909
🐛 update logic to support more instance state
2 parents 8bf77d2 + 02745bb commit 6f84df9

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

api/v1alpha3/types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,6 @@ func (r SecurityGroupRule) Equal(x SecurityGroupRule) bool {
227227
type InstanceState string
228228

229229
var (
230-
// InstanceStateBuilding is the string representing an instance in a building state.
231-
InstanceStateBuilding = InstanceState("BUILDING")
232-
233230
// InstanceStateActive is the string representing an instance in an active state.
234231
InstanceStateActive = InstanceState("ACTIVE")
235232

@@ -241,6 +238,9 @@ var (
241238

242239
// InstanceStateShutoff is the string representing an instance in a shutoff state.
243240
InstanceStateShutoff = InstanceState("SHUTOFF")
241+
242+
// InstanceStateDeleted is the string representing an instance in a deleted state.
243+
InstanceStateDeleted = InstanceState("DELETED")
244244
)
245245

246246
// Bastion represents basic information about the bastion node.

api/v1alpha4/types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,6 @@ func (r SecurityGroupRule) Equal(x SecurityGroupRule) bool {
279279
type InstanceState string
280280

281281
var (
282-
// InstanceStateBuilding is the string representing an instance in a building state.
283-
InstanceStateBuilding = InstanceState("BUILDING")
284-
285282
// InstanceStateActive is the string representing an instance in an active state.
286283
InstanceStateActive = InstanceState("ACTIVE")
287284

@@ -293,6 +290,9 @@ var (
293290

294291
// InstanceStateShutoff is the string representing an instance in a shutoff state.
295292
InstanceStateShutoff = InstanceState("SHUTOFF")
293+
294+
// InstanceStateDeleted is the string representing an instance in a deleted state.
295+
InstanceStateDeleted = InstanceState("DELETED")
296296
)
297297

298298
// Bastion represents basic information about the bastion node.

controllers/openstackmachine_controller.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ type OpenStackMachineReconciler struct {
6464

6565
const (
6666
waitForClusterInfrastructureReadyDuration = 15 * time.Second
67+
waitForInstanceBecomeActiveToReconcile = 60 * time.Second
6768
)
6869

6970
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=openstackmachines,verbs=get;list;watch;create;update;patch;delete
@@ -343,11 +344,19 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, logger
343344
case infrav1.InstanceStateActive:
344345
logger.Info("Machine instance is ACTIVE", "instance-id", instanceStatus.ID())
345346
openStackMachine.Status.Ready = true
346-
case infrav1.InstanceStateBuilding:
347-
logger.Info("Machine instance is BUILDING", "instance-id", instanceStatus.ID())
348-
default:
347+
case infrav1.InstanceStateError:
348+
// Error is unexpected, thus we report error and never retry
349349
handleUpdateMachineError(logger, openStackMachine, errors.Errorf("OpenStack instance state %q is unexpected", instanceStatus.State()))
350350
return ctrl.Result{}, nil
351+
case infrav1.InstanceStateDeleted:
352+
// we should avoid further actions for DELETED VM
353+
logger.Info("Instance state is DELETED, no actions")
354+
return ctrl.Result{}, nil
355+
default:
356+
// The other state is normal (for example, migrating, shutoff) but we don't want to proceed until it's ACTIVE
357+
// due to potential conflict or unexpected actions
358+
logger.Info("Waiting for instance to become ACTIVE", "instance-id", instanceStatus.ID(), "status", instanceStatus.State())
359+
return ctrl.Result{RequeueAfter: waitForInstanceBecomeActiveToReconcile}, nil
351360
}
352361

353362
if openStackCluster.Spec.ManagedAPIServerLoadBalancer {

0 commit comments

Comments
 (0)