Skip to content

Commit abefef0

Browse files
authored
fix(vm): add hiding of the NetworkReady condition when its status is Unknown. (#1567)
This PR adjusts the NetworkInterfaceHandler to remove the NetworkReady condition when its status resolves to Unknown, and updates corresponding unit tests to expect the condition to be absent rather than present with an Unknown status. Signed-off-by: Dmitry Lopatin <[email protected]>
1 parent 7b79710 commit abefef0

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ func (h *NetworkInterfaceHandler) Handle(ctx context.Context, s state.VirtualMac
6565
Generation(vm.GetGeneration())
6666

6767
defer func() {
68-
conditions.SetCondition(cb, &vm.Status.Conditions)
68+
if cb.Condition().Status == metav1.ConditionUnknown {
69+
conditions.RemoveCondition(vmcondition.TypeNetworkReady, &vm.Status.Conditions)
70+
} else {
71+
conditions.SetCondition(cb, &vm.Status.Conditions)
72+
}
6973
}()
7074

7175
if len(vm.Spec.Networks) > 1 {

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,14 @@ var _ = Describe("NetworkInterfaceHandler", func() {
134134
err := fakeClient.Get(ctx, client.ObjectKeyFromObject(vm), newVM)
135135
Expect(err).NotTo(HaveOccurred())
136136

137-
cond, exists := conditions.GetCondition(vmcondition.TypeNetworkReady, newVM.Status.Conditions)
138-
Expect(exists).To(BeTrue())
139-
Expect(cond.Status).To(Equal(metav1.ConditionUnknown))
140-
Expect(cond.Reason).To(Equal(conditions.ReasonUnknown.String()))
137+
_, exists := conditions.GetCondition(vmcondition.TypeNetworkReady, newVM.Status.Conditions)
138+
Expect(exists).To(BeFalse())
141139
Expect(newVM.Status.Networks).NotTo(BeNil())
142140
})
143141
})
144142

145143
Describe("NetworkSpec have only 'Main' interface", func() {
146-
It("Network status is not exist; Condition should have status 'False'", func() {
144+
It("Condition should have status 'Unknown'", func() {
147145
networkSpec := []v1alpha2.NetworksSpec{
148146
{
149147
Type: v1alpha2.NetworksTypeMain,
@@ -157,10 +155,8 @@ var _ = Describe("NetworkInterfaceHandler", func() {
157155
err := fakeClient.Get(ctx, client.ObjectKeyFromObject(vm), newVM)
158156
Expect(err).NotTo(HaveOccurred())
159157

160-
cond, exists := conditions.GetCondition(vmcondition.TypeNetworkReady, newVM.Status.Conditions)
161-
Expect(exists).To(BeTrue())
162-
Expect(cond.Status).To(Equal(metav1.ConditionUnknown))
163-
Expect(cond.Reason).To(Equal(conditions.ReasonUnknown.String()))
158+
_, exists := conditions.GetCondition(vmcondition.TypeNetworkReady, newVM.Status.Conditions)
159+
Expect(exists).To(BeFalse())
164160
Expect(newVM.Status.Networks).NotTo(BeNil())
165161
})
166162
})

0 commit comments

Comments
 (0)