Skip to content

Commit

Permalink
CNV-53430: make examples compatible with s390x arch
Browse files Browse the repository at this point in the history
  • Loading branch information
upalatucci committed Dec 18, 2024
1 parent 6b5bc33 commit 1f9e306
Show file tree
Hide file tree
Showing 4 changed files with 275 additions and 163 deletions.
240 changes: 146 additions & 94 deletions src/templates/vm-template-yaml.ts
Original file line number Diff line number Diff line change
@@ -1,95 +1,147 @@
import { TemplateModel } from '@kubevirt-ui/kubevirt-api/console';
import { TemplateModel, V1Template } from '@kubevirt-ui/kubevirt-api/console';
import { isClusterOnS390X, safeDump } from '@kubevirt-utils/utils/utils';

export const defaultVMTemplateYamlTemplate = `
apiVersion: ${TemplateModel.apiGroup}/${TemplateModel.apiVersion}
kind: ${TemplateModel.kind}
metadata:
name: example
labels:
template.kubevirt.io/type: vm
os.template.kubevirt.io/fedora: 'true'
workload.template.kubevirt.io/server: 'true'
annotations:
name.os.template.kubevirt.io/fedora: Fedora
description: VM template example
openshift.io/display-name: "Fedora VM"
iconClass: icon-fedora
objects:
- apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
name: '\${NAME}'
annotations:
description: VM example
labels:
app: '\${NAME}'
vm.kubevirt.io/template: example
os.template.kubevirt.io/fedora: 'true'
spec:
runStrategy: Halted
template:
metadata:
annotations:
vm.kubevirt.io/flavor: small
vm.kubevirt.io/os: fedora
vm.kubevirt.io/workload: server
labels:
kubevirt.io/domain: '\${NAME}'
kubevirt.io/size: small
spec:
domain:
cpu:
cores: 1
sockets: 1
threads: 1
devices:
disks:
- disk:
bus: virtio
name: rootdisk
- disk:
bus: virtio
name: cloudinitdisk
interfaces:
- masquerade: {}
model: virtio
name: default
networkInterfaceMultiqueue: true
rng: {}
features:
acpi: {}
smm:
enabled: true
firmware:
bootloader:
efi: {}
machine:
type: q35
memory:
guest: 2Gi
hostname: '\${NAME}'
networks:
- name: default
pod: {}
terminationGracePeriodSeconds: 180
volumes:
- name: rootdisk
containerDisk:
image: 'quay.io/containerdisks/fedora'
- cloudInitNoCloud:
userData: |-
#cloud-config
user: fedora
password: '\${CLOUD_USER_PASSWORD}'
chpasswd: { expire: False }
name: cloudinitdisk
parameters:
- name: NAME
description: Name for the new VM
generate: expression
from: 'example-[a-z0-9]{16}'
- name: CLOUD_USER_PASSWORD
description: Randomized password for the cloud-init user
generate: expression
from: '[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}'
`;
const defaultTemplate: V1Template = {
apiVersion: `${TemplateModel.apiGroup}/${TemplateModel.apiVersion}`,
kind: `${TemplateModel.kind}`,
metadata: {
annotations: {
description: 'VM template example',
iconClass: 'icon-fedora',
'name.os.template.kubevirt.io/fedora': 'Fedora',
'openshift.io/display-name': 'Fedora VM',
},
labels: {
'os.template.kubevirt.io/fedora': 'true',
'template.kubevirt.io/type': 'vm',
'workload.template.kubevirt.io/server': 'true',
},
name: 'example',
},
objects: [
{
apiVersion: 'kubevirt.io/v1',
kind: 'VirtualMachine',
metadata: {
annotations: {
description: 'VM example',
},
labels: {
app: '\\${NAME}',
'os.template.kubevirt.io/fedora': 'true',
'vm.kubevirt.io/template': 'example',
},
name: '\\${NAME}',
},
spec: {
runStrategy: 'Halted',
template: {
metadata: {
annotations: {
'vm.kubevirt.io/flavor': 'small',
'vm.kubevirt.io/os': 'fedora',
'vm.kubevirt.io/workload': 'server',
},
labels: {
'kubevirt.io/domain': '\\${NAME}',
'kubevirt.io/size': 'small',
},
},
spec: {
domain: {
cpu: {
cores: 1,
sockets: 1,
threads: 1,
},
devices: {
disks: [
{
disk: {
bus: 'virtio',
},
name: 'rootdisk',
},
{
disk: {
bus: 'virtio',
},
name: 'cloudinitdisk',
},
],
interfaces: [
{
masquerade: {},
model: 'virtio',
name: 'default',
},
],
networkInterfaceMultiqueue: true,
rng: {},
},

...(!isClusterOnS390X && {
features: {
acpi: {},
smm: {
enabled: true,
},
},
firmware: {
bootloader: {
efi: {},
},
},
machine: {
type: 'q35',
},
}),
memory: {
guest: '2Gi',
},
},
hostname: '\\${NAME}',
networks: [
{
name: 'default',
pod: {},
},
],
terminationGracePeriodSeconds: 180,
volumes: [
{
containerDisk: {
image: 'quay.io/containerdisks/fedora',
},
name: 'rootdisk',
},
{
cloudInitNoCloud: {
userData:
"#cloud-config\nuser: fedora\npassword: '\\${CLOUD_USER_PASSWORD}'\nchpasswd: { expire: False }",
},
name: 'cloudinitdisk',
},
],
},
},
},
},
],
parameters: [
{
description: 'Name for the new VM',
from: 'example-[a-z0-9]{16}',
generate: 'expression',
name: 'NAME',
},
{
description: 'Randomized password for the cloud-init user',
from: '[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}',
generate: 'expression',
name: 'CLOUD_USER_PASSWORD',
},
],
};

export const defaultVMTemplateYamlTemplate = safeDump(defaultTemplate);
Loading

0 comments on commit 1f9e306

Please sign in to comment.