Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cvi,vi): unlock pending vi/cvi from vd ref #416

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

LopatinDmitr
Copy link
Contributor

@LopatinDmitr LopatinDmitr commented Oct 2, 2024

Description

  • Add conditon 'InUse" for VirtualDisk. This condition indicate:
    • that the VirtualDisk may be used for create ClusterVirtualImage or VirtualImage
    • that the VirtualDisk may be attached to running VirtualMachine

Why do we need it, and what problem does it solve?

Fix problem with lock VirtualImage and ClusterVirtual image in phase 'Pending' after stopping or deleting VirtualMachine, when used needed VirtualDisk in them.

What is the expected result?

Checklist

  • The code is covered by unit tests.
  • e2e tests passed.
  • Documentation updated according to the changes.
  • Changes were tested in the Kubernetes cluster manually.

@LopatinDmitr LopatinDmitr requested a review from Isteb4k October 7, 2024 15:28
@LopatinDmitr LopatinDmitr marked this pull request as ready for review October 7, 2024 15:28
@LopatinDmitr LopatinDmitr force-pushed the fix/vi/unlock-pending-vi-from-vd-ref branch 2 times, most recently from 45552d1 to 8e5b4f1 Compare October 13, 2024 09:29
@LopatinDmitr LopatinDmitr changed the title fix(vi): unlock pending vi from vd ref fix(cvi,vi): unlock pending vi/cvi from vd ref Oct 13, 2024
@LopatinDmitr LopatinDmitr requested a review from Isteb4k October 14, 2024 20:37
@Isteb4k Isteb4k self-requested a review October 15, 2024 16:29
@LopatinDmitr LopatinDmitr force-pushed the fix/vi/unlock-pending-vi-from-vd-ref branch from 523f4a4 to f8134b5 Compare October 21, 2024 08:36
@LopatinDmitr LopatinDmitr requested review from Isteb4k and diafour and removed request for Isteb4k October 23, 2024 21:14
@LopatinDmitr LopatinDmitr force-pushed the fix/vi/unlock-pending-vi-from-vd-ref branch from 70fd271 to 0f11fd4 Compare October 27, 2024 19:57
@LopatinDmitr LopatinDmitr force-pushed the fix/vi/unlock-pending-vi-from-vd-ref branch 8 times, most recently from d37bad7 to 7b7bcd5 Compare October 29, 2024 20:42
@LopatinDmitr LopatinDmitr marked this pull request as draft October 30, 2024 09:11
@LopatinDmitr LopatinDmitr force-pushed the fix/vi/unlock-pending-vi-from-vd-ref branch from 7b7bcd5 to 11bbb7f Compare October 30, 2024 12:12
@LopatinDmitr LopatinDmitr requested a review from Isteb4k November 22, 2024 08:25
@LopatinDmitr LopatinDmitr marked this pull request as ready for review November 22, 2024 08:25
@LopatinDmitr LopatinDmitr force-pushed the fix/vi/unlock-pending-vi-from-vd-ref branch 6 times, most recently from f5f5d24 to 2c03739 Compare November 22, 2024 13:16
@LopatinDmitr LopatinDmitr force-pushed the fix/vi/unlock-pending-vi-from-vd-ref branch 7 times, most recently from 8d2b638 to 8b0c8b6 Compare November 26, 2024 19:49
@LopatinDmitr LopatinDmitr marked this pull request as draft November 27, 2024 08:47
@LopatinDmitr LopatinDmitr force-pushed the fix/vi/unlock-pending-vi-from-vd-ref branch 2 times, most recently from 03a7ea4 to a959b5b Compare December 4, 2024 21:02
@LopatinDmitr LopatinDmitr requested a review from Isteb4k December 5, 2024 06:41
@LopatinDmitr LopatinDmitr marked this pull request as ready for review December 5, 2024 06:42
@LopatinDmitr LopatinDmitr force-pushed the fix/vi/unlock-pending-vi-from-vd-ref branch from a959b5b to 3132202 Compare December 9, 2024 08:03
Signed-off-by: dmitry.lopatin <[email protected]>
@LopatinDmitr LopatinDmitr force-pushed the fix/vi/unlock-pending-vi-from-vd-ref branch from 3132202 to c7c091c Compare December 9, 2024 08:05
@@ -34,6 +34,8 @@ const (
SnapshottingType Type = "Snapshotting"
// StorageClassReadyType indicates whether the storage class is ready.
StorageClassReadyType Type = "StorageClassReady"
// InUseType indicates whether the VirtualDisk is attached to a running VirtualMachine or is being used in a process of a VirtualImage creation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of an image creation

allowedPhases := []virtv2.ImagePhase{virtv2.ImageProvisioning, virtv2.ImagePending}

for _, vi := range vis.Items {
if slices.Contains(allowedPhases, vi.Status.Phase) && vi.Spec.DataSource.Type == virtv2.DataSourceTypeObjectRef && vi.Spec.DataSource.ObjectRef != nil && vi.Spec.DataSource.ObjectRef.Kind == virtv2.VirtualDiskKind {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vi.Spec.DataSource.ObjectRef.Name == vd.Name

allowedPhases := []virtv2.ImagePhase{virtv2.ImageProvisioning, virtv2.ImagePending}

for _, vi := range vis.Items {
if slices.Contains(allowedPhases, vi.Status.Phase) && vi.Spec.DataSource.Type == virtv2.DataSourceTypeObjectRef && vi.Spec.DataSource.ObjectRef != nil && vi.Spec.DataSource.ObjectRef.Kind == virtv2.VirtualDiskKind {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too long line

cb := conditions.NewConditionBuilder(vdcondition.InUseType)

switch {
case allowUseForVM && inUseCondition.Status == metav1.ConditionUnknown:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a little optimization is possible here: you dont have to list vi and cvi if allowUseForVM is true

conditions.SetCondition(cb, &vd.Status.Conditions)
}
default:
needChange := false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mb rename to setUnkown := false ?

import (
"context"

"github.com/onsi/ginkgo/v2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why dont use dot import alias?

})

ginkgo.Context("when VirtualDisk is used by not ready VirtualMachine", func() {
ginkgo.It("must set status True and reason AllowedForVirtualMachineUsage", func() {
Copy link
Contributor

@Isteb4k Isteb4k Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it sets Unknown

})
})

ginkgo.Context("when VirtualDisk is not in use after create image", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after image creation

})
})

ginkgo.Context("when VirtualDisk is not in use after running VM", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after VM deletion

Namespace: vm.GetNamespace(),
LabelSelector: labels.SelectorFromSet(map[string]string{virtv1.VirtualMachineNameLabel: vm.GetName()}),
})
if err != nil && !k8serrors.IsNotFound(err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List cannot return not found error

Signed-off-by: dmitry.lopatin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants