Skip to content

Commit

Permalink
Add - delete source pod after restoring
Browse files Browse the repository at this point in the history
  • Loading branch information
vutuong committed Jan 17, 2021
1 parent 1c39ba4 commit 13dfd70
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
7 changes: 4 additions & 3 deletions config/samples/2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ metadata:
spec:
containers:
- name: vlc
image: lroktu/vlc-server:latest
image: tuongvx/vlc-app:latest
ports:
- containerPort: 8080
protocol: TCP
args: ["big_buck_bunny.mp4","--loop","--sout", "#transcode{scodec=none}:http{mux=ffmpeg{mux=flv},dst=:8080/}"]
#args: ["big_buck_bunny.mp4","--loop","--sout", "#transcode{scodec=none}:http{mux=ffmpeg{mux=flv},dst=:8080/}"]
args: ["frozen.mp4","--loop","--sout", "#transcode{scodec=none}:http{mux=ffmpeg{mux=flv},dst=:8080/}"]
nodeSelector:
kubernetes.io/hostname: worker1
kubernetes.io/hostname: worker2
4 changes: 2 additions & 2 deletions config/samples/test2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ spec:
spec:
containers:
- name: vlc
image: lroktu/vlc-server:latest
image: tuongvx/vlc-app:latest
ports:
- containerPort: 8080
protocol: TCP
#args: ["big_buck_bunny.mp4","--loop","--sout", "#transcode{scodec=none}:http{mux=ffmpeg{mux=flv},dst=:8080/}"]
nodeSelector:
kubernetes.io/hostname: worker2
kubernetes.io/hostname: worker1
18 changes: 15 additions & 3 deletions controllers/podmigration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,27 @@ func (r *PodmigrationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error
}
log.Info("", "Live-migration", "checkpointPath"+checkpointPath)
log.Info("", "Live-migration", "Step 2 - Wait until checkpoint info are created - completed")

// time.Sleep(10)
// Step3: restore destPod from sourcePod checkpoted info
newPod, err := r.restorePod(ctx, pod, annotations["sourcePod"], checkpointPath)
if err != nil {
log.Error(err, "unable to restore", "pod", pod)
return ctrl.Result{}, err
}
log.Info("", "Live-migration", "Step 3 - Restore destPod from sourcePod's checkpointed info - completed")
time.Sleep(10)

time.Sleep(5)
// Step4: Clean checkpointpod process and checkpointPath
if err := r.removeCheckpointPod(ctx, copySourcePod, "/var/lib/kubelet/migration/kkk", newPod.Name, req.Namespace); err != nil {
log.Error(err, "unable to remove checkpoint", "pod", pod)
return ctrl.Result{}, err
}
log.Info("", "Live-migration", "Step 4 - Clean checkpointPod process and checkpointPath completed")

// step5: Delete source Pod
if err := r.deletePod(ctx, sourcePod); err != nil {
log.Error(err, "unable to delete", "source pod", sourcePod)
return ctrl.Result{}, err
}
return ctrl.Result{}, nil
}
if count == 0 {
Expand Down Expand Up @@ -219,6 +224,13 @@ func (r *PodmigrationReconciler) updateMultiPod(ctx context.Context, replicas in
return nil
}

func (r *PodmigrationReconciler) deletePod(ctx context.Context, pod *corev1.Pod) error {
if err := r.Delete(ctx, pod); err != nil {
return err
}
return nil
}

func (r *PodmigrationReconciler) checkpointPod(ctx context.Context, pod *corev1.Pod) error {
snapshotPolicy := "checkpoint"
snapshotPath := "/var/lib/kubelet/migration/kkk"
Expand Down

0 comments on commit 13dfd70

Please sign in to comment.