Skip to content

Commit 6c32cf6

Browse files
author
Valeriy Khorunzhin
committed
manual freeze
Signed-off-by: Valeriy Khorunzhin <valeriy.khorunzhin@flant.com>
1 parent 9b0b0b0 commit 6c32cf6

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

images/virt-handler/werf.inc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ shell:
106106
107107
setup:
108108
- |
109+
echo kek
110+
109111
/relocate_binaries.sh -i "{{ $builderDependencies.binaries | join " " }}" -o /relocate
110112
111113
mkdir -p /relocate/etc /relocate/root

images/virtualization-artifact/pkg/controller/vm/internal/filesystem.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,29 @@ package internal
1818

1919
import (
2020
"context"
21+
"fmt"
2122

2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2425

2526
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
2627
"github.com/deckhouse/virtualization-controller/pkg/controller/vm/internal/state"
2728
"github.com/deckhouse/virtualization/api/core/v1alpha2/vmcondition"
29+
subv1alpha2 "github.com/deckhouse/virtualization/api/subresources/v1alpha2"
2830
)
2931

30-
const nameFilesystemHandler = "FilesystemHandler"
32+
const (
33+
nameFilesystemHandler = "FilesystemHandler"
34+
annKek = "kek"
35+
)
3136

32-
func NewFilesystemHandler() *FilesystemHandler {
33-
return &FilesystemHandler{}
37+
func NewFilesystemHandler(virtClient VirtClient) *FilesystemHandler {
38+
return &FilesystemHandler{virtClient: virtClient}
3439
}
3540

36-
type FilesystemHandler struct{}
41+
type FilesystemHandler struct {
42+
virtClient VirtClient
43+
}
3744

3845
func (h *FilesystemHandler) Handle(ctx context.Context, s state.VirtualMachineState) (reconcile.Result, error) {
3946
if s.VirtualMachine().IsEmpty() {
@@ -67,6 +74,20 @@ func (h *FilesystemHandler) Handle(ctx context.Context, s state.VirtualMachineSt
6774
return reconcile.Result{}, nil
6875
}
6976

77+
if request, ok := changed.Annotations[annKek]; ok {
78+
switch request {
79+
case "freeze":
80+
if err = h.virtClient.VirtualMachines(changed.Namespace).Freeze(ctx, changed.Name, subv1alpha2.VirtualMachineFreeze{}); err != nil {
81+
return reconcile.Result{}, fmt.Errorf("freeze virtual machine %s/%s: %w", changed.Namespace, changed.Name, err)
82+
}
83+
case "unfreeze":
84+
if err = h.virtClient.VirtualMachines(changed.Namespace).Unfreeze(ctx, changed.Name); err != nil {
85+
return reconcile.Result{}, fmt.Errorf("unfreeze virtual machine %s/%s: %w", changed.Namespace, changed.Name, err)
86+
}
87+
}
88+
delete(changed.Annotations, annKek)
89+
}
90+
7091
agentReady, _ := conditions.GetCondition(vmcondition.TypeAgentReady, changed.Status.Conditions)
7192
if agentReady.Status != metav1.ConditionTrue {
7293
return reconcile.Result{}, nil

images/virtualization-artifact/pkg/controller/vm/vm_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func SetupController(
7171
internal.NewUSBDeviceAttachHandler(client, virtClient),
7272
internal.NewProvisioningHandler(client),
7373
internal.NewAgentHandler(),
74-
internal.NewFilesystemHandler(),
74+
internal.NewFilesystemHandler(virtClient),
7575
internal.NewSnapshottingHandler(client),
7676
internal.NewPodHandler(client),
7777
internal.NewSizePolicyHandler(),

0 commit comments

Comments
 (0)