Skip to content

Commit

Permalink
fix(vm): remove restartID and spec.restartApprovalID (#27)
Browse files Browse the repository at this point in the history
fix(vm): remove restartID and spec.restartApprovalID (#27)

---------

Signed-off-by: Ivan Mikheykin <[email protected]>
Co-authored-by: Dmitry Rakitin <[email protected]>
  • Loading branch information
diafour and Isteb4k authored Mar 29, 2024
1 parent 979c4f4 commit b9c0c4d
Show file tree
Hide file tree
Showing 17 changed files with 138 additions and 936 deletions.
6 changes: 0 additions & 6 deletions api/core/v1alpha2/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ const (
// ReasonHotplugPostponed is event reason that disk hotplug is not possible at the moment.
ReasonHotplugPostponed = "HotplugPostponed"

// ReasonVMChangeIDExpired is event reason that change id approve request should be updated.
ReasonVMChangeIDExpired = "ChangeIDExpired"

// ReasonVMChangeIDApproveAccepted is event reason that change id approve was accepted and handled.
ReasonVMChangeIDApproveAccepted = "ChangeIDApproveAccepted"

// ReasonVMWaitForBlockDevices is event reason that block devices used by VM are not ready yet.
ReasonVMWaitForBlockDevices = "WaitForBlockDevices"

Expand Down
14 changes: 4 additions & 10 deletions api/core/v1alpha2/virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,15 @@ type VirtualMachineSpec struct {
Memory MemorySpec `json:"memory"`
BlockDevices []BlockDeviceSpec `json:"blockDevices"`
Provisioning *Provisioning `json:"provisioning"`

// RestartApprovalID is a field for manual approval of disruptive changes.
// TODO Implement APIService and remove this field.
// +optional
RestartApprovalID string `json:"restartApprovalID,omitempty"`
}

type RunPolicy string

const (
AlwaysOnPolicy RunPolicy = "AlwaysOn"
AlwaysOffPolicy RunPolicy = "AlwaysOff"
ManualPolicy RunPolicy = "Manual"
AlwaysOnUnlessStoppedManualy RunPolicy = "AlwaysOnUnlessStoppedManualy"
AlwaysOnPolicy RunPolicy = "AlwaysOn"
AlwaysOffPolicy RunPolicy = "AlwaysOff"
ManualPolicy RunPolicy = "Manual"
AlwaysOnUnlessStoppedManually RunPolicy = "AlwaysOnUnlessStoppedManually"
)

type OsType string
Expand Down Expand Up @@ -132,7 +127,6 @@ type VirtualMachineStatus struct {
BlockDevicesAttached []BlockDeviceStatus `json:"blockDevicesAttached"`
GuestOSInfo virtv1.VirtualMachineInstanceGuestOSInfo `json:"guestOSInfo"`
Message string `json:"message"`
RestartID string `json:"restartID"`

// RestartAwaitingChanges holds operations to be manually approved
// before applying to the virtual machine spec.
Expand Down
16 changes: 1 addition & 15 deletions api/pkg/apiserver/api/generated/openapi/zz_generated.openapi.go

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

2 changes: 1 addition & 1 deletion crds/doc-ru-virtualmachine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ spec:
* `AlwaysOn` — после создания ВМ всегда находится в работающем состоянии, даже в случае ее выключения средствами ОС.
* `AlwaysOff` — после создания ВМ всегда находится в выключенном состоянии.
* `Manual` — после создания ВМ выключается, состояние ВМ (включение/выключение) контролируется через API-сервисы или средствами ОС.
* `AlwaysOnUnlessStoppedManualy` — после создания ВМ всегда находится в работающем состоянии, даже в случае ее выключения средствами ОС, ВМ может быть выключена с помощью соответствующего API-сервиса.
* `AlwaysOnUnlessStoppedManually` — после создания ВМ всегда находится в работающем состоянии, даже в случае ее выключения средствами ОС, ВМ может быть выключена с помощью соответствующего API-сервиса.
virtualMachineIPAddressClaimName:
description: |
Expand Down
23 changes: 7 additions & 16 deletions crds/virtualmachine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ spec:
- "AlwaysOn"
- "AlwaysOff"
- "Manual"
- "AlwaysOnUnlessStoppedManualy"
default: "AlwaysOnUnlessStoppedManualy"
- "AlwaysOnUnlessStoppedManually"
default: "AlwaysOnUnlessStoppedManually"
description: |
This parameter defines the VM startup policy
* `AlwaysOn` - after creation the VM is always in a running state, even in case of its shutdown by OS means.
* `AlwaysOff` - after creation the VM is always in the off state.
* `Manual` - after creation the VM is switched off, the VM state (switching on/off) is controlled via sub-resources or OS means.
* `AlwaysOnUnlessStoppedManualy` - after creation the VM is always in a running state, even in case of its shutdown by means of the OS, the VM can be shut down using the corresponding subresource.
* `AlwaysOnUnlessStoppedManually` - after creation the VM is always in a running state, even in case of its shutdown by means of the OS, the VM can be shut down using the corresponding subresource.
virtualMachineIPAddressClaimName:
type: string
Expand Down Expand Up @@ -777,16 +777,16 @@ spec:
default:
restartApprovalMode: Manual
description: |
Disruptions settings for VM.
Disruptions settings for virtual machine.
Some VM settings require a reboot of the VM when changing the configuration. To reboot, it is necessary to approve the changes. The `approvalMode` parameter is used for this purpose.
Some virtual machine settings require a reboot of the virtual machine when changing the configuration. To reboot, it is necessary to approve the changes. The `approvalMode` parameter is used for this purpose.
properties:
restartApprovalMode:
type: string
description: |
The approval mode for disruptive updates:
- `Manual` — to approve restart, you must do this manually by copying the restart ID from `.status.restartID` to `.spec.restartApprovalID`.
- `Automatic` — automatically approve disruption-involving updates.
- `Manual` — restart virtual machine manually to apply disruptive updates.
- `Automatic` — virtual machine will restart automatically to apply disruptive updates.
enum:
- Manual
- Automatic
Expand Down Expand Up @@ -947,11 +947,6 @@ spec:
anyOf:
- required: ["virtualMachineImage"]
- required: ["clusterVirtualMachineImage"]
restartApprovalID:
type: string
description: |
Hash of virtual machine changes from .status.restartID.
Required to approve restart for applying disruptive changes.
status:
type: object
properties:
Expand Down Expand Up @@ -1107,10 +1102,6 @@ spec:
type: string
description: |
Detailed description of the VM state.
restartID:
type: string
description: |
Hash of virtual machine changes. Use spec.restartApprovalID to approve disruptive changes, e.g. restart.
restartAwaitingChanges:
description: |
A list of changes require restart for applying.
Expand Down
22 changes: 15 additions & 7 deletions images/virtualization-artifact/pkg/common/kvvm/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,33 @@ func FindPodByKVVMI(ctx context.Context, cli client.Client, kvvmi *virtv1.Virtua
if err != nil || len(podList.Items) == 0 {
return nil, err
}
return GetVMPod(kvvmi, &podList), nil
}

func GetVMPod(kvvmi *virtv1.VirtualMachineInstance, podList *corev1.PodList) *corev1.Pod {
if len(podList.Items) == 0 {
return nil
}
if len(podList.Items) == 1 {
return &podList.Items[0], nil
return &podList.Items[0]
}
// Next, if pods are > 0

// If migration is completed - return the target pod.
if kvvmi.Status.MigrationState != nil && kvvmi.Status.MigrationState.Completed {
if kvvmi != nil && kvvmi.Status.MigrationState != nil && kvvmi.Status.MigrationState.Completed {
for _, pod := range podList.Items {
if pod.Name == kvvmi.Status.MigrationState.TargetPod {
return &pod, nil
return &pod
}
}
}
// return the first running pod

// Return the first Running Pod or just a first Pod.
for _, pod := range podList.Items {
if pod.Status.Phase == corev1.PodRunning {
return &pod, nil
return &pod
}
}
return &podList.Items[0], nil
return &podList.Items[0]
}

// DeletePodByKVVMI deletes pod by kvvmi.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (b *KVVM) SetRunPolicy(runPolicy virtv2.RunPolicy) error {
// initialize only
b.Resource.Spec.RunStrategy = util.GetPointer(virtv1.RunStrategyManual)
}
case virtv2.AlwaysOnUnlessStoppedManualy:
case virtv2.AlwaysOnUnlessStoppedManually:
if !b.ResourceExists {
// initialize only
b.Resource.Spec.RunStrategy = util.GetPointer(virtv1.RunStrategyAlways)
Expand Down
Loading

0 comments on commit b9c0c4d

Please sign in to comment.