Skip to content

Commit f680000

Browse files
Revert "fix(vm): add removing VM's conditions by design (#931)"
This reverts commit de83ce6.
1 parent de83ce6 commit f680000

17 files changed

Lines changed: 267 additions & 1297 deletions

File tree

api/core/v1alpha2/vmcondition/condition.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const (
2929
TypeRunning Type = "Running"
3030
TypeMigrating Type = "Migrating"
3131
TypeMigratable Type = "Migratable"
32+
TypePodStarted Type = "PodStarted"
3233
TypeProvisioningReady Type = "ProvisioningReady"
3334
TypeAgentReady Type = "AgentReady"
3435
TypeAgentVersionNotSupported Type = "AgentVersionNotSupported"
@@ -80,6 +81,10 @@ const (
8081
ReasonRestartAwaitingVMClassChangesExist Reason = "RestartAwaitingVMClassChangesExist"
8182
ReasonRestartNoNeed Reason = "NoNeedRestart"
8283

84+
ReasonPodStarted Reason = "PodStarted"
85+
ReasonPodNotFound Reason = "PodNotFound"
86+
ReasonPodNotStarted Reason = "PodNotStarted"
87+
8388
ReasonMigratable Reason = "VirtualMachineMigratable"
8489
ReasonNotMigratable Reason = "VirtualMachineNotMigratable"
8590

@@ -89,14 +94,14 @@ const (
8994
ReasonVmIsNotRunning Reason = "VirtualMachineNotRunning"
9095
ReasonVmIsRunning Reason = "VirtualMachineRunning"
9196
ReasonInternalVirtualMachineError Reason = "InternalVirtualMachineError"
92-
ReasonPodNotStarted Reason = "PodNotStarted"
9397

9498
// ReasonFilesystemFrozen indicates that virtual machine's filesystem has been successfully frozen.
9599
ReasonFilesystemFrozen Reason = "Frozen"
96100

97101
WaitingForTheSnapshotToStart Reason = "WaitingForTheSnapshotToStart"
98102
ReasonSnapshottingInProgress Reason = "SnapshottingInProgress"
99103

104+
ReasonSizingPolicyMatched Reason = "SizingPolicyMatched"
100105
ReasonSizingPolicyNotMatched Reason = "SizingPolicyNotMatched"
101106
ReasonVirtualMachineClassTerminating Reason = "VirtualMachineClassTerminating"
102107
ReasonVirtualMachineClassNotExists Reason = "VirtalMachineClassNotExists"

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

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ import (
3131

3232
const nameAgentHandler = "AgentHandler"
3333

34+
var agentConditions = []vmcondition.Type{
35+
vmcondition.TypeAgentReady,
36+
vmcondition.TypeAgentVersionNotSupported,
37+
}
38+
3439
func NewAgentHandler() *AgentHandler {
3540
return &AgentHandler{}
3641
}
@@ -44,6 +49,10 @@ func (h *AgentHandler) Handle(ctx context.Context, s state.VirtualMachineState)
4449
current := s.VirtualMachine().Current()
4550
changed := s.VirtualMachine().Changed()
4651

52+
if update := addAllUnknown(changed, agentConditions...); update {
53+
return reconcile.Result{Requeue: true}, nil
54+
}
55+
4756
if isDeletion(current) {
4857
return reconcile.Result{}, nil
4958
}
@@ -71,14 +80,7 @@ func (h *AgentHandler) syncAgentReady(vm *virtv2.VirtualMachine, kvvmi *virtv1.V
7180

7281
cb := conditions.NewConditionBuilder(vmcondition.TypeAgentReady).Generation(vm.GetGeneration())
7382

74-
defer func() {
75-
phase := vm.Status.Phase
76-
if phase == virtv2.MachinePending || phase == virtv2.MachineStarting || phase == virtv2.MachineStopped {
77-
conditions.RemoveCondition(vmcondition.TypeAgentReady, &vm.Status.Conditions)
78-
} else {
79-
conditions.SetCondition(cb, &vm.Status.Conditions)
80-
}
81-
}()
83+
defer func() { conditions.SetCondition(cb, &vm.Status.Conditions) }()
8284

8385
if kvvmi == nil {
8486
cb.Status(metav1.ConditionFalse).
@@ -114,19 +116,7 @@ func (h *AgentHandler) syncAgentVersionNotSupport(vm *virtv2.VirtualMachine, kvv
114116

115117
cb := conditions.NewConditionBuilder(vmcondition.TypeAgentVersionNotSupported).Generation(vm.GetGeneration())
116118

117-
defer func() {
118-
switch vm.Status.Phase {
119-
case virtv2.MachinePending, virtv2.MachineStarting, virtv2.MachineStopped:
120-
conditions.RemoveCondition(vmcondition.TypeAgentVersionNotSupported, &vm.Status.Conditions)
121-
122-
default:
123-
if cb.Condition().Status == metav1.ConditionTrue {
124-
conditions.SetCondition(cb, &vm.Status.Conditions)
125-
} else {
126-
conditions.RemoveCondition(vmcondition.TypeAgentVersionNotSupported, &vm.Status.Conditions)
127-
}
128-
}
129-
}()
119+
defer func() { conditions.SetCondition(cb, &vm.Status.Conditions) }()
130120

131121
if kvvmi == nil {
132122
cb.Status(metav1.ConditionFalse).

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

Lines changed: 0 additions & 170 deletions
This file was deleted.

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

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,16 @@ func (h *FirmwareHandler) syncFirmwareUpToDate(vm *virtv2.VirtualMachine, kvvmi
6868
upToDate := kvvmi == nil || kvvmi.Status.LauncherContainerImageVersion == "" || kvvmi.Status.LauncherContainerImageVersion == h.image
6969

7070
cb := conditions.NewConditionBuilder(vmcondition.TypeFirmwareUpToDate).Generation(vm.GetGeneration())
71-
defer func() {
72-
switch vm.Status.Phase {
73-
case virtv2.MachinePending, virtv2.MachineStarting, virtv2.MachineStopped:
74-
conditions.RemoveCondition(vmcondition.TypeFirmwareUpToDate, &vm.Status.Conditions)
75-
76-
default:
77-
if cb.Condition().Status == metav1.ConditionFalse {
78-
conditions.SetCondition(cb, &vm.Status.Conditions)
79-
} else {
80-
conditions.RemoveCondition(vmcondition.TypeFirmwareUpToDate, &vm.Status.Conditions)
81-
}
82-
}
83-
}()
84-
85-
if !upToDate {
86-
cb.Status(metav1.ConditionFalse).
87-
Reason(vmcondition.ReasonFirmwareOutOfDate).
88-
Message("The VM firmware version is outdated and not recommended for use with the current version of the virtualization module, please migrate or reboot the VM to upgrade its firmware version.")
71+
if upToDate {
72+
cb.Status(metav1.ConditionTrue).
73+
Reason(vmcondition.ReasonFirmwareUpToDate).
74+
Message("")
8975
conditions.SetCondition(cb, &vm.Status.Conditions)
76+
return
9077
}
78+
79+
cb.Status(metav1.ConditionFalse).
80+
Reason(vmcondition.ReasonFirmwareOutOfDate).
81+
Message("The VM firmware version is outdated and not recommended for use with the current version of the virtualization module, please migrate or reboot the VM to upgrade its firmware version.")
82+
conditions.SetCondition(cb, &vm.Status.Conditions)
9183
}

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

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var _ = Describe("TestFirmwareHandler", func() {
7373
}
7474

7575
DescribeTable("Condition TypeFirmwareUpToDate should be in expected state",
76-
func(vm *virtv2.VirtualMachine, kvvmi *virtv1.VirtualMachineInstance, expectedStatus metav1.ConditionStatus, expectedReason vmcondition.Reason, expectedExistence bool) {
76+
func(vm *virtv2.VirtualMachine, kvvmi *virtv1.VirtualMachineInstance, expectedStatus metav1.ConditionStatus, expectedReason vmcondition.Reason) {
7777
fakeClient, resource, vmState = setupEnvironment(vm, kvvmi)
7878
reconcile()
7979

@@ -82,51 +82,16 @@ var _ = Describe("TestFirmwareHandler", func() {
8282
Expect(err).NotTo(HaveOccurred())
8383

8484
upToDate, exists := conditions.GetCondition(vmcondition.TypeFirmwareUpToDate, newVM.Status.Conditions)
85-
Expect(exists).To(Equal(expectedExistence))
86-
if exists {
87-
Expect(upToDate.Status).To(Equal(expectedStatus))
88-
Expect(upToDate.Reason).To(Equal(expectedReason.String()))
89-
}
85+
Expect(exists).To(BeTrue())
86+
Expect(upToDate.Status).To(Equal(expectedStatus))
87+
Expect(upToDate.Reason).To(Equal(expectedReason.String()))
9088
},
91-
Entry("Should be up to date", newVM(), newKVVMI(expectedImage), metav1.ConditionTrue, vmcondition.ReasonFirmwareUpToDate, false),
92-
Entry("Should be up to date because kvvmi is not exists", newVM(), nil, metav1.ConditionTrue, vmcondition.ReasonFirmwareUpToDate, false),
93-
Entry("Should be out of date 1", newVM(), newKVVMI("other-image-1"), metav1.ConditionFalse, vmcondition.ReasonFirmwareOutOfDate, true),
94-
Entry("Should be out of date 2", newVM(), newKVVMI("other-image-2"), metav1.ConditionFalse, vmcondition.ReasonFirmwareOutOfDate, true),
95-
Entry("Should be out of date 3", newVM(), newKVVMI("other-image-3"), metav1.ConditionFalse, vmcondition.ReasonFirmwareOutOfDate, true),
96-
Entry("Should be out of date 4", newVM(), newKVVMI("other-image-4"), metav1.ConditionFalse, vmcondition.ReasonFirmwareOutOfDate, true),
97-
Entry("Should be out of date 5", newVM(), newKVVMI("other-image-5"), metav1.ConditionFalse, vmcondition.ReasonFirmwareOutOfDate, true),
98-
)
99-
100-
DescribeTable("Condition TypeFirmwareUpToDate should be in the expected state considering the VM phase",
101-
func(vm *virtv2.VirtualMachine, phase virtv2.MachinePhase, kvvmi *virtv1.VirtualMachineInstance, expectedStatus metav1.ConditionStatus, expectedExistence bool) {
102-
vm.Status.Phase = phase
103-
fakeClient, resource, vmState = setupEnvironment(vm, kvvmi)
104-
reconcile()
105-
newVM := &virtv2.VirtualMachine{}
106-
err := fakeClient.Get(ctx, client.ObjectKeyFromObject(vm), newVM)
107-
Expect(err).NotTo(HaveOccurred())
108-
upToDate, exists := conditions.GetCondition(vmcondition.TypeFirmwareUpToDate, newVM.Status.Conditions)
109-
Expect(exists).To(Equal(expectedExistence))
110-
if exists {
111-
Expect(upToDate.Status).To(Equal(expectedStatus))
112-
}
113-
},
114-
Entry("Running phase, condition should not be set", newVM(), virtv2.MachineRunning, newKVVMI(expectedImage), metav1.ConditionUnknown, false),
115-
Entry("Running phase, condition should be set", newVM(), virtv2.MachineRunning, newKVVMI("other-image-1"), metav1.ConditionFalse, true),
116-
117-
Entry("Migrating phase, condition should not be set", newVM(), virtv2.MachineMigrating, newKVVMI(expectedImage), metav1.ConditionUnknown, false),
118-
Entry("Migrating phase, condition should be set", newVM(), virtv2.MachineMigrating, newKVVMI("other-image-1"), metav1.ConditionFalse, true),
119-
120-
Entry("Stopping phase, condition should not be set", newVM(), virtv2.MachineStopping, newKVVMI(expectedImage), metav1.ConditionUnknown, false),
121-
Entry("Stopping phase, condition should be set", newVM(), virtv2.MachineStopping, newKVVMI("other-image-1"), metav1.ConditionFalse, true),
122-
123-
Entry("Pending phase, condition should not be set", newVM(), virtv2.MachinePending, newKVVMI(expectedImage), metav1.ConditionUnknown, false),
124-
Entry("Pending phase, condition should not be set", newVM(), virtv2.MachinePending, newKVVMI("other-image-1"), metav1.ConditionUnknown, false),
125-
126-
Entry("Starting phase, condition should not be set", newVM(), virtv2.MachineStarting, newKVVMI(expectedImage), metav1.ConditionUnknown, false),
127-
Entry("Starting phase, condition should not be set", newVM(), virtv2.MachineStarting, newKVVMI("other-image-1"), metav1.ConditionUnknown, false),
128-
129-
Entry("Stopped phase, condition should not be set", newVM(), virtv2.MachineStopped, newKVVMI(expectedImage), metav1.ConditionUnknown, false),
130-
Entry("Stopped phase, condition should not be set", newVM(), virtv2.MachineStopped, newKVVMI("other-image-1"), metav1.ConditionUnknown, false),
89+
Entry("Should be up to date", newVM(), newKVVMI(expectedImage), metav1.ConditionTrue, vmcondition.ReasonFirmwareUpToDate),
90+
Entry("Should be up to date because kvvmi is not exists", newVM(), nil, metav1.ConditionTrue, vmcondition.ReasonFirmwareUpToDate),
91+
Entry("Should be out of date 1", newVM(), newKVVMI("other-image-1"), metav1.ConditionFalse, vmcondition.ReasonFirmwareOutOfDate),
92+
Entry("Should be out of date 2", newVM(), newKVVMI("other-image-2"), metav1.ConditionFalse, vmcondition.ReasonFirmwareOutOfDate),
93+
Entry("Should be out of date 3", newVM(), newKVVMI("other-image-3"), metav1.ConditionFalse, vmcondition.ReasonFirmwareOutOfDate),
94+
Entry("Should be out of date 4", newVM(), newKVVMI("other-image-4"), metav1.ConditionFalse, vmcondition.ReasonFirmwareOutOfDate),
95+
Entry("Should be out of date 5", newVM(), newKVVMI("other-image-5"), metav1.ConditionFalse, vmcondition.ReasonFirmwareOutOfDate),
13196
)
13297
})

0 commit comments

Comments
 (0)