Skip to content

fix(vi): validate VirtualImage storage class#852

Closed
hardcoretime wants to merge 3 commits intomainfrom
fix/vi/validate-vi-storageclass
Closed

fix(vi): validate VirtualImage storage class#852
hardcoretime wants to merge 3 commits intomainfrom
fix/vi/validate-vi-storageclass

Conversation

@hardcoretime
Copy link
Copy Markdown
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
Comment thread images/virtualization-artifact/pkg/controller/vi/vi_webhook.go
}

func (v *Validator) validateStorageClass(ctx context.Context, vi *virtv2.VirtualImage) (admission.Warnings, error) {
if vi.Spec.PersistentVolumeClaim != (virtv2.VirtualImagePersistentVolumeClaim{}) {
Copy link
Copy Markdown
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?

Comment thread images/virtualization-artifact/pkg/controller/vi/vi_webhook.go
Comment thread images/virtualization-artifact/pkg/controller/vi/vi_webhook.go
Comment thread images/virtualization-artifact/pkg/controller/vi/vi_webhook.go
return nil, nil
}

func (v *Validator) validateStorageClass(ctx context.Context, vi *virtv2.VirtualImage) (admission.Warnings, error) {
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread images/virtualization-artifact/pkg/controller/moduleconfig/util.go
@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
@universal-itengineer universal-itengineer modified the milestones: v0.18.0, v0.19.0 May 12, 2025
@Isteb4k Isteb4k modified the milestones: v0.19.0, v0.20.0 May 29, 2025
@nevermarine nevermarine modified the milestones: v0.20.0, v0.21.0 Jun 17, 2025
@nevermarine nevermarine modified the milestones: v0.21.0, v0.22.0 Jun 26, 2025
@universal-itengineer universal-itengineer modified the milestones: v0.22.0, v0.23.0 Jul 10, 2025
@nevermarine nevermarine modified the milestones: v0.23.0, v0.24.0 Jul 24, 2025
@universal-itengineer universal-itengineer modified the milestones: v0.24.0, v0.25.0 Aug 8, 2025
@hardcoretime hardcoretime deleted the fix/vi/validate-vi-storageclass branch August 20, 2025 08:22
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.

4 participants