Skip to content

Commit

Permalink
feat(vd): resize-condition-to-resizing
Browse files Browse the repository at this point in the history
Signed-off-by: Daniil Antoshin <[email protected]>

fix: tests

Signed-off-by: Daniil Antoshin <[email protected]>

fix

Signed-off-by: Daniil Antoshin <[email protected]>
  • Loading branch information
danilrwx committed Dec 12, 2024
1 parent afe682a commit 412e37a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions api/core/v1alpha2/vdcondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const (
DatasourceReadyType Type = "DatasourceReady"
// ReadyType indicates whether the import process succeeded and the `VirtualDisk` is ready for use.
ReadyType Type = "Ready"
// ResizedType indicates whether the disk resizing operation is completed.
ResizedType Type = "Resized"
// ResizingType indicates whether the disk resizing operation is completed.
ResizingType Type = "Resizing"
// SnapshottingType indicates whether the disk snapshotting operation is in progress.
SnapshottingType Type = "Snapshotting"
// StorageClassReadyType indicates whether the storage class is ready.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func NewResizingHandler(diskService DiskService) *ResizingHandler {
func (h ResizingHandler) Handle(ctx context.Context, vd *virtv2.VirtualDisk) (reconcile.Result, error) {
log := logger.FromContext(ctx).With(logger.SlogHandler("resizing"))

condition, _ := conditions.GetCondition(vdcondition.ResizedType, vd.Status.Conditions)
cb := conditions.NewConditionBuilder(vdcondition.ResizedType).Generation(vd.Generation)
condition, _ := conditions.GetCondition(vdcondition.ResizingType, vd.Status.Conditions)
cb := conditions.NewConditionBuilder(vdcondition.ResizingType).Generation(vd.Generation)

defer func() { conditions.SetCondition(cb, &vd.Status.Conditions) }()

Expand Down Expand Up @@ -107,7 +107,7 @@ func (h ResizingHandler) Handle(ctx context.Context, vd *virtv2.VirtualDisk) (re

vd.Status.Phase = virtv2.DiskResizing
cb.
Status(metav1.ConditionFalse).
Status(metav1.ConditionTrue).
Reason(vdcondition.InProgress).
Message(pvcResizing.Message)
return reconcile.Result{}, nil
Expand Down Expand Up @@ -155,7 +155,7 @@ func (h ResizingHandler) Handle(ctx context.Context, vd *virtv2.VirtualDisk) (re

vd.Status.Phase = virtv2.DiskResizing
cb.
Status(metav1.ConditionFalse).
Status(metav1.ConditionTrue).
Reason(vdcondition.InProgress).
Message("The virtual disk resizing has started.")
return reconcile.Result{}, nil
Expand All @@ -165,7 +165,7 @@ func (h ResizingHandler) Handle(ctx context.Context, vd *virtv2.VirtualDisk) (re
switch condition.Reason {
case vdcondition.InProgress.String(), vdcondition.Resized.String():
cb.
Status(metav1.ConditionTrue).
Status(metav1.ConditionFalse).
Reason(vdcondition.Resized).
Message("")
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ var _ = Describe("Resizing handler Run", func() {

_, err := h.Handle(testContext(), vd)
Expect(err).To(BeNil())
resized, _ := conditions.GetCondition(vdcondition.ResizedType, vd.Status.Conditions)
Expect(resized.Status).To(Equal(metav1.ConditionFalse))
resized, _ := conditions.GetCondition(vdcondition.ResizingType, vd.Status.Conditions)
Expect(resized.Status).To(Equal(metav1.ConditionTrue))
Expect(resized.Reason).To(Equal(vdcondition.InProgress.String()))
})

Expand All @@ -116,7 +116,7 @@ var _ = Describe("Resizing handler Run", func() {

_, err := h.Handle(testContext(), vd)
Expect(err).To(BeNil())
resized, _ := conditions.GetCondition(vdcondition.ResizedType, vd.Status.Conditions)
resized, _ := conditions.GetCondition(vdcondition.ResizingType, vd.Status.Conditions)
Expect(resized.Status).To(Equal(metav1.ConditionFalse))
Expect(resized.Reason).To(Equal(vdcondition.ResizingNotRequested.String()))
})
Expand All @@ -128,7 +128,7 @@ var _ = Describe("Resizing handler Run", func() {

_, err := h.Handle(testContext(), vd)
Expect(err).To(BeNil())
resized, _ := conditions.GetCondition(vdcondition.ResizedType, vd.Status.Conditions)
resized, _ := conditions.GetCondition(vdcondition.ResizingType, vd.Status.Conditions)
Expect(resized.Status).To(Equal(metav1.ConditionFalse))
Expect(resized.Reason).To(Equal(vdcondition.ResizingNotRequested.String()))
})
Expand All @@ -138,7 +138,7 @@ var _ = Describe("Resizing handler Run", func() {

_, err := h.Handle(testContext(), vd)
Expect(err).To(BeNil())
resized, _ := conditions.GetCondition(vdcondition.ResizedType, vd.Status.Conditions)
resized, _ := conditions.GetCondition(vdcondition.ResizingType, vd.Status.Conditions)
Expect(resized.Status).To(Equal(metav1.ConditionFalse))
Expect(resized.Reason).To(Equal(vdcondition.ResizingNotRequested.String()))
})
Expand All @@ -150,14 +150,14 @@ var _ = Describe("Resizing handler Run", func() {

_, err := h.Handle(testContext(), vd)
Expect(err).To(BeNil())
resized, _ := conditions.GetCondition(vdcondition.ResizedType, vd.Status.Conditions)
Expect(resized.Status).To(Equal(metav1.ConditionFalse))
resized, _ := conditions.GetCondition(vdcondition.ResizingType, vd.Status.Conditions)
Expect(resized.Status).To(Equal(metav1.ConditionTrue))
Expect(resized.Reason).To(Equal(vdcondition.InProgress.String()))
})

It("Resize has completed", func() {
vd.Status.Conditions = append(vd.Status.Conditions, metav1.Condition{
Type: vdcondition.ResizedType.String(),
Type: vdcondition.ResizingType.String(),
Status: metav1.ConditionFalse,
Reason: vdcondition.InProgress.String(),
})
Expand All @@ -166,8 +166,8 @@ var _ = Describe("Resizing handler Run", func() {

_, err := h.Handle(testContext(), vd)
Expect(err).To(BeNil())
resized, _ := conditions.GetCondition(vdcondition.ResizedType, vd.Status.Conditions)
Expect(resized.Status).To(Equal(metav1.ConditionTrue))
resized, _ := conditions.GetCondition(vdcondition.ResizingType, vd.Status.Conditions)
Expect(resized.Status).To(Equal(metav1.ConditionFalse))
Expect(resized.Reason).To(Equal(vdcondition.Resized.String()))
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (h SnapshottingHandler) Handle(ctx context.Context, vd *virtv2.VirtualDisk)
continue
}

resized, _ := conditions.GetCondition(vdcondition.ResizedType, vd.Status.Conditions)
resized, _ := conditions.GetCondition(vdcondition.ResizingType, vd.Status.Conditions)
if resized.Reason == vdcondition.InProgress.String() {
cb.
Status(metav1.ConditionFalse).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ func (h LifeCycleHandler) ensureBlockDeviceConsistency(ctx context.Context, vm *
return fmt.Errorf("%w: waiting for the Ready condition of the virtual disk %q to be True", ErrVirtualDiskResizing, vd.Name)
}

resizingReady, _ := conditions.GetCondition(vdcondition.ResizedType, vd.Status.Conditions)
resizingReady, _ := conditions.GetCondition(vdcondition.ResizingType, vd.Status.Conditions)
if resizingReady.Reason == vdcondition.InProgress.String() {
return fmt.Errorf("%w: waiting for the virtual disk %q to be resized", ErrVirtualDiskResizing, vd.Name)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var _ = Describe("LifeCycle handler", func() {
Status: metav1.ConditionTrue,
},
{
Type: vdcondition.Resized.String(),
Type: vdcondition.ResizingType.String(),
Status: metav1.ConditionTrue,
Reason: vdcondition.Resized.String(),
},
Expand Down Expand Up @@ -198,7 +198,7 @@ var _ = Describe("LifeCycle handler", func() {

It("The virtual disk is the process of Resizing", func() {
snapshotter.GetVirtualDiskFunc = func(_ context.Context, _, _ string) (*virtv2.VirtualDisk, error) {
cb := conditions.NewConditionBuilder(vdcondition.Resized).
cb := conditions.NewConditionBuilder(vdcondition.ResizingType).
Generation(vd.Generation).
Status(metav1.ConditionFalse).
Reason(vdcondition.InProgress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ func (w VirtualDiskWatcher) filterUpdateEvents(e event.UpdateEvent) bool {
return false
}

oldResized, _ := conditions.GetCondition(vdcondition.ResizedType, oldVD.Status.Conditions)
newResized, _ := conditions.GetCondition(vdcondition.ResizedType, newVD.Status.Conditions)
oldResized, _ := conditions.GetCondition(vdcondition.ResizingType, oldVD.Status.Conditions)
newResized, _ := conditions.GetCondition(vdcondition.ResizingType, newVD.Status.Conditions)

return oldResized.Status != newResized.Status || oldResized.Reason != newResized.Reason
}

0 comments on commit 412e37a

Please sign in to comment.