Skip to content

Commit

Permalink
Merge pull request #839 from keyingliu/reboot
Browse files Browse the repository at this point in the history
Keep VM data during node restart
  • Loading branch information
ivan4th committed Jan 14, 2019
2 parents 8b439ae + 2d79639 commit 07b5608
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 20 deletions.
7 changes: 7 additions & 0 deletions deploy/data/virtlet-ds.yaml
Expand Up @@ -138,6 +138,8 @@ spec:
command:
- /libvirt.sh
volumeMounts:
- mountPath: /etc/libvirt/qemu
name: qemu
- mountPath: /sys/fs/cgroup
name: cgroup
- mountPath: /lib/modules
Expand Down Expand Up @@ -177,6 +179,8 @@ spec:
# In case we inject local virtlet image we want to use it not officially available one
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: /etc/libvirt/qemu
name: qemu
- mountPath: /run
# Don't add "mountPropagation: Bidirectional", it will lack mount entry
name: run
Expand Down Expand Up @@ -299,6 +303,9 @@ spec:
- hostPath:
path: /var/run/netns
name: netns-dir
- hostPath:
path: /etc/libvirt/qemu
name: qemu
- configMap:
name: virtlet-image-translations
name: image-name-translations
Expand Down
20 changes: 5 additions & 15 deletions pkg/libvirttools/gc.go
Expand Up @@ -96,22 +96,12 @@ func (v *VirtualizationTool) checkSandboxNetNs(sandbox metadata.PodSandboxMetada
}

