-
Notifications
You must be signed in to change notification settings - Fork 1
feat(images): showing why cannot delete #859
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
base: main
Are you sure you want to change the base?
Conversation
39993d5
to
b98aa71
Compare
b98aa71
to
592b0dc
Compare
592b0dc
to
b62ece7
Compare
b25943b
to
501885a
Compare
Signed-off-by: Valeriy Khorunzhin <[email protected]>
Signed-off-by: Valeriy Khorunzhin <[email protected]>
Signed-off-by: Valeriy Khorunzhin <[email protected]>
Signed-off-by: Valeriy Khorunzhin <[email protected]>
501885a
to
71ca641
Compare
Signed-off-by: mortelumina98 <[email protected]>
inUseCondition, _ := conditions.GetCondition(cvicondition.InUseType, cvi.Status.Conditions) | ||
if inUseCondition.Status == metav1.ConditionTrue && conditions.IsLastUpdated(inUseCondition, cvi) { | ||
controllerutil.AddFinalizer(cvi, virtv2.FinalizerCVICleanup) | ||
return reconcile.Result{}, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall do cleanup and drop finalaizer if resource termigating
limitations under the License. | ||
*/ | ||
|
||
package internal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename file to suite_test.go
"github.com/deckhouse/virtualization/api/core/v1alpha2/cvicondition" | ||
) | ||
|
||
var _ = DescribeTable("InUseHandler Handle", func(args inUseHandlerTestArgs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check unit tests in vm handlers. We have some helprers for register specs
objects = append(objects, &cvi) | ||
} | ||
|
||
fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(objects...).WithIndex( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see testutil package
@@ -55,6 +55,14 @@ func (h LifeCycleHandler) Handle(ctx context.Context, cvi *virtv2.ClusterVirtual | |||
} | |||
|
|||
if cvi.DeletionTimestamp != nil { | |||
if readyCondition.Status == metav1.ConditionTrue { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why it is needed?
switch len(vds.Items) { | ||
case 1: | ||
messageBuilder.WriteString(fmt.Sprintf("ClusterVirtualImage is currently being used to create the VirtualDisk %s/%s", vds.Items[0].Namespace, vds.Items[0].Name)) | ||
case 2, 3: | ||
var vdNamespacedNames []string | ||
for _, vd := range vds.Items { | ||
vdNamespacedNames = append(vdNamespacedNames, fmt.Sprintf("%s/%s", vd.Namespace, vd.Name)) | ||
} | ||
messageBuilder.WriteString(fmt.Sprintf("ClusterVirtualImage is currently being used to create the VirtualDisks: %s", strings.Join(vdNamespacedNames, ", "))) | ||
default: | ||
messageBuilder.WriteString(fmt.Sprintf("ClusterVirtualImage is used to create %d VirtualDisks", len(vds.Items))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This switch statement appears to be overly complex. I notice that you are writing separate messages for one item, two or three items, and a larger number of items. It seems this logic could be simplified into a single if len(...) <= 3 {} else {}
structure.
switch len(vmUsedImage) { | ||
case 1: | ||
messageBuilder.WriteString(fmt.Sprintf("The ClusterVirtualImage is currently attached to the VirtualMachine %s/%s", vmUsedImage[0].Namespace, vmUsedImage[0].Name)) | ||
case 2, 3: | ||
var vmNamespacedNames []string | ||
for _, vm := range vmUsedImage { | ||
vmNamespacedNames = append(vmNamespacedNames, fmt.Sprintf("%s/%s", vm.Namespace, vm.Name)) | ||
} | ||
messageBuilder.WriteString(fmt.Sprintf("The ClusterVirtualImage is currently attached to the VirtualMachines: %s", strings.Join(vmNamespacedNames, ", "))) | ||
default: | ||
messageBuilder.WriteString(fmt.Sprintf("%d VirtualMachines are using the ClusterVirtualImage", len(vmUsedImage))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This switch statement appears to be overly complex. I notice that you are writing separate messages for one item, two or three items, and a larger number of items. It seems this logic could be simplified into a single if len(...) <= 3 {} else {}
structure.
|
||
var vis virtv2.VirtualImageList | ||
err = h.client.List(ctx, &vis, client.MatchingFields{ | ||
indexer.IndexFieldVIByCVIDataSourceNotReady: cvi.GetName(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should filter ready sources here instead. This would eliminate the need for an additional indexer.
|
||
var cvis virtv2.ClusterVirtualImageList | ||
err = h.client.List(ctx, &cvis, client.MatchingFields{ | ||
indexer.IndexFieldCVIByCVIDataSourceNotReady: cvi.GetName(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should filter ready sources here instead. This would eliminate the need for an additional indexer.
|
||
var vds virtv2.VirtualDiskList | ||
err = h.client.List(ctx, &vds, client.MatchingFields{ | ||
indexer.IndexFieldVDByCVIDataSourceNotReady: cvi.GetName(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should filter ready sources here instead. This would eliminate the need for an additional indexer.
Description
Resources preventing the deletion of VirtualImage and ClusterVirtualImage are being displayed.
Why do we need it, and what problem does it solve?
What is the expected result?
Checklist
Changelog entries