Skip to content

Commit

Permalink
feat(vmop): first implementation (#4)
Browse files Browse the repository at this point in the history
## Description
 Implementation resource VirtualMachineOperation. 
The VirtualMachineOperation custom resource allows for declarative
management of a working virtual machine. It enables actions such as
stopping, starting, and restarting the virtual machine.

## Why do we need it, and what problem does it solve?
The VirtualMachineOperation resource is needed to provide a high-level
abstraction for managing virtual machines. It solves the problem of
efficiently and easily controlling the state of virtual machines through
a declarative approach, rather than relying on manual, time-consuming
operations.

## What is the expected result?
VirtualMachineOperation is an immutable resource. After deployment, it
can have 4 phases of status: Completed, Failed, InProgress, Pending.

---------

Signed-off-by: Yaroslav Borbat <[email protected]>
Signed-off-by: Yaroslav Borbat <[email protected]>
Co-authored-by: Ivan Mikheykin <[email protected]>
  • Loading branch information
yaroslavborbat and diafour authored Feb 9, 2024
1 parent 6c7ec69 commit 7bf5e68
Show file tree
Hide file tree
Showing 18 changed files with 905 additions and 21 deletions.
2 changes: 1 addition & 1 deletion hack/upload-pvc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fi


cat <<EOF | kubectl -n $NS apply -f -
apiVersion: virtualization.deckhouse.io/v2alpha1
apiVersion: virtualization.deckhouse.io/v1alpha2
kind: VirtualMachineImage
metadata:
name: $NAME
Expand Down
2 changes: 1 addition & 1 deletion hack/upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fi


cat <<EOF | kubectl -n $NS apply -f -
apiVersion: virtualization.deckhouse.io/v2alpha1
apiVersion: virtualization.deckhouse.io/v1alpha2
kind: VirtualMachineImage
metadata:
name: $NAME
Expand Down
5 changes: 5 additions & 0 deletions images/virtualization-controller/Taskfile.dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,11 @@ tasks:
cmds:
- kubectl apply -f api/crds/virtualmachineipaddresslease.yaml

dev:update:vmop:
desc: "Update VirtualMachineOperation CRD"
cmds:
- kubectl apply -f api/crds/virtualmachineoperations.yaml

kctl:
cmds:
- kubectl -n virtualization-controller {{.CLI_ARGS}}
Expand Down
9 changes: 9 additions & 0 deletions images/virtualization-controller/api/v1alpha2/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,13 @@ const (

// ReasonErrVmNotSynced is event reason that vm is not synced.
ReasonErrVmNotSynced = "VirtualMachineNotSynced "

// ReasonErrVMOPNotPermitted is event reason that vmop is not permitted.
ReasonErrVMOPNotPermitted = "VirtualMachineOperationNotPermitted"

// ReasonErrVMOPFailed is event reason that operation is failed
ReasonErrVMOPFailed = "VirtualMachineOperationFailed"

// ReasonVMOPSucceeded is event reason that the operation is successfully completed
ReasonVMOPSucceeded = "VirtualMachineOperationSucceeded"
)
2 changes: 2 additions & 0 deletions images/virtualization-controller/api/v1alpha2/finalizers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
FinalizerVMIProtection = "virtualization.deckhouse.io/vmi-protection"
FinalizerVMDProtection = "virtualization.deckhouse.io/vmd-protection"
FinalizerKVVMProtection = "virtualization.deckhouse.io/kvvm-protection"
FinalizerVMOPProtection = "virtualization.deckhouse.io/vmop-protection"

FinalizerCVMICleanup = "virtualization.deckhouse.io/cvmi-cleanup"
FinalizerVMICleanup = "virtualization.deckhouse.io/vmi-cleanup"
Expand All @@ -21,4 +22,5 @@ const (
FinalizerIPAddressClaimCleanup = "virtualization.deckhouse.io/vmip-cleanup"
FinalizerIPAddressLeaseCleanup = "virtualization.deckhouse.io/vmipl-cleanup"
FinalizerVMBDACleanup = "virtualization.deckhouse.io/vmbda-cleanup"
FinalizerVMOPCleanup = "virtualization.deckhouse.io/vmop-cleanup"
)
2 changes: 2 additions & 0 deletions images/virtualization-controller/api/v1alpha2/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&VirtualMachineIPAddressClaimList{},
&VirtualMachineIPAddressLease{},
&VirtualMachineIPAddressLeaseList{},
&VirtualMachineOperation{},
&VirtualMachineOperationList{},
)

metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package v1alpha2

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

const (
VMOPKind = "VirtualMachineOperation"
VMOPResource = "virtualmachineoperations"
)

// VirtualMachineOperation is operation performed on the VirtualMachine.
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type VirtualMachineOperation struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec VirtualMachineOperationSpec `json:"spec"`
Status VirtualMachineOperationStatus `json:"status,omitempty"`
}

type VirtualMachineOperationSpec struct {
Type VMOPOperation `json:"type"`
VirtualMachineName string `json:"virtualMachineName"`
Force bool `json:"force,omitempty"`
}

type VirtualMachineOperationStatus struct {
Phase VMOPPhase `json:"phase"`
FailureReason string `json:"failureReason,omitempty"`
FailureMessage string `json:"failureMessage,omitempty"`
}

// VirtualMachineOperationList contains a list of VirtualMachineOperation
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type VirtualMachineOperationList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []VirtualMachineOperation `json:"items"`
}

type VMOPPhase string

const (
VMOPPhasePending VMOPPhase = "Pending"
VMOPPhaseInProgress VMOPPhase = "InProgress"
VMOPPhaseCompleted VMOPPhase = "Completed"
VMOPPhaseFailed VMOPPhase = "Failed"
)

type VMOPOperation string

const (
VMOPOperationTypeRestart VMOPOperation = "Restart"
VMOPOperationTypeStart VMOPOperation = "Start"
VMOPOperationTypeStop VMOPOperation = "Stop"
)

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
appconfig "github.com/deckhouse/virtualization-controller/pkg/config"
"github.com/deckhouse/virtualization-controller/pkg/controller"
"github.com/deckhouse/virtualization-controller/pkg/controller/ipam"
"github.com/deckhouse/virtualization-controller/pkg/controller/vmop"
)

var (
Expand Down Expand Up @@ -249,6 +250,11 @@ func main() {
os.Exit(1)
}

if _, err := vmop.NewController(ctx, mgr, log); err != nil {
log.Error(err, "")
os.Exit(1)
}

log.Info("Starting the Manager.")

// Start the Manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ webhooks:
- name: "vm.validation.webhook.virtualization.deckhouse.io"
rules:
- apiGroups: ["virtualization.deckhouse.io"]
apiVersions: ["v2alpha1"]
apiVersions: ["v1alpha2"]
operations: ["CREATE", "UPDATE"]
resources: ["virtualmachines"]
scope: "Namespaced"
clientConfig:
service:
namespace: virtualization-controller
name: admission-webhook-service
path: /validate-virtualization-deckhouse-io-v2alpha1-virtualmachine
path: /validate-virtualization-deckhouse-io-v1alpha2-virtualmachine
port: 443
caBundle: |
{{ .Files.Get "admission-webhook-certs/ca.pem" | b64enc }}
Expand All @@ -23,15 +23,15 @@ webhooks:
- name: "vmd.validation.webhook.virtualization.deckhouse.io"
rules:
- apiGroups: ["virtualization.deckhouse.io"]
apiVersions: ["v2alpha1"]
apiVersions: ["v1alpha2"]
operations: ["CREATE", "UPDATE"]
resources: ["virtualmachinedisks"]
scope: "Namespaced"
clientConfig:
service:
namespace: virtualization-controller
name: admission-webhook-service
path: /validate-virtualization-deckhouse-io-v2alpha1-virtualmachinedisk
path: /validate-virtualization-deckhouse-io-v1alpha2-virtualmachinedisk
port: 443
caBundle: |
{{ .Files.Get "admission-webhook-certs/ca.pem" | b64enc }}
Expand All @@ -40,15 +40,15 @@ webhooks:
- name: "vmip.validation.webhook.virtualization.deckhouse.io"
rules:
- apiGroups: ["virtualization.deckhouse.io"]
apiVersions: ["v2alpha1"]
apiVersions: ["v1alpha2"]
operations: ["CREATE", "UPDATE"]
resources: ["virtualmachineipaddressclaims"]
scope: "Namespaced"
clientConfig:
service:
namespace: virtualization-controller
name: admission-webhook-service
path: /validate-virtualization-deckhouse-io-v2alpha1-virtualmachineipaddressclaim
path: /validate-virtualization-deckhouse-io-v1alpha2-virtualmachineipaddressclaim
port: 443
caBundle: |
{{ .Files.Get "admission-webhook-certs/ca.pem" | b64enc }}
Expand All @@ -57,15 +57,15 @@ webhooks:
- name: "vmipl.validation.webhook.virtualization.deckhouse.io"
rules:
- apiGroups: ["virtualization.deckhouse.io"]
apiVersions: ["v2alpha1"]
apiVersions: ["v1alpha2"]
operations: ["CREATE"]
resources: ["virtualmachineipaddressleases"]
scope: "Cluster"
clientConfig:
service:
namespace: virtualization-controller
name: admission-webhook-service
path: /validate-virtualization-deckhouse-io-v2alpha1-virtualmachineipaddresslease
path: /validate-virtualization-deckhouse-io-v1alpha2-virtualmachineipaddresslease
port: 443
caBundle: |
{{ .Files.Get "admission-webhook-certs/ca.pem" | b64enc }}
Expand Down
Loading

0 comments on commit 7bf5e68

Please sign in to comment.