Skip to content

Commit

Permalink
correct the case of no pod
Browse files Browse the repository at this point in the history
  • Loading branch information
vutuong committed Dec 19, 2020
1 parent b4b7cf0 commit 64c1259
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
6 changes: 3 additions & 3 deletions config/samples/podmig_v1_podmigration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ spec:
labels:
app: redis
annotations:
snapshotPolicy: "abcb"
snapshotPath: "/var/lib/kubelet/migration/mig61"
snapshotPolicy: "checkpoint"
snapshotPath: "/var/lib/kubelet/migration"
spec:
containers:
- name: redis
Expand All @@ -29,4 +29,4 @@ spec:
resources:
limits:
memory: "128Mi"
cpu: "500m"
cpu: "500m"
33 changes: 30 additions & 3 deletions controllers/podmigration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ func (r *PodmigrationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error
log.Info("", "disired pod ", pod)
switch len(childPods.Items) {
case 0:

if annotations["snapshotPath"] == "" || annotations["snapshotPolicy"] == "" {
if annotations["snapshotPolicy"] == "" || annotations["snapshotPath"] == "" {
log.Info("", "snapshotPolicy and snapshotPath is not given", annotations["snapshotPath"])
} else {
} else if annotations["snapshotPolicy"] == "restore" {
// snapshotPath and snapshotPolicy is given, should check if snapshotPath is exist or not
_, err := os.Stat(annotations["snapshotPath"])
if os.IsNotExist(err) {
Expand All @@ -98,11 +97,39 @@ func (r *PodmigrationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error
// snapshotPath found, logging
log.Info("", "snapshotPath found, we will start conatainer from checkpoint", annotations["snapshotPath"])
}
} else {
// In case there is no Pod running, we onnly accept snapshot = "restore"
// Reset Annotations.snapshotPolicy and snapshotPath in other case
pod.ObjectMeta.Annotations["snapshotPolicy"] = ""
pod.ObjectMeta.Annotations["snapshotPath"] = ""
}
if err := r.Create(ctx, pod); err != nil {
log.Error(err, "unable to create Pod for MigratingPod", "pod", pod)
return ctrl.Result{}, err
}
case 1:
// if we should restore, check the snapshotPath
// TODO(Tuong): clean code, not duplicate
// if annotations["snapshotPolicy"] == "restore" {
// // snapshotPath and snapshotPolicy is given, should check if snapshotPath is exist or not
// _, err := os.Stat(annotations["snapshotPath"])
// if os.IsNotExist(err) {
// // if snapshotPath not found, delete snapshotPolicy and snapshotPath
// // Pod then start as normal
// pod.ObjectMeta.Annotations["snapshotPolicy"] = ""
// pod.ObjectMeta.Annotations["snapshotPath"] = ""
// log.Info("", "snapshotPath not found, we will start pod as normal", annotations["snapshotPath"])

// } else {
// // snapshotPath found, logging
// log.Info("", "snapshotPath found, we will start conatainer from checkpoint", annotations["snapshotPath"])
// }
// }
// if err := r.Create(ctx, pod); err != nil {
// log.Error(err, "unable to create Pod for MigratingPod", "pod", pod)
// return ctrl.Result{}, err
// }

default:
log.Info("", "no action", annotations["snapshotPath"])

Expand Down

0 comments on commit 64c1259

Please sign in to comment.