Skip to content

Commit

Permalink
Add first logic to reate pod from checkpoint or not
Browse files Browse the repository at this point in the history
  • Loading branch information
vutuong committed Dec 17, 2020
1 parent c91bdf1 commit b4b7cf0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
13 changes: 8 additions & 5 deletions config/samples/podmig_v1_podmigration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ metadata:
name: test
spec:
template:
metadata:
labels:
app: redis
annotations:
snapshotPolicy: "abcb"
snapshotPath: "/var/lib/kubelet/migration/mig61"
spec:
metadata:
labels:
app: redis
containers:
- name: redis
image: redis
ports:
- containerPort: 6379
protocol: tcp
- containerPort: 6379
protocol: TCP
resources:
limits:
memory: "128Mi"
Expand Down
35 changes: 35 additions & 0 deletions controllers/podmigration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controllers

import (
"context"
"os"

"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -71,7 +72,41 @@ func (r *PodmigrationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error
if err != nil {
return ctrl.Result{}, err
}

template := &migratingPod.Spec.Template
annotations := getPodsAnnotationSet(template)
// annotations := template.ObjectMeta
log.Info("", "annotations ", annotations["snapshotPath"])
log.Info("", "disired pod ", childPods)
log.Info("", "disired pod ", pod)
switch len(childPods.Items) {
case 0:

if annotations["snapshotPath"] == "" || annotations["snapshotPolicy"] == "" {
log.Info("", "snapshotPolicy and snapshotPath is not given", annotations["snapshotPath"])
} else {
// 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"])

}
return ctrl.Result{}, nil
}

Expand Down

0 comments on commit b4b7cf0

Please sign in to comment.