Skip to content

Commit

Permalink
Add GUI source code and fix the old source to match GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
vutuong committed Jan 20, 2021
1 parent baff3f6 commit 7c50d65
Show file tree
Hide file tree
Showing 36 changed files with 14,967 additions and 39 deletions.
15 changes: 11 additions & 4 deletions api-server/endpoints/podmigration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package endpoints

import (
"fmt"
"strings"

v1 "github.com/SSU-DCN/podmigration-operator/api/v1"
"github.com/emicklei/go-restful"
Expand Down Expand Up @@ -56,7 +57,12 @@ func (pe *PodmigrationEndpoint) list(request *restful.Request, response *restful
func (pe *PodmigrationEndpoint) create(request *restful.Request, response *restful.Response) {
pm := new(Podmigration)
err := request.ReadEntity(pm)

pm.Action = strings.ToLower(pm.Action)
fmt.Println(pm)
fmt.Println(pm.Action)
fmt.Println(pm.SourcePod)
fmt.Println(pm)
fmt.Println("what the hell")
if err != nil {
writeError(response, 400, Error{
Title: "Bad Request",
Expand All @@ -76,7 +82,9 @@ func (pe *PodmigrationEndpoint) create(request *restful.Request, response *restf
// Check whether sourcePod of live-migration is exist or not
var sourcePod *corev1.Pod
var template corev1.PodTemplateSpec
if pm.Action == "live-migration" && pm.SourcePod != "" {
// if pm.Action == "live-migration" && pm.SourcePod != "" {
if pm.SourcePod != "" {
fmt.Println(pm.SourcePod)
var childPods corev1.PodList
if err := pe.client.List(request.Request.Context(), &childPods, client.InNamespace(namespace)); err != nil {
writeError(response, 400, Error{
Expand All @@ -88,7 +96,6 @@ func (pe *PodmigrationEndpoint) create(request *restful.Request, response *restf

if len(childPods.Items) > 0 {
for _, pod := range childPods.Items {
fmt.Println(pod.Name)
if pod.Name == pm.SourcePod && pod.Status.Phase == "Running" {
sourcePod = pod.DeepCopy()
container := sourcePod.Spec.Containers[0]
Expand Down Expand Up @@ -135,7 +142,7 @@ func (pe *PodmigrationEndpoint) create(request *restful.Request, response *restf
},
}
}
// fmt.Println(template)
fmt.Println(template)
// fmt.Println(pm.DestHost)
// fmt.Println(template.Spec.NodeSelector)
obj := &v1.Podmigration{
Expand Down
91 changes: 56 additions & 35 deletions controllers/podmigration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,30 +98,36 @@ func (r *PodmigrationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error
log.Info("", "number of actual running pod ", count)

if annotations["snapshotPolicy"] == "live-migration" && annotations["sourcePod"] != "" {
// list source pods for live-migration
// We are live-migrate a running pod here - Hot scale
// Step1: Check source pod is exist or not clean previous source pod checkpoint/restore annotations and snapshotPath
sourcePod, err := r.checkPodExist(ctx, annotations["sourcePod"], req.Namespace)
if err != nil || sourcePod == nil {
log.Error(err, "sourcePod not exist", "pod", annotations["sourcePod"])
return ctrl.Result{}, err
}
if err := r.removeCheckpointPod(ctx, sourcePod, "/var/lib/kubelet/migration/kkk", "", req.Namespace); err != nil {
log.Error(err, "unable to remove checkpoint", "pod", sourcePod)
return ctrl.Result{}, err
}
log.Info("", "Live-migration", "Step 1 - Check source pod is exist or not - completed")
log.Info("", "sourcePod ok ", sourcePod)
log.Info("", "sourcePod status ", sourcePod.Status.Phase)

// Step1: checkpoint sourcePod
copySourcePod := sourcePod.DeepCopy()
if err := r.checkpointPod(ctx, copySourcePod); err != nil {
// Step2: checkpoint sourcePod
// copySourcePod := sourcePod.DeepCopy()
if err := r.checkpointPod(ctx, sourcePod, ""); err != nil {
log.Error(err, "unable to checkpoint", "pod", sourcePod)
return ctrl.Result{}, err
}
log.Info("", "Live-migration", "Step1 - checkpoint source Pod - completed")
log.Info("", "Live-migration", "Step 2 - checkpoint source Pod - completed")
// TODO(TUONG): make migrate all container inside Pod
// for container := range copySourcePod.Spec.Containers {
// fmt.Println(copySourcePod.Spec.Containers[container].Name)
// log.Info("", "container of pod", copySourcePod.Spec.Containers[container].Name)
// }

// Step2: wait until checkpoint info are created
container := copySourcePod.Spec.Containers[0].Name
checkpointPath := path.Join("/var/lib/kubelet/migration/kkk", strings.Split(copySourcePod.Name, "-")[0])
// Step3: wait until checkpoint info are created
container := sourcePod.Spec.Containers[0].Name
checkpointPath := path.Join("/var/lib/kubelet/migration/kkk", strings.Split(sourcePod.Name, "-")[0])
log.Info("", "live-migration pod", container)
for {
_, err := os.Stat(path.Join(checkpointPath, container, "descriptors.json"))
Expand All @@ -132,31 +138,33 @@ 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")
log.Info("", "Live-migration", "Step 3 - Wait until checkpoint info are created - completed")
// time.Sleep(10)
// Step3: restore destPod from sourcePod checkpoted info
// Step4: 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", sourcePod)
return ctrl.Result{}, err
}
log.Info("", "Live-migration", "Step 3 - Restore destPod from sourcePod's checkpointed info - completed")
log.Info("", "Live-migration", "Step 4 - Restore destPod from sourcePod's checkpointed info - completed")
// 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 {
// Step5: Clean checkpointpod process and checkpointPath
if err := r.removeCheckpointPod(ctx, sourcePod, "/var/lib/kubelet/migration/kkk", newPod.Name, req.Namespace); err != nil {
log.Error(err, "unable to remove checkpoint", "pod", sourcePod)
return ctrl.Result{}, err
}
log.Info("", "Live-migration", "Step 4 - Clean checkpointPod process and checkpointPath completed")
log.Info("", "Live-migration", "Step 5 - Clean checkpointPod process and checkpointPath - completed")

// step5: Delete source Pod
// Step6: Delete source Pod
if err := r.deletePod(ctx, sourcePod); err != nil {
log.Error(err, "unable to delete", "source pod", sourcePod)
return ctrl.Result{}, err
}
log.Info("", "Live-migration", "Step 6 - Delete the source pod - completed")
return ctrl.Result{}, nil
}
if count == 0 {
if count == 0 && annotations["snapshotPolicy"] == "restore" {
// We are restoring pods here - Warm scale
_, err := os.Stat(annotations["snapshotPath"])
if annotations["snapshotPolicy"] != "restore" && os.IsNotExist(err) {
pod.ObjectMeta.Annotations["snapshotPolicy"] = ""
Expand All @@ -166,6 +174,7 @@ func (r *PodmigrationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error
log.Error(err, "unable to create Pod for restore", "pod", pod)
return ctrl.Result{}, err
}
log.Info("", "Restore", "Step 0 - Create multiple pods from checkpoint infomation - completed")
} else if count != 0 && count != migratingPod.Spec.Replicas {
_, err := os.Stat(annotations["snapshotPath"])
if annotations["snapshotPolicy"] != "restore" && os.IsNotExist(err) {
Expand All @@ -176,22 +185,30 @@ func (r *PodmigrationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error
log.Error(err, "unable to create Pod for restore", "pod", pod)
return ctrl.Result{}, err
}
log.Info("", "Restore", "Step 0 - Scale multiple pods from checkpoint infomation - completed")
} else {
_, err := os.Stat(annotations["snapshotPath"])
if annotations["snapshotPolicy"] == "checkpoint" && !os.IsNotExist(err) {
curPod := &childPods.Items[0]
newPod := curPod.DeepCopy()
ann := newPod.ObjectMeta.Annotations
if ann == nil {
ann = make(map[string]string)
// We are checkpointing a running pod here
if annotations["snapshotPolicy"] == "checkpoint" && annotations["sourcePod"] != "" {
_, err := os.Stat(annotations["snapshotPath"])
// Step1: Check source pod is exist or not
sourcePod, err := r.checkPodExist(ctx, annotations["sourcePod"], req.Namespace)
if err != nil || sourcePod == nil {
log.Error(err, "sourcePod not exist", "pod", annotations["sourcePod"])
return ctrl.Result{}, err
}
ann["snapshotPolicy"] = "checkpoint"
ann["snapshotPath"] = annotations["snapshotPath"]
newPod.ObjectMeta.Annotations = ann
if err := r.Update(ctx, newPod); err != nil {
log.Error(err, "unable to patch annotations", "pod", pod)
log.Info("", "Checkpoint", "Step 1 - Check the snapshotPaht is exist or not - completed")
// Step2: Clean previous checkpoint folder if exist
if err := r.removeCheckpointPod(ctx, sourcePod, annotations["snapshotPath"], "", req.Namespace); err != nil {
log.Error(err, "unable to remove checkpoint", "pod", sourcePod)
return ctrl.Result{}, err
}
log.Info("", "Checkpoint", "Step 2 - Clean previous checkpoint folder if exist - completed")
// Step3: Checkpoint the source pod now
if err := r.checkpointPod(ctx, sourcePod, annotations["snapshotPath"]); err != nil {
log.Error(err, "unable to checkpoint", "pod", sourcePod)
return ctrl.Result{}, err
}
log.Info("", "Checkpoint", "Step 3 - Checkpoint source Pod and save it - completed")
}
}
return ctrl.Result{}, nil
Expand Down Expand Up @@ -233,9 +250,11 @@ func (r *PodmigrationReconciler) deletePod(ctx context.Context, pod *corev1.Pod)
return nil
}

func (r *PodmigrationReconciler) checkpointPod(ctx context.Context, pod *corev1.Pod) error {
func (r *PodmigrationReconciler) checkpointPod(ctx context.Context, pod *corev1.Pod, snapshotPath string) error {
snapshotPolicy := "checkpoint"
snapshotPath := "/var/lib/kubelet/migration/kkk"
if snapshotPath == "" {
snapshotPath = "/var/lib/kubelet/migration/kkk"
}
if err := r.updateAnnotations(ctx, pod, snapshotPolicy, snapshotPath); err != nil {
return err
}
Expand All @@ -259,10 +278,12 @@ func (r *PodmigrationReconciler) restorePod(ctx context.Context, pod *corev1.Pod
}

func (r *PodmigrationReconciler) removeCheckpointPod(ctx context.Context, pod *corev1.Pod, snapshotPathCurrent, newPodName, namespace string) error {
for {
ok, _ := r.checkPodExist(ctx, newPodName, namespace)
if ok != nil {
break
if newPodName != "" {
for {
ok, _ := r.checkPodExist(ctx, newPodName, namespace)
if ok != nil {
break
}
}
}
snapshotPolicyUpdate := ""
Expand Down
3 changes: 3 additions & 0 deletions gui/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
> 1%
last 2 versions
not dead
25 changes: 25 additions & 0 deletions gui/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
root: true,
env: {
node: true
},
extends: ["plugin:vue/essential", "eslint:recommended", "@vue/prettier"],
parserOptions: {
parser: "babel-eslint"
},
rules: {
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off"
},
overrides: [
{
files: [
"**/__tests__/*.{j,t}s?(x)",
"**/tests/unit/**/*.spec.{j,t}s?(x)"
],
env: {
jest: true
}
}
]
};
24 changes: 24 additions & 0 deletions gui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.DS_Store
node_modules
/dist

/tests/e2e/videos/
/tests/e2e/screenshots/

# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
34 changes: 34 additions & 0 deletions gui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# darkroom-gui

## Project setup
```
npm install
```

### Compiles and hot-reloads for development
```
npm run serve
```

### Compiles and minifies for production
```
npm run build
```

### Run your unit tests
```
npm run test:unit
```

### Run your end-to-end tests
```
npm run test:e2e
```

### Lints and fixes files
```
npm run lint
```

### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).
3 changes: 3 additions & 0 deletions gui/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ["@vue/cli-plugin-babel/preset"]
};
Loading

0 comments on commit 7c50d65

Please sign in to comment.