Skip to content

Commit

Permalink
Build KubeVirt artifact
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Mohr <[email protected]>
  • Loading branch information
rmohr committed Mar 10, 2022
1 parent bcce9a9 commit 59086f0
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ maipo/
*.shellchecked
.coverage
tools/bin
.idea
1 change: 1 addition & 0 deletions schema/cosa/cosa_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type BuildArtifacts struct {
Initramfs *Artifact `json:"initramfs,omitempty"`
Iso *Artifact `json:"iso,omitempty"`
Kernel *Artifact `json:"kernel,omitempty"`
KubeVirt *Artifact `json:"kubevirt,omitempty"`
LiveInitramfs *Artifact `json:"live-initramfs,omitempty"`
LiveIso *Artifact `json:"live-iso,omitempty"`
LiveKernel *Artifact `json:"live-kernel,omitempty"`
Expand Down
9 changes: 8 additions & 1 deletion schema/cosa/schema_doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated by ./generate-schema.sh
// Generated by /home/rmohr/coreos-assembler/schema/generate-schema.sh
// DO NOT EDIT

package cosa
Expand Down Expand Up @@ -421,6 +421,7 @@ var generatedSchemaJSON = `{
"metal4k",
"nutanix",
"openstack",
"kubevirt",
"qemu",
"vmware",
"vultr"
Expand Down Expand Up @@ -516,6 +517,12 @@ var generatedSchemaJSON = `{
"title":"OpenStack",
"$ref": "#/definitions/artifact"
},
"kubevirt": {
"$id":"#/properties/images/properties/kubevirt",
"type":"object",
"title":"KubeVirt",
"$ref": "#/definitions/artifact"
},
"vmware": {
"$id":"#/properties/images/properties/vmware",
"type":"object",
Expand Down
7 changes: 7 additions & 0 deletions schema/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@
"metal4k",
"nutanix",
"openstack",
"kubevirt",
"qemu",
"vmware",
"vultr"
Expand Down Expand Up @@ -511,6 +512,12 @@
"title":"OpenStack",
"$ref": "#/definitions/artifact"
},
"kubevirt": {
"$id":"#/properties/images/properties/kubevirt",
"type":"object",
"title":"KubeVirt",
"$ref": "#/definitions/artifact"
},
"vmware": {
"$id":"#/properties/images/properties/vmware",
"type":"object",
Expand Down
122 changes: 122 additions & 0 deletions src/cmd-buildextend-kubevirt
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/usr/bin/python3 -u
import logging as log
import os.path
import sys

cosa_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, f"{cosa_dir}/cosalib")
sys.path.insert(0, cosa_dir)

from cosalib.build import BuildExistsError
from cosalib.cli import BuildCli
import cosalib.qemuvariants as QVariants
import cosalib.ova as OVA


def get_builder(imgtype, build_root, build="latest", force=False, compress=False, schema=None):
kargs = {
"build": build,
"buildroot": build_root,
"force": force,
"compress": compress,
"schema": schema,
"variant": imgtype
}

if imgtype in QVariants.VARIANTS:
log.info(f"Target '{imgtype.upper()}' is a Qemu Variant image")
return QVariants.QemuVariantImage(**kargs)

if imgtype in OVA.VARIANTS:
return OVA.OVA(**kargs)

raise Exception(f"{imgtype} is not supported by this command")


def artifact_cli():
""" cli implements command-line innovation """
log.basicConfig(
format='[%(levelname)s]: %(message)s',
level=log.INFO)

targets = list(QVariants.VARIANTS.keys())
targets.extend(OVA.VARIANTS.keys())
targets.append("manual")

parser = BuildCli()
subparsers = parser.add_subparsers(dest="command")

# Options for finding the build.
parser.add_argument("--force", action='store_true',
help="Force rebuild of existing disk")
parser.add_argument("--compress", action='store_true',
help="Compress generated image")

# Support for legacy cmd-buildextend-* targets
symlink = None
for k in targets:
if sys.argv[0].endswith(f"cmd-buildextend-{k}"):
symlink = k
log.info(f"CLI is a symlink for cmd-buildextend-{k}")
break

# Predefined mode
target = subparsers.add_parser(name="target",
description="manually define build")
target.add_argument("target", default=None,
help="name of predefined target",
choices=targets)

# Manual mode for developers
manual = subparsers.add_parser(name="manual",
description="build new disk from cli args")
manual.add_argument("--image_format", required=True,
help="qemu-img supported image format, i.e vpc")
manual.add_argument("--image_suffix", required=True,
help="file name suffix")
manual.add_argument("--platform", required=True,
help="Ignition platform to set image to")
manual.add_argument("--convert_options",
help="qemu-img options")
manual.add_argument("--virtual-size", help="Virtual Size to use")

args = parser.parse_args()

builder = None

# Figure out if the build target has been set
build_target = None
if "target" in args:
build_target = args.target
elif symlink:
build_target = symlink

if build_target:
builder = get_builder(build_target, args.buildroot, args.build,
force=args.force, compress=args.compress, schema=args.schema)
elif args.command == "manual":
kwargs = {
'force': args.force,
'image_format': args.image_format,
'image_suffix': args.image_suffix,
'platform': args.platform,
'schema': args.schema,
'virtual_size': args.virtual_size,
}
if args.convert_options:
kwargs["convert_options"] = {'-o': f'{args.convert_options}'}

builder = QVariants.QemuVariantImage(buildroot=args.buildroot,
build=args.build,
**kwargs)
else:
raise Exception("please see --help for correct invocation")

return builder


if __name__ == '__main__':
try:
artifact_cli().build_artifacts()
except BuildExistsError as e:
log.warning(e)
2 changes: 1 addition & 1 deletion src/coreos-assembler
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ cmd=${1:-}
build_commands="init fetch build run prune clean list"
# commands more likely to be used in a prod pipeline only
advanced_build_commands="buildfetch buildupload oc-adm-release push-container upload-oscontainer"
buildextend_commands="aliyun aws azure digitalocean exoscale gcp ibmcloud live metal metal4k nutanix openstack qemu vmware vultr"
buildextend_commands="aliyun aws azure digitalocean exoscale gcp ibmcloud kubevirt live metal metal4k nutanix openstack qemu vmware vultr"
utility_commands="aws-replicate compress generate-hashlist koji-upload kola remote-prune sign tag"
other_commands="shell meta"
if [ -z "${cmd}" ]; then
Expand Down
6 changes: 5 additions & 1 deletion src/cosalib/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
gcp,
vultr,
exoscale,
ibmcloud
ibmcloud,
kubevirt
)

