-
Notifications
You must be signed in to change notification settings - Fork 303
/
create.go
90 lines (78 loc) · 4.57 KB
/
create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package kubevirt
import (
"context"
"fmt"
"github.com/openshift/hypershift/api/fixtures"
"github.com/spf13/cobra"
crclient "sigs.k8s.io/controller-runtime/pkg/client"
hyperv1 "github.com/openshift/hypershift/api/v1beta1"
"github.com/openshift/hypershift/cmd/nodepool/core"
)
type KubevirtPlatformCreateOptions struct {
Memory string
Cores uint32
ContainerDiskImage string
RootVolumeSize uint32
RootVolumeStorageClass string
RootVolumeAccessModes string
RootVolumeVolumeMode string
CacheStrategyType string
NetworkInterfaceMultiQueue string
}
func NewCreateCommand(coreOpts *core.CreateNodePoolOptions) *cobra.Command {
platformOpts := &KubevirtPlatformCreateOptions{
Memory: "4Gi",
Cores: 2,
ContainerDiskImage: "",
RootVolumeSize: 32,
CacheStrategyType: "",
NetworkInterfaceMultiQueue: "",
}
cmd := &cobra.Command{
Use: "kubevirt",
Short: "Creates basic functional NodePool resources for KubeVirt platform",
SilenceUsage: true,
}
cmd.Flags().StringVar(&platformOpts.Memory, "memory", platformOpts.Memory, "The amount of memory which is visible inside the Guest OS (type BinarySI, e.g. 5Gi, 100Mi)")
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.RootVolumeVolumeMode, "root-volume-volume-mode", platformOpts.RootVolumeVolumeMode, "The volume mode of the root volume to use for machines in the NodePool. Supported values are \"Block\", \"Filesystem\"")
cmd.Flags().StringVar(&platformOpts.ContainerDiskImage, "containerdisk", platformOpts.ContainerDiskImage, "A reference to docker image with the embedded disk to be used to create the machines")
cmd.Flags().StringVar(&platformOpts.CacheStrategyType, "root-volume-cache-strategy", platformOpts.CacheStrategyType, "Set the boot image caching strategy; Supported values:\n- \"None\": no caching (default).\n- \"PVC\": Cache into a PVC; only for QCOW image; ignored for container images")
cmd.Flags().StringVar(&platformOpts.NetworkInterfaceMultiQueue, "network-multiqueue", platformOpts.NetworkInterfaceMultiQueue, `If "Enable", virtual network interfaces configured with a virtio bus will also enable the vhost multiqueue feature for network devices. supported values are "Enable" and "Disable"; default = "Disable"`)
cmd.RunE = coreOpts.CreateRunFunc(platformOpts)
return cmd
}
func (o *KubevirtPlatformCreateOptions) UpdateNodePool(_ context.Context, nodePool *hyperv1.NodePool, _ *hyperv1.HostedCluster, _ crclient.Client) error {
if o.CacheStrategyType != "" &&
o.CacheStrategyType != string(hyperv1.KubevirtCachingStrategyNone) &&
o.CacheStrategyType != string(hyperv1.KubevirtCachingStrategyPVC) {
return fmt.Errorf(`wrong value for the --root-volume-cache-strategy parameter. May be only "None" or "PVC"`)
}
var multiQueue *hyperv1.MultiQueueSetting
switch o.NetworkInterfaceMultiQueue {
case "": // do nothing; value is nil
case string(hyperv1.MultiQueueEnable), string(hyperv1.MultiQueueDisable):
value := hyperv1.MultiQueueSetting(o.NetworkInterfaceMultiQueue)
multiQueue = &value
default:
return fmt.Errorf(`wrong value for the --network-multiqueue parameter. May be only "Enable" or "Disable"`)
}
nodePool.Spec.Platform.Kubevirt = fixtures.ExampleKubeVirtTemplate(&fixtures.ExampleKubevirtOptions{
Memory: o.Memory,
Cores: o.Cores,
Image: o.ContainerDiskImage,
RootVolumeSize: o.RootVolumeSize,
RootVolumeStorageClass: o.RootVolumeStorageClass,
RootVolumeAccessModes: o.RootVolumeAccessModes,
RootVolumeVolumeMode: o.RootVolumeVolumeMode,
CacheStrategyType: o.CacheStrategyType,
NetworkInterfaceMultiQueue: multiQueue,
})
return nil
}
func (o *KubevirtPlatformCreateOptions) Type() hyperv1.PlatformType {
return hyperv1.KubevirtPlatform
}