Skip to content

Commit

Permalink
fix(vd): fix create vd from vi on pvc (#552)
Browse files Browse the repository at this point in the history
Signed-off-by: dmitry.lopatin <[email protected]>
Co-authored-by: Valeriy Khorunzhin <[email protected]>
  • Loading branch information
LopatinDmitr and eofff authored Dec 5, 2024
1 parent 09830be commit 6f05a20
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, vd *virtv2.VirtualDisk)
}

switch vi.Spec.Storage {
case virtv2.StorageKubernetes:
case virtv2.StorageKubernetes,
virtv2.StoragePersistentVolumeClaim:
return ds.viPVCSyncer.Sync(ctx, vd)
case virtv2.StorageContainerRegistry:
return ds.viDVCRSyncer.Sync(ctx, vd)
Expand Down Expand Up @@ -117,7 +118,8 @@ func (ds ObjectRefDataSource) Validate(ctx context.Context, vd *virtv2.VirtualDi
}

switch vi.Spec.Storage {
case virtv2.StorageKubernetes:
case virtv2.StorageKubernetes,
virtv2.StoragePersistentVolumeClaim:
return ds.viPVCSyncer.Validate(ctx, vd)
case virtv2.StorageContainerRegistry:
return ds.viDVCRSyncer.Validate(ctx, vd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (h LifeCycleHandler) Handle(ctx context.Context, vi *virtv2.VirtualImage) (
return reconcile.Result{Requeue: true}, fmt.Errorf("condition %s not found", vicondition.StorageClassReadyType)
}

if readyCondition.Status != metav1.ConditionTrue && vi.Spec.Storage == virtv2.StorageKubernetes && storageClassReadyCondition.Status != metav1.ConditionTrue {
if readyCondition.Status != metav1.ConditionTrue && (vi.Spec.Storage == virtv2.StorageKubernetes || vi.Spec.Storage == virtv2.StoragePersistentVolumeClaim) && storageClassReadyCondition.Status != metav1.ConditionTrue {
readyCB := conditions.NewConditionBuilder(vicondition.ReadyType).
Generation(vi.Generation).
Status(metav1.ConditionFalse).
Expand All @@ -102,7 +102,7 @@ func (h LifeCycleHandler) Handle(ctx context.Context, vi *virtv2.VirtualImage) (
conditions.SetCondition(readyCB, &vi.Status.Conditions)
}

if vi.Spec.Storage == virtv2.StorageKubernetes &&
if (vi.Spec.Storage == virtv2.StorageKubernetes || vi.Spec.Storage == virtv2.StoragePersistentVolumeClaim) &&
readyCondition.Status != metav1.ConditionTrue &&
storageClassReadyCondition.Status != metav1.ConditionTrue &&
vi.Status.StorageClassName != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ var _ = Describe("LifeCycleHandler Run", func() {
Status: metav1.ConditionFalse,
},
StorageClassInStatus: "sc",
StorageType: virtv2.StorageKubernetes,
StorageType: virtv2.StoragePersistentVolumeClaim,
ExpectCleanup: true,
},
),
Expand Down Expand Up @@ -196,7 +196,7 @@ var _ = Describe("LifeCycleHandler Run", func() {
Status: metav1.ConditionFalse,
},
StorageClassInStatus: "",
StorageType: virtv2.StorageKubernetes,
StorageType: virtv2.StoragePersistentVolumeClaim,
ExpectCleanup: false,
},
),
Expand All @@ -210,7 +210,7 @@ var _ = Describe("LifeCycleHandler Run", func() {
Status: metav1.ConditionFalse,
},
StorageClassInStatus: "sc",
StorageType: virtv2.StorageKubernetes,
StorageType: virtv2.StoragePersistentVolumeClaim,
ExpectCleanup: false,
},
),
Expand All @@ -224,7 +224,7 @@ var _ = Describe("LifeCycleHandler Run", func() {
Status: metav1.ConditionTrue,
},
StorageClassInStatus: "sc",
StorageType: virtv2.StorageKubernetes,
StorageType: virtv2.StoragePersistentVolumeClaim,
ExpectCleanup: false,
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var _ = Describe("StorageClassHandler Run", func() {
"StorageClassReady must be false because no storage class can be return",
handlerTestArgs{
DiskServiceMock: newDiskServiceMock(nil),
VI: newVI(nil, virtv2.StorageKubernetes),
VI: newVI(nil, virtv2.StoragePersistentVolumeClaim),
ExpectedCondition: metav1.Condition{
Status: metav1.ConditionFalse,
Reason: vicondition.StorageClassNotFound.String(),
Expand All @@ -70,7 +70,7 @@ var _ = Describe("StorageClassHandler Run", func() {
"StorageClassReady must be true because storage class from spec found",
handlerTestArgs{
DiskServiceMock: newDiskServiceMock(ptr.To("sc")),
VI: newVI(ptr.To("sc"), virtv2.StorageKubernetes),
VI: newVI(ptr.To("sc"), virtv2.StoragePersistentVolumeClaim),
ExpectedCondition: metav1.Condition{
Status: metav1.ConditionTrue,
Reason: vicondition.StorageClassReady.String(),
Expand All @@ -81,7 +81,7 @@ var _ = Describe("StorageClassHandler Run", func() {
"StorageClassReady must be true because default storage class found",
handlerTestArgs{
DiskServiceMock: newDiskServiceMock(ptr.To("sc")),
VI: newVI(ptr.To("sc"), virtv2.StorageKubernetes),
VI: newVI(ptr.To("sc"), virtv2.StoragePersistentVolumeClaim),
ExpectedCondition: metav1.Condition{
Status: metav1.ConditionTrue,
Reason: vicondition.StorageClassReady.String(),
Expand Down

0 comments on commit 6f05a20

Please sign in to comment.