-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[kubevirt] unify template and make a http datavolume import the default
Prepares the hypershift cli to auto-detect the required rhcos version from the cluster release payload. Since this is not known at cluster creation time, template parameters are introduced: `{rhcos:openstack:checksum}` for container disks, and `{rhcos:openstack:url}` for datavolume imports. The hypershift cli is extended the following way: * By default the hypershift CLI adds now a datavolume which will http-import the later-on auto-detected rhcos image. * `--containerdisk-repository` can be specified, to let the cluster figure out the right rhcos version when containerdisks should be used. Example: `--containerdisk-repository=quay.io/containerdisks/rhcos`. * `--root-volume-size` and `--root-volume-storage-class` can be used to customize the datavolume. Finally the nodepool-create and the cluster-create command now share the same kubevirt template to remove the duplication. Signed-off-by: Roman Mohr <rmohr@redhat.com>
- Loading branch information
Showing
9 changed files
with
218 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package fixtures | ||
|
||
import ( | ||
"fmt" | ||
|
||
hyperv1 "github.com/openshift/hypershift/api/v1alpha1" | ||
"github.com/openshift/hypershift/cmd/util" | ||
corev1 "k8s.io/api/core/v1" | ||
apiresource "k8s.io/apimachinery/pkg/api/resource" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
kubevirtv1 "kubevirt.io/api/core/v1" | ||
"kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1" | ||
capikubevirt "sigs.k8s.io/cluster-api-provider-kubevirt/api/v1alpha1" | ||
) | ||
|
||
func ExampleKubeVirtTemplate(o *ExampleKubevirtOptions) *hyperv1.KubevirtNodePoolPlatform { | ||
runAlways := kubevirtv1.RunStrategyAlways | ||
guestQuantity := apiresource.MustParse(o.Memory) | ||
exampleTemplate := &hyperv1.KubevirtNodePoolPlatform{ | ||
NodeTemplate: &capikubevirt.VirtualMachineTemplateSpec{ | ||
Spec: kubevirtv1.VirtualMachineSpec{ | ||
RunStrategy: &runAlways, | ||
Template: &kubevirtv1.VirtualMachineInstanceTemplateSpec{ | ||
Spec: kubevirtv1.VirtualMachineInstanceSpec{ | ||
Domain: kubevirtv1.DomainSpec{ | ||
CPU: &kubevirtv1.CPU{Cores: o.Cores}, | ||
Memory: &kubevirtv1.Memory{Guest: &guestQuantity}, | ||
Devices: kubevirtv1.Devices{ | ||
Interfaces: []kubevirtv1.Interface{ | ||
{ | ||
Name: "default", | ||
InterfaceBindingMethod: kubevirtv1.InterfaceBindingMethod{ | ||
Bridge: &kubevirtv1.InterfaceBridge{}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
Networks: []kubevirtv1.Network{ | ||
{ | ||
Name: "default", | ||
NetworkSource: kubevirtv1.NetworkSource{ | ||
Pod: &kubevirtv1.PodNetwork{}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
exampleTemplate.NodeTemplate.Spec.Template.Spec.Domain.Devices.Disks = []kubevirtv1.Disk{ | ||
{ | ||
Name: util.RHCOSMagicVolumeName, | ||
DiskDevice: kubevirtv1.DiskDevice{ | ||
Disk: &kubevirtv1.DiskTarget{ | ||
Bus: "virtio", | ||
}, | ||
}, | ||
}, | ||
} | ||
if o.Image != "" { | ||
exampleTemplate.NodeTemplate.Spec.Template.Spec.Volumes = []kubevirtv1.Volume{ | ||
{ | ||
Name: util.RHCOSMagicVolumeName, | ||
VolumeSource: kubevirtv1.VolumeSource{ | ||
ContainerDisk: &kubevirtv1.ContainerDiskSource{ | ||
Image: o.Image, | ||
}, | ||
}, | ||
}, | ||
} | ||
} else { | ||
dataVolume := defaultDataVolume() | ||
setDataVolumeDefaults(&dataVolume, o) | ||
exampleTemplate.NodeTemplate.Spec.DataVolumeTemplates = []kubevirtv1.DataVolumeTemplateSpec{dataVolume} | ||
exampleTemplate.NodeTemplate.Spec.Template.Spec.Volumes = []kubevirtv1.Volume{ | ||
{ | ||
Name: util.RHCOSMagicVolumeName, | ||
VolumeSource: kubevirtv1.VolumeSource{ | ||
DataVolume: &kubevirtv1.DataVolumeSource{ | ||
Name: util.RHCOSMagicVolumeName, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
return exampleTemplate | ||
} | ||
|
||
func defaultDataVolume() kubevirtv1.DataVolumeTemplateSpec { | ||
return kubevirtv1.DataVolumeTemplateSpec{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: util.RHCOSMagicVolumeName, | ||
}, | ||
Spec: v1beta1.DataVolumeSpec{ | ||
Source: &v1beta1.DataVolumeSource{ | ||
HTTP: &v1beta1.DataVolumeSourceHTTP{URL: util.RHCOSOpenStackURLParam}, | ||
}, | ||
}, | ||
} | ||
} | ||
func setDataVolumeDefaults(spec *kubevirtv1.DataVolumeTemplateSpec, o *ExampleKubevirtOptions) { | ||
if spec.Spec.Storage == nil { | ||
spec.Spec.Storage = &v1beta1.StorageSpec{ | ||
Resources: corev1.ResourceRequirements{ | ||
Requests: map[corev1.ResourceName]apiresource.Quantity{ | ||
corev1.ResourceStorage: util.KubeVirtVolumeDefaultSize, | ||
}, | ||
}, | ||
StorageClassName: &o.RootVolumeStorageClass, | ||
} | ||
} | ||
if o.RootVolumeSize != 0 { | ||
size := apiresource.MustParse(fmt.Sprintf("%vGi", o.RootVolumeSize)) | ||
spec.Spec.Storage.Resources = corev1.ResourceRequirements{ | ||
Requests: map[corev1.ResourceName]apiresource.Quantity{ | ||
corev1.ResourceStorage: size, | ||
}, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package util | ||
|
||
import "k8s.io/apimachinery/pkg/api/resource" | ||
|
||
const ( | ||
RHCOSOpenStackChecksumParameter string = "{rhcos:openstack:checksum}" | ||
RHCOSMagicVolumeName string = "rhcos" | ||
RHCOSOpenStackURLParam string = "{rhcos:openstack:url}" | ||
) | ||
|
||
var KubeVirtVolumeDefaultSize = resource.MustParse("16Gi") |
Oops, something went wrong.