Skip to content

Commit

Permalink
neonvm-controller: Set podName only while Pending (#973)
Browse files Browse the repository at this point in the history
Fixes #967, extracted from #970.

In short, the state machine becomes simpler if we only set the VM's pod
name when it's in Pending. This gives us a couple things:

1. When the VM is Failed or Succeeded, we can un-set the pod name and it
   will be stable. This is what fixes #967
2. It gives us a consistent place to set status fields relating to a
   particular pod *before* creating the pod. This is why it's helpful
   for #970
  • Loading branch information
sharnoff authored Jun 20, 2024
1 parent 936a238 commit 031c40a
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions neonvm/controllers/vm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,6 @@ func (r *VMReconciler) doReconcile(ctx context.Context, vm *vmv1.VirtualMachine)
vm.Status.SSHSecretName = fmt.Sprintf("ssh-neonvm-%s", vm.Name)
}

// Generate runner pod name
if len(vm.Status.PodName) == 0 {
vm.Status.PodName = names.SimpleNameGenerator.GenerateName(fmt.Sprintf("%s-", vm.Name))
// Update the .Status on API Server to avoid creating multiple pods for a single VM
// See https://github.com/neondatabase/autoscaling/issues/794 for the context
if err := r.Status().Update(ctx, vm); err != nil {
return fmt.Errorf("Failed to update VirtualMachine status: %w", err)
}
}

switch vm.Status.Phase {

case "":
Expand Down Expand Up @@ -369,6 +359,16 @@ func (r *VMReconciler) doReconcile(ctx context.Context, vm *vmv1.VirtualMachine)
// VirtualMachine just created, change Phase to "Pending"
vm.Status.Phase = vmv1.VmPending
case vmv1.VmPending:
// Generate runner pod name
if len(vm.Status.PodName) == 0 {
vm.Status.PodName = names.SimpleNameGenerator.GenerateName(fmt.Sprintf("%s-", vm.Name))
// Update the .Status on API Server to avoid creating multiple pods for a single VM
// See https://github.com/neondatabase/autoscaling/issues/794 for the context
if err := r.Status().Update(ctx, vm); err != nil {
return fmt.Errorf("Failed to update VirtualMachine status: %w", err)
}
}

// Check if the runner pod already exists, if not create a new one
vmRunner := &corev1.Pod{}
err := r.Get(ctx, types.NamespacedName{Name: vm.Status.PodName, Namespace: vm.Namespace}, vmRunner)
Expand Down

0 comments on commit 031c40a

Please sign in to comment.