if !v.mountPointChecker.IsPathAnNs(sinfo.ContainerSideNetwork.NsPath) {
containers, err := v.metadataStore.ListPodContainers(sandbox.GetID())
if err != nil {
return err
}
for _, container := range containers {
// remove container from metadata store
if err := container.Save(func(*types.ContainerInfo) (*types.ContainerInfo, error) {
return nil, nil
}); err != nil {
return err
// NS didn't found, need RunSandbox again
if err := sandbox.Save(func(s *types.PodSandboxInfo) (*types.PodSandboxInfo, error) {
if s != nil {
s.State = types.PodSandboxState_SANDBOX_NOTREADY
}
}

// remove sandbox from metadata store
if err := sandbox.Save(func(*types.PodSandboxInfo) (*types.PodSandboxInfo, error) {
return nil, nil
return s, nil
}); err != nil {
return err
}
Expand Down
12 changes: 9 additions & 3 deletions pkg/manager/manager.go
Expand Up @@ -173,14 +173,16 @@ func (v *VirtletManager) Stop() {
// garbage collection for both libvirt and the image store.
func (v *VirtletManager) recoverAndGC() error {
var errors []string
for _, err := range v.recoverNetworkNamespaces() {
errors = append(errors, fmt.Sprintf("* error recovering VM network namespaces: %v", err))
}

for _, err := range v.virtTool.GarbageCollect() {
errors = append(errors, fmt.Sprintf("* error performing libvirt GC: %v", err))
}

// recover network namespace after VM GC
for _, err := range v.recoverNetworkNamespaces() {
errors = append(errors, fmt.Sprintf("* error recovering VM network namespaces: %v", err))
}

if err := v.imageStore.GC(); err != nil {
errors = append(errors, fmt.Sprintf("* error during image GC: %v", err))
}
Expand Down Expand Up @@ -213,6 +215,10 @@ OUTER:
allErrors = append(allErrors, fmt.Errorf("inconsistent database. Found pod %q sandbox but can not retrive its metadata", s.GetID()))
continue
}
// Don't recover if sandbox is not ready
if psi.State != types.PodSandboxState_SANDBOX_READY {
continue
}

haveRunningContainers := false
containers, err := v.metadataStore.ListPodContainers(s.GetID())
Expand Down
7 changes: 7 additions & 0 deletions pkg/tools/TestGenCommand__compat.out.yaml
Expand Up @@ -41,6 +41,8 @@ spec:
securityContext:
privileged: true
volumeMounts:
- mountPath: /etc/libvirt/qemu
name: qemu
- mountPath: /sys/fs/cgroup
name: cgroup
- mountPath: /lib/modules
Expand Down Expand Up @@ -76,6 +78,8 @@ spec:
securityContext:
privileged: true
volumeMounts:
- mountPath: /etc/libvirt/qemu
name: qemu
- mountPath: /run:shared
name: run
- mountPath: /lib/modules
Expand Down Expand Up @@ -278,6 +282,9 @@ spec:
- hostPath:
path: /var/run/netns
name: netns-dir
- hostPath:
path: /etc/libvirt/qemu
name: qemu
- configMap:
name: virtlet-image-translations
name: image-name-translations
Expand Down
7 changes: 7 additions & 0 deletions pkg/tools/TestGenCommand__compat_dev.out.yaml
Expand Up @@ -41,6 +41,8 @@ spec:
securityContext:
privileged: true
volumeMounts:
- mountPath: /etc/libvirt/qemu
name: qemu
- mountPath: /sys/fs/cgroup
name: cgroup
- mountPath: /lib/modules
Expand Down Expand Up @@ -78,6 +80,8 @@ spec:
securityContext:
privileged: true
volumeMounts:
- mountPath: /etc/libvirt/qemu
name: qemu
- mountPath: /run:shared
name: run
- mountPath: /lib/modules
Expand Down Expand Up @@ -286,6 +290,9 @@ spec:
- hostPath:
path: /var/run/netns
name: netns-dir
- hostPath:
path: /etc/libvirt/qemu
name: qemu
- configMap:
name: virtlet-image-translations
name: image-name-translations
Expand Down
7 changes: 7 additions & 0 deletions pkg/tools/TestGenCommand__dev.out.yaml
Expand Up @@ -41,6 +41,8 @@ spec:
securityContext:
privileged: true
volumeMounts:
- mountPath: /etc/libvirt/qemu
name: qemu
- mountPath: /sys/fs/cgroup
name: cgroup
- mountPath: /lib/modules
Expand Down Expand Up @@ -78,6 +80,8 @@ spec:
securityContext:
privileged: true
volumeMounts:
- mountPath: /etc/libvirt/qemu
name: qemu
- mountPath: /run
name: run
- mountPath: /lib/modules
Expand Down Expand Up @@ -288,6 +292,9 @@ spec:
- hostPath:
path: /var/run/netns
name: netns-dir
- hostPath:
path: /etc/libvirt/qemu
name: qemu
- configMap:
name: virtlet-image-translations
name: image-name-translations
Expand Down
7 changes: 7 additions & 0 deletions pkg/tools/TestGenCommand__plain.out.yaml
Expand Up @@ -41,6 +41,8 @@ spec:
securityContext:
privileged: true
volumeMounts:
- mountPath: /etc/libvirt/qemu
name: qemu
- mountPath: /sys/fs/cgroup
name: cgroup
- mountPath: /lib/modules
Expand Down Expand Up @@ -76,6 +78,8 @@ spec:
securityContext:
privileged: true
volumeMounts:
- mountPath: /etc/libvirt/qemu
name: qemu
- mountPath: /run
name: run
- mountPath: /lib/modules
Expand Down Expand Up @@ -280,6 +284,9 @@ spec:
- hostPath:
path: /var/run/netns
name: netns-dir
- hostPath:
path: /etc/libvirt/qemu
name: qemu
- configMap:
name: virtlet-image-translations
name: image-name-translations
Expand Down
7 changes: 7 additions & 0 deletions pkg/tools/TestGenCommand__tag.out.yaml
Expand Up @@ -41,6 +41,8 @@ spec:
securityContext:
privileged: true
volumeMounts:
- mountPath: /etc/libvirt/qemu
name: qemu
- mountPath: /sys/fs/cgroup
name: cgroup
- mountPath: /lib/modules
Expand Down Expand Up @@ -76,6 +78,8 @@ spec:
securityContext:
privileged: true
volumeMounts:
- mountPath: /etc/libvirt/qemu
name: qemu
- mountPath: /run
name: run
- mountPath: /lib/modules
Expand Down Expand Up @@ -280,6 +284,9 @@ spec:
- hostPath:
path: /var/run/netns
name: netns-dir
- hostPath:
path: /etc/libvirt/qemu
name: qemu
- configMap:
name: virtlet-image-translations
name: image-name-translations
Expand Down
4 changes: 2 additions & 2 deletions pkg/tools/bindata.go

Large diffs are not rendered by default.

0 comments on commit 07b5608

Please sign in to comment.