Skip to content

feat: Support Kraftfile v0.7 templates and OCI runtime refs#2771

Closed
ijaidev wants to merge 2 commits intounikraft:stagingfrom
ijaidev:schema-0.7-support
Closed

feat: Support Kraftfile v0.7 templates and OCI runtime refs#2771
ijaidev wants to merge 2 commits intounikraft:stagingfrom
ijaidev:schema-0.7-support

Conversation

@ijaidev
Copy link
Copy Markdown
Contributor

@ijaidev ijaidev commented Apr 3, 2026

PR Title

feat: add Kraftfile v0.7 project loading, template resolution, and OCI runtime ref support

Description of changes

This PR adds end-to-end support for Kraftfile v0.7 projects across project loading, template resolution, runtime lookup, and packaging/build flows.

The first part of the change teaches project initialization to dispatch by Kraftfile spec version and introduces a dedicated v0.7 loader built on unikraft.com/x/kraftfile. The new loader maps v0.7 documents into the existing application model, records the loader/spec version on the project, supports parsing unikraft/runtime/library/target/rootfs/rom/volume fields, preserves project naming semantics from the source document, normalizes target artifact names, and keeps v0.7 projects read-only by rejecting legacy mutation paths such as Save, AddLibrary, and RemoveLibrary.

The second part resolves v0.7 templates before project construction so template defaults are merged first and project values still take precedence. It also preserves full OCI runtime references instead of incorrectly splitting registry-based refs into name/tag pairs, adds helper query/reference methods to runtime resolution, and updates build/run/pkg flows to use those helpers consistently when searching for runtime packages.

Root filesystem and ROM handling are updated to carry filesystem metadata from the v0.7 schema through initrd and OCI packaging paths. ROM inputs now travel as structured filesystem descriptors instead of bare strings, allowing format-aware packaging while still reusing the existing initrd build pipeline. The build, run, pkg, compose, and deploy commands also switch their rootfs-type handling to the v0.7 filesystem enum and reuse the project output directory so artifacts land in the configured build location.

The change is covered with focused tests for spec sniffing, loader dispatch, project naming/outdir behavior, component parsing, runtime reference preservation, rootfs format handling, volume mapping, and runtime OCI parsing.

Validation

  • unit tests passed
  • make fmt passed

Note

  • PR is still not mergeable. It is for approval purposes

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds end-to-end Kraftfile v0.7 support by dispatching project loading based on spec version, resolving templates prior to project construction, preserving full OCI runtime references, and carrying v0.7 filesystem metadata (rootfs/ROM) through build/package flows.

Changes:

  • Add spec sniffing + loader dispatch and implement a dedicated v0.7 project loader (incl. template pre-merge).
  • Preserve full OCI runtime references via new runtime query/reference helpers and update runtime lookups accordingly.
  • Plumb v0.7 filesystem descriptors/types through targets, initrd, packaging, and CLI flows (rootfs type + ROM descriptors).

Reviewed changes

Copilot reviewed 31 out of 32 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
unikraft/type.go Adds shared project-name normalization helper.
unikraft/target/target.go Normalizes target artifact names; switches ROMs to FS descriptors.
unikraft/runtime/transform.go Updates schema transform to preserve full OCI refs.
unikraft/runtime/runtime.go Adds runtime query/reference helpers + improved name/version splitting.
unikraft/runtime/runtime_test.go Adds tests for runtime ref parsing and schema transform.
unikraft/app/volume/transform.go Adds support for volumes.mode.
unikraft/app/template_resolver.go Introduces v0.7 template resolution & merge before project construction.
unikraft/app/project.go Refactors legacy loader path and records loader/spec metadata.
unikraft/app/project_v07.go Implements v0.7 loader mapping Kraftfile fields into the app model.
unikraft/app/project_v07_test.go Adds tests for spec dispatch, naming, outdir, runtime refs, volumes, etc.
unikraft/app/project_loader.go Adds spec sniffing + dispatch entrypoint for project creation.
unikraft/app/normalize.go Reuses shared name normalization helper.
unikraft/app/loader.go Updates legacy application parsing to new fs type / ROM descriptor types.
unikraft/app/loader_kind.go Introduces loader kind constants and mutation-not-supported error.
unikraft/app/application.go Records loader/spec version, blocks mutation for non-legacy, updates ROM/fsType types.
unikraft/app/application_options.go Adds options to record loader/spec; switches ROM/fsType option types.
packmanager/pack_options.go Switches ROMs to FS descriptors in pack options.
oci/pack.go Switches ROM handling to FS descriptors for OCI packaging.
internal/cli/kraft/run/runner_kraftfile_runtime.go Uses runtime query/reference helpers when resolving runtimes.
internal/cli/kraft/run/run.go Switches rootfs-type flag plumbing to v0.7 fs type enum.
internal/cli/kraft/pkg/pkg.go Switches pkg rootfs/ROM options to v0.7 fs/FS types.
internal/cli/kraft/pkg/packager_kraftfile_runtime.go Updates packaging flow to pass FS ROM descriptors into initrd ROM builder.
internal/cli/kraft/cloud/deploy/deploy.go Switches rootfs-type handling to v0.7 fs type enum.
internal/cli/kraft/cloud/compose/up/up.go Switches rootfs-type handling to v0.7 fs type enum.
internal/cli/kraft/cloud/compose/build/build.go Switches rootfs-type handling to v0.7 fs type enum.
internal/cli/kraft/build/builder_kraftfile_runtime.go Uses runtime query/reference helpers and improves runtime search messaging.
internal/cli/kraft/build/build.go Writes initrd artifacts to project outdir and switches rootfs-type enum type.
initrd/rootfs.go Changes ROM builder to accept FS descriptors and build format-aware ROM images.
initrd/options.go Switches initrd fs type to use kraftfile v0.7 enum and updates helpers/constants.
initrd/file.go Updates fs type detection to return v0.7 fs type enum.
go.mod Adds new dependencies for kraftfile v0.7 support + yaml.
go.sum Updates checksums for new/updated dependencies.
Comments suppressed due to low confidence (1)

initrd/rootfs.go:134

  • ROM output paths are hard-coded to filepath.Join(workdir, unikraft.BuildDir, ...). For projects that set a custom output directory (especially v0.7 where artifacts are expected to land in the configured BUILD_DIR), this will write ROM artifacts to a different location. Consider deriving the output base from unikraft.FromContext(ctx).BUILD_DIR (when set) or adding an explicit output-dir parameter.
			WithOutput(filepath.Join(
				workdir,
				unikraft.BuildDir,
				fmt.Sprintf("rom%d-%s.%s", i+1, arch, fsType),
			)),

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread unikraft/app/loader.go Outdated
value["destination"] = doc.Destination
}
if doc.Mode != nil {
value["mode"] = doc.Mode
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc.Mode is passed through as-is, but volume.TransformFromSchema expects the mode property to be a string. If doc.Mode is an optional/pointer type (as implied by the nil-check), this will fail at runtime. Pass the dereferenced string value instead (and keep omitting the key when unset).

Suggested change
value["mode"] = doc.Mode
value["mode"] = *doc.Mode

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc.Mode is not a pointer, so it can't be dereferenced. volume.TransformFromSchema will throw an error if it can't be converted into a string.

Comment thread internal/cli/kraft/pkg/pkg.go Outdated
Comment thread internal/cli/kraft/pkg/pkg.go Outdated
@ijaidev ijaidev force-pushed the schema-0.7-support branch from 6f829a3 to f0f8cc1 Compare April 4, 2026 07:11
@ijaidev
Copy link
Copy Markdown
Contributor Author

ijaidev commented Apr 4, 2026

@craciunoiuc I made some changes as asked by Copilot

Somehow, CI tests are not triggered

@ijaidev ijaidev force-pushed the schema-0.7-support branch from f0f8cc1 to 632034a Compare April 5, 2026 17:03
@craciunoiuc
Copy link
Copy Markdown
Member

They're not triggered because there is a conflict in gomod
image

@craciunoiuc
Copy link
Copy Markdown
Member

Also the PR is quite lengthy, can you split it into more commits so it's easier to go through?

Dispatch project loading by Kraftfile spec version and map
v0.7 documents into the existing application model.

Keep v0.7 projects read-only for now and cover loader
selection, component parsing, runtime/template/rootfs
mapping, volume mode handling, and mutation rejection.

Signed-off-by: Jaidev <himjaidev@gmail.com>
@ijaidev ijaidev force-pushed the schema-0.7-support branch from 632034a to cfc1f63 Compare April 6, 2026 10:01
@ijaidev
Copy link
Copy Markdown
Contributor Author

ijaidev commented Apr 6, 2026

Also the PR is quite lengthy, can you split it into more commits so it's easier to go through?

some files are dependent on each other and require changes simultaneously. But I'm trying to figure out how I can organise this in small commits

@ijaidev
Copy link
Copy Markdown
Contributor Author

ijaidev commented Apr 6, 2026

image

Unrelated to this, but make fmt is broken (on my machine at least)
new command is go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.11.4 fmt

Should I update the Makefile?

@ijaidev ijaidev force-pushed the schema-0.7-support branch from cfc1f63 to e54bccc Compare April 6, 2026 10:33
Resolve v0.7 templates before loading projects so template\ndefaults merge correctly and project fields still take precedence.\n\nPreserve full OCI runtime references, carry FS metadata for\nrootfs and ROMs, and reuse the project output directory across\nbuild, pkg, and deploy flows.

Signed-off-by: Jaidev <himjaidev@gmail.com>
@ijaidev ijaidev force-pushed the schema-0.7-support branch from e54bccc to 763c961 Compare April 6, 2026 10:50
@craciunoiuc
Copy link
Copy Markdown
Member

Yup, go ahead, create a separate commit for it though

@craciunoiuc craciunoiuc changed the title Schema 0.7 support feat: Support Kraftfile v0.7 templates and OCI runtime refs Apr 6, 2026
@ijaidev
Copy link
Copy Markdown
Contributor Author

ijaidev commented Apr 8, 2026

#2776

@craciunoiuc

Created another PR with smaller commits

@ijaidev ijaidev closed this Apr 8, 2026
@github-project-automation github-project-automation Bot moved this from 🧊 Icebox to 🚀 Done in KraftKit Roadmap Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🚀 Done

Development

Successfully merging this pull request may close these issues.

3 participants