Skip to content

fix(vi): validate VirtualImage storage class #852

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

hardcoretime
Copy link
Contributor

@hardcoretime hardcoretime commented Mar 12, 2025

Description

A temporary solution until the problem with PersistentVolumeMode is resolved.

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

This is currently required to prevent a VirtualImage from being created with the PersistentVolumeFilesystem storage class.

What is the expected result?

VirtualImage cannot be created the PersistentVolumeFilesystem storage class.

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.

Changelog entries

section: vi 
type: fix
summary:  "Prevent a `VirtualImage` from being created with the `PersistentVolumeFilesystem` storage class."
impact_level: high
impact: |
  `VirtualImage` cannot be created the `PersistentVolumeFilesystem` storage class.

@hardcoretime hardcoretime added this to the v0.18.0 milestone Mar 12, 2025
@hardcoretime hardcoretime force-pushed the fix/vi/validate-vi-storageclass branch 19 times, most recently from 1a24522 to bdbb8dc Compare March 14, 2025 01:12
@hardcoretime hardcoretime marked this pull request as ready for review March 14, 2025 01:35
Signed-off-by: Roman Sysoev <roman.sysoev@flant.com>
@hardcoretime hardcoretime force-pushed the fix/vi/validate-vi-storageclass branch from bdbb8dc to eb2917a Compare March 14, 2025 02:23
@@ -114,3 +131,36 @@ func (v *Validator) ValidateDelete(_ context.Context, _ runtime.Object) (admissi
v.logger.Error("Ensure the correctness of ValidatingWebhookConfiguration", "err", err)
return nil, nil
}

func (v *Validator) validateStorageClass(ctx context.Context, vi *virtv2.VirtualImage) (admission.Warnings, error) {
if vi.Spec.PersistentVolumeClaim != (virtv2.VirtualImagePersistentVolumeClaim{}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you decide not to check vi.Spec.Storage if vi.Spec.PersistentVolumeClaim is empty?

@@ -114,3 +131,36 @@ func (v *Validator) ValidateDelete(_ context.Context, _ runtime.Object) (admissi
v.logger.Error("Ensure the correctness of ValidatingWebhookConfiguration", "err", err)
return nil, nil
}

func (v *Validator) validateStorageClass(ctx context.Context, vi *virtv2.VirtualImage) (admission.Warnings, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We want to check and prevent the creation of images not only for the storage class from the spec but also for default storage classes. This way, the user won't wait unnecessarily for an image that will never be created. Or was this check intentionally not added?

if len(scProfile.Status.ClaimPropertySets) == 0 {
return reconcile.Result{}, fmt.Errorf("failed to validate the `PersistentVolumeMode` of the `StorageProfile`: %s", sc.Name)
}
if *scProfile.Status.ClaimPropertySets[0].VolumeMode == corev1.PersistentVolumeFilesystem {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add the test case to ensure that the condition will be false if the storage class is not ReadWriteMany and Block.

@hardcoretime hardcoretime marked this pull request as draft March 14, 2025 18:58
@hardcoretime hardcoretime marked this pull request as ready for review March 27, 2025 11:45
@hardcoretime hardcoretime marked this pull request as draft March 27, 2025 15:37
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.

2 participants