@@ -18,22 +18,29 @@ package internal
1818
1919import (
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
3845func (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
0 commit comments