CLOUD_CLI_TARGET = {
Expand Down Expand Up @@ -44,6 +45,9 @@
"powervs": (ibmcloud.ibmcloud_cli,
ibmcloud.ibmcloud_run_ore,
ibmcloud.ibmcloud_run_ore_replicate),
"kubevirt": (kubevirt.kubevirt_cli,
kubevirt.kubevirt_run_ore,
kubevirt.kubevirt_run_ore_replicate),
}


Expand Down
18 changes: 18 additions & 0 deletions src/cosalib/kubevirt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def kubevirt_run_ore(build, args):
print("""
Images are not published to KubeVirt. This command is a placeholder.
""")


def kubevirt_run_ore_replicate(*args, **kwargs):
print("""
KubeVirt does not require regional replication. This command is a
placeholder.
""")


def kubevirt_cli(parser):
"""
Extend a parser with the KubeVirt options
"""
return parser
4 changes: 4 additions & 0 deletions src/cosalib/qemuvariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
"--format=oldgnu"
]
},
"kubevirt": {
"image_format": "qcow2",
"platform": "kubevirt",
},
"openstack": {
"image_format": "qcow2",
"platform": "openstack",
Expand Down
9 changes: 8 additions & 1 deletion src/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,8 @@
"openstack",
"qemu",
"vmware",
"vultr"
"vultr",
"kubevirt"
],
"properties": {
"ostree": {
Expand Down Expand Up @@ -511,6 +512,12 @@
"title":"OpenStack",
"$ref": "#/definitions/artifact"
},
"kubevirt": {
"$id":"#/properties/images/properties/kubevirt",
"type":"object",
"title":"KubeVirt",
"$ref": "#/definitions/artifact"
},
"vmware": {
"$id":"#/properties/images/properties/vmware",
"type":"object",
Expand Down

0 comments on commit 59086f0

Please sign in to comment.