Skip to content

Commit

Permalink
Merge pull request openshift#1583 from orenc1/rootvolume_accessmode_t…
Browse files Browse the repository at this point in the history
…uning

Add tuning option of AccessModes for Kubevirt NodePool root volume
  • Loading branch information
openshift-merge-robot authored Jul 30, 2022
2 parents d74698b + 6374caa commit a78f398
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 11 deletions.
14 changes: 14 additions & 0 deletions api/fixtures/example_kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fixtures

import (
"fmt"
"strings"

hyperv1 "github.com/openshift/hypershift/api/v1alpha1"
apiresource "k8s.io/apimachinery/pkg/api/resource"
Expand All @@ -15,23 +16,36 @@ type ExampleKubevirtOptions struct {
Image string
RootVolumeSize uint32
RootVolumeStorageClass string
RootVolumeAccessModes string
}

func ExampleKubeVirtTemplate(o *ExampleKubevirtOptions) *hyperv1.KubevirtNodePoolPlatform {
var storageClassName *string
var accessModesStr []string
var accessModes []hyperv1.PersistentVolumeAccessMode
volumeSize := apiresource.MustParse(fmt.Sprintf("%vGi", o.RootVolumeSize))

if o.RootVolumeStorageClass != "" {
storageClassName = &o.RootVolumeStorageClass
}

if o.RootVolumeAccessModes != "" {
accessModesStr = strings.Split(o.RootVolumeAccessModes, ",")
for _, ams := range accessModesStr {
var am hyperv1.PersistentVolumeAccessMode
am = hyperv1.PersistentVolumeAccessMode(ams)
accessModes = append(accessModes, am)
}
}

exampleTemplate := &hyperv1.KubevirtNodePoolPlatform{
RootVolume: &hyperv1.KubevirtRootVolume{
KubevirtVolume: hyperv1.KubevirtVolume{
Type: hyperv1.KubevirtVolumeTypePersistent,
Persistent: &hyperv1.KubevirtPersistentVolume{
Size: &volumeSize,
StorageClass: storageClassName,
AccessModes: accessModes,
},
},
},
Expand Down
10 changes: 9 additions & 1 deletion api/v1alpha1/nodepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,10 @@ type KubevirtCompute struct {
Cores *uint32 `json:"cores"`
}

// KubevirtPersistentVolume containes the values involved with provisioning persistent storage for a KubeVirt VM.
// +kubebuilder:validation:Enum=ReadWriteOnce;ReadWriteMany;ReadOnly;ReadWriteOncePod
type PersistentVolumeAccessMode corev1.PersistentVolumeAccessMode

// KubevirtPersistentVolume contains the values involved with provisioning persistent storage for a KubeVirt VM.
type KubevirtPersistentVolume struct {
// Size is the size of the persistent storage volume
//
Expand All @@ -447,6 +450,11 @@ type KubevirtPersistentVolume struct {
//
// +optional
StorageClass *string `json:"storageClass,omitempty"`
// AccessModes is an array that contains the desired Access Modes the root volume should have.
// More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes
//
// +optional
AccessModes []PersistentVolumeAccessMode `json:"accessModes,omitempty"`
}

// KubevirtRootVolume represents the volume that the rhcos disk will be stored and run from.
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cmd/cluster/core/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ type KubevirtPlatformCreateOptions struct {
ContainerDiskImage string
RootVolumeSize uint32
RootVolumeStorageClass string
RootVolumeAccessModes string
}

type AWSPlatformOptions struct {
Expand Down
1 change: 1 addition & 0 deletions cmd/cluster/kubevirt/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func applyPlatformSpecificsValues(ctx context.Context, exampleOptions *apifixtur
Image: opts.KubevirtPlatform.ContainerDiskImage,
RootVolumeSize: opts.KubevirtPlatform.RootVolumeSize,
RootVolumeStorageClass: opts.KubevirtPlatform.RootVolumeStorageClass,
RootVolumeAccessModes: opts.KubevirtPlatform.RootVolumeAccessModes,
}
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,18 @@ spec:
This is the default type used when no storage type is
defined.
properties:
accessModes:
description: 'AccessModes is an array that contains
the desired Access Modes the root volume should
have. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes'
items:
enum:
- ReadWriteOnce
- ReadWriteMany
- ReadOnly
- ReadWriteOncePod
type: string
type: array
size:
anyOf:
- type: integer
Expand Down
9 changes: 3 additions & 6 deletions cmd/nodepool/kubevirt/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type KubevirtPlatformCreateOptions struct {
ContainerDiskImage string
RootVolumeSize uint32
RootVolumeStorageClass string
RootVolumeAccessModes string
}

func NewCreateCommand(coreOpts *core.CreateNodePoolOptions) *cobra.Command {
Expand All @@ -35,14 +36,9 @@ func NewCreateCommand(coreOpts *core.CreateNodePoolOptions) *cobra.Command {
cmd.Flags().Uint32Var(&platformOpts.Cores, "cores", platformOpts.Cores, "The number of cores inside the vmi, Must be a value greater or equal 1")
cmd.Flags().StringVar(&platformOpts.RootVolumeStorageClass, "root-volume-storage-class", platformOpts.RootVolumeStorageClass, "The storage class to use for machines in the NodePool")
cmd.Flags().Uint32Var(&platformOpts.RootVolumeSize, "root-volume-size", platformOpts.RootVolumeSize, "The size of the root volume for machines in the NodePool in Gi")
cmd.Flags().StringVar(&platformOpts.RootVolumeAccessModes, "root-volume-access-modes", platformOpts.RootVolumeAccessModes, "The access modes of the root volume to use for machines in the NodePool (comma-delimited list)")
cmd.Flags().StringVar(&platformOpts.ContainerDiskImage, "containerdisk", platformOpts.ContainerDiskImage, "A reference to docker image with the embedded disk to be used to create the machines")

// TODO (nargaman): replace with official container image, after RFE-2501 is completed
// As long as there is no official container image
// The image must be provided by user
// Otherwise it must fail
cmd.MarkFlagRequired("containerdisk")

cmd.RunE = coreOpts.CreateRunFunc(platformOpts)

return cmd
Expand All @@ -55,6 +51,7 @@ func (o *KubevirtPlatformCreateOptions) UpdateNodePool(_ context.Context, nodePo
Image: o.ContainerDiskImage,
RootVolumeSize: o.RootVolumeSize,
RootVolumeStorageClass: o.RootVolumeStorageClass,
RootVolumeAccessModes: o.RootVolumeAccessModes,
})
return nil
}
Expand Down
24 changes: 23 additions & 1 deletion docs/content/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4737,7 +4737,7 @@ KubevirtCompute
<a href="#hypershift.openshift.io/v1alpha1.KubevirtVolume">KubevirtVolume</a>)
</p>
<p>
<p>KubevirtPersistentVolume containes the values involved with provisioning persistent storage for a KubeVirt VM.</p>
<p>KubevirtPersistentVolume contains the values involved with provisioning persistent storage for a KubeVirt VM.</p>
</p>
<table>
<thead>
Expand Down Expand Up @@ -4773,6 +4773,21 @@ string
<p>StorageClass is the storageClass used for the underlying PVC that hosts the volume</p>
</td>
</tr>
<tr>
<td>
<code>accessModes</code></br>
<em>
<a href="#hypershift.openshift.io/v1alpha1.PersistentVolumeAccessMode">
[]PersistentVolumeAccessMode
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>AccessModes is an array that contains the desired Access Modes the root volume should have.
More info: <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes">https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes</a></p>
</td>
</tr>
</tbody>
</table>
###KubevirtRootVolume { #hypershift.openshift.io/v1alpha1.KubevirtRootVolume }
Expand Down Expand Up @@ -5730,6 +5745,13 @@ the management cluster.</p>
</td>
</tr></tbody>
</table>
###PersistentVolumeAccessMode { #hypershift.openshift.io/v1alpha1.PersistentVolumeAccessMode }
<p>
(<em>Appears on:</em>
<a href="#hypershift.openshift.io/v1alpha1.KubevirtPersistentVolume">KubevirtPersistentVolume</a>)
</p>
<p>
</p>
###PersistentVolumeEtcdStorageSpec { #hypershift.openshift.io/v1alpha1.PersistentVolumeEtcdStorageSpec }
<p>
(<em>Appears on:</em>
Expand Down
12 changes: 12 additions & 0 deletions hack/app-sre/saas_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27126,6 +27126,18 @@ objects:
This is the default type used when no storage type
is defined.
properties:
accessModes:
description: 'AccessModes is an array that contains
the desired Access Modes the root volume should
have. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes'
items:
enum:
- ReadWriteOnce
- ReadWriteMany
- ReadOnly
- ReadWriteOncePod
type: string
type: array
size:
anyOf:
- type: integer
Expand Down
15 changes: 12 additions & 3 deletions hypershift-operator/controllers/nodepool/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,18 @@ func virtualMachineTemplateBase(image string, kvPlatform *hyperv1.KubevirtNodePo
}

if kvPlatform.RootVolume != nil &&
kvPlatform.RootVolume.Persistent != nil &&
kvPlatform.RootVolume.Persistent.StorageClass != nil {
dataVolume.Spec.Storage.StorageClassName = kvPlatform.RootVolume.Persistent.StorageClass
kvPlatform.RootVolume.Persistent != nil {
if kvPlatform.RootVolume.Persistent.StorageClass != nil {
dataVolume.Spec.Storage.StorageClassName = kvPlatform.RootVolume.Persistent.StorageClass
}
if len(kvPlatform.RootVolume.Persistent.AccessModes) != 0 {
var accessModes []corev1.PersistentVolumeAccessMode
for _, am := range kvPlatform.RootVolume.Persistent.AccessModes {
amv1 := corev1.PersistentVolumeAccessMode(am)
accessModes = append(accessModes, amv1)
}
dataVolume.Spec.Storage.AccessModes = accessModes
}
}

template.Spec.DataVolumeTemplates = []kubevirtv1.DataVolumeTemplateSpec{dataVolume}
Expand Down

0 comments on commit a78f398

Please sign in to comment.