Skip to content

Commit

Permalink
feat(vm): apply new controller design (#120)
Browse files Browse the repository at this point in the history
apply new controller design

Signed-off-by: yaroslavborbat <[email protected]>
  • Loading branch information
yaroslavborbat authored Jun 25, 2024
1 parent bf009a0 commit ba12e49
Show file tree
Hide file tree
Showing 38 changed files with 3,630 additions and 2,545 deletions.
4 changes: 3 additions & 1 deletion api/core/v1alpha2/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ const (
ReasonErrUploaderWaitDurationExpired = "UploaderWaitDurationExpired"

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

// ReasonVMDegraded is event reason that vm is degraded.
ReasonVMDegraded = "VirtualmachineDegraded"
// ReasonErrVMOPNotPermitted is event reason that vmop is not permitted.
ReasonErrVMOPNotPermitted = "VirtualMachineOperationNotPermitted"

Expand Down
13 changes: 7 additions & 6 deletions api/core/v1alpha2/finalizers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ const (
FinalizerPVCProtection = "virtualization.deckhouse.io/pvc-protection"
FinalizerPVProtection = "virtualization.deckhouse.io/pv-protection"

FinalizerCVMIProtection = "virtualization.deckhouse.io/cvi-protection"
FinalizerVMIProtection = "virtualization.deckhouse.io/vi-protection"
FinalizerVMDProtection = "virtualization.deckhouse.io/vd-protection"
FinalizerKVVMProtection = "virtualization.deckhouse.io/kvvm-protection"
FinalizerVMOPProtection = "virtualization.deckhouse.io/vmop-protection"
FinalizerVMCPUProtection = "virtualization.deckhouse.io/vmcpu-protection"
FinalizerCVIProtection = "virtualization.deckhouse.io/cvi-protection"
FinalizerVIProtection = "virtualization.deckhouse.io/vi-protection"
FinalizerVDProtection = "virtualization.deckhouse.io/vd-protection"
FinalizerKVVMProtection = "virtualization.deckhouse.io/kvvm-protection"
FinalizerVMOPProtection = "virtualization.deckhouse.io/vmop-protection"
FinalizerVMCPUProtection = "virtualization.deckhouse.io/vmcpu-protection"
FinalizerIPAddressClaimProtection = "virtualization.deckhouse.io/vmip-protection"

FinalizerCVICleanup = "virtualization.deckhouse.io/cvi-cleanup"
FinalizerVDCleanup = "virtualization.deckhouse.io/vd-cleanup"
Expand Down
45 changes: 42 additions & 3 deletions api/core/v1alpha2/virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ type VirtualMachineStatus struct {
IPAddress string `json:"ipAddress"`
BlockDeviceRefs []BlockDeviceStatusRef `json:"blockDeviceRefs"`
GuestOSInfo virtv1.VirtualMachineInstanceGuestOSInfo `json:"guestOSInfo"`
Message string `json:"message"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
Stats *VirtualMachineStats `json:"stats,omitempty"`
MigrationState *VirtualMachineMigrationState `json:"migrationState,omitempty"`

// RestartAwaitingChanges holds operations to be manually approved
// before applying to the virtual machine spec.
Expand All @@ -182,19 +184,56 @@ type VirtualMachineStatus struct {
RestartAwaitingChanges []apiextensionsv1.JSON `json:"restartAwaitingChanges,omitempty"`
}

type VirtualMachineStats struct {
PhasesTransitions []VirtualMachinePhaseTransitionTimestamp `json:"phasesTransitions,omitempty"`
LaunchTimeDuration VirtualMachineLaunchTimeDuration `json:"launchTimeDuration,omitempty"`
}

// VirtualMachinePhaseTransitionTimestamp gives a timestamp in relation to when a phase is set on a vm.
type VirtualMachinePhaseTransitionTimestamp struct {
Phase MachinePhase `json:"phase,omitempty"`
// PhaseTransitionTimestamp is the timestamp of when the phase change occurred
Timestamp metav1.Time `json:"timestamp,omitempty"`
}

type VirtualMachineLaunchTimeDuration struct {
WaitingForDependencies *metav1.Duration `json:"waitingForDependencies,omitempty"`
VirtualMachineStarting *metav1.Duration `json:"virtualMachineStarting,omitempty"`
GuestOSAgentStarting *metav1.Duration `json:"guestOSAgentStarting,omitempty"`
}

type VirtualMachineMigrationState struct {
StartTimestamp *metav1.Time `json:"startTimestamp,omitempty"`
EndTimestamp *metav1.Time `json:"endTimestamp,omitempty"`
Target VirtualMachineLocation `json:"target,omitempty"`
Source VirtualMachineLocation `json:"source,omitempty"`
Result MigrationResult `json:"result,omitempty"`
}

type MigrationResult string

const (
MigrationResultSucceeded MigrationResult = "Succeeded"
MigrationResultFailed MigrationResult = "Failed"
)

type VirtualMachineLocation struct {
Node string `json:"node,omitempty"`
Pod string `json:"pod,omitempty"`
}

type MachinePhase string

const (
MachineScheduling MachinePhase = "Scheduling"
MachinePending MachinePhase = "Pending"
MachineRunning MachinePhase = "Running"
MachineFailed MachinePhase = "Failed"
MachineTerminating MachinePhase = "Terminating"
MachineStopped MachinePhase = "Stopped"
MachineStopping MachinePhase = "Stopping"
MachineStarting MachinePhase = "Starting"
MachineMigrating MachinePhase = "Migrating"
MachinePause MachinePhase = "Pause"
MachineDegraded MachinePhase = "Degraded"
)

// VirtualMachineList contains a list of VirtualMachine
Expand Down
2 changes: 1 addition & 1 deletion api/core/v1alpha2/vmaffinity.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewAffinityFromVMAffinity(vmAffinity *VMAffinity) *corev1.Affinity {
}
if vmAff := vmAffinity.VirtualMachineAndPodAffinity; vmAff != nil {
corePodAff := &corev1.PodAffinity{}
corePr := make([]corev1.WeightedPodAffinityTerm, len(vmAff.RequiredDuringSchedulingIgnoredDuringExecution))
corePr := make([]corev1.WeightedPodAffinityTerm, len(vmAff.PreferredDuringSchedulingIgnoredDuringExecution))
for i, pr := range vmAff.PreferredDuringSchedulingIgnoredDuringExecution {
corePr[i] = corev1.WeightedPodAffinityTerm{
Weight: pr.Weight,
Expand Down
74 changes: 74 additions & 0 deletions api/core/v1alpha2/vmcondition/condition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package vmcondition

type Type string

func (t Type) String() string {
return string(t)
}

const (
TypeCPUModelReady Type = "CPUModelReady"
TypeIPAddressClaimReady Type = "VirtualMachineIPAddressClaimReady"
TypeBlockDevicesReady Type = "BlockDevicesReady"
TypeRunning Type = "Running"
TypeMigrating Type = "Migrating"
TypePodStarted Type = "PodStarted"
TypeProvisioningReady Type = "ProvisioningReady"
TypeAgentReady Type = "AgentReady"
TypeAgentVersionNotSupported Type = "AgentVersionNotSupported"
TypeConfigurationApplied Type = "ConfigurationApplied"
TypeAwaitingRestartToApplyConfiguration Type = "AwaitingRestartToApplyConfiguration"
)

type Reason string

func (r Reason) String() string {
return string(r)
}

const (
ReasonAgentNotReady Reason = "AgentNotReady"

ReasonCPUModelReady Reason = "CPUModelReady"
ReasonCPUModelNotReady Reason = "CPUModelNotReady"

ReasonIPAddressClaimReady Reason = "VirtualMachineIPAddressClaimReady"
ReasonIPAddressClaimNotReady Reason = "VirtualMachineIPAddressClaimNotReady"
ReasonIPAddressClaimNotAssigned Reason = "VirtualMachineIPAddressClaimNotAssigned"
ReasonIPAddressClaimNotAvailable Reason = "VirtualMachineIPAddressClaimNotAvailable"

ReasonBlockDevicesAttachmentReady Reason = "BlockDevicesAttachmentReady"
ReasonBlockDevicesAttachmentNotReady Reason = "BlockDevicesAttachmentNotReady"

ReasonProvisioningReady Reason = "ProvisioningReady"
ReasonProvisioningNotReady Reason = "ProvisioningNotReady"

ReasonConfigurationApplied Reason = "ConfigurationApplied"
ReasonConfigurationNotApplied Reason = "ConfigurationNotApplied"
ReasonRestartAwaitingChangesExist Reason = "RestartAwaitingChangesExist"
ReasonRestartAwaitingChangesNotExist Reason = "RestartAwaitingChangesNotExist"
ReasonRestartNoNeed Reason = "NoNeedRestart"

ReasonPodNodFound Reason = "PodNotFound"
ReasonPodStarted Reason = "PodStarted"
ReasonVmIsMigrating Reason = "VirtualMachineMigrating"
ReasonVmIsNotMigrating Reason = "VirtualMachineNotMigrating"
ReasonVmIsNotRunning Reason = "VirtualMachineNotRunning"
ReasonVmIsRunning Reason = "VirtualMachineRunning"
)
131 changes: 131 additions & 0 deletions api/core/v1alpha2/zz_generated.deepcopy.go

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

Loading

0 comments on commit ba12e49

Please sign in to comment.