Skip to content

refactor(api/machine): Introduce ParseNetwork for network string parsing#2724

Open
MahnoKropotkinvich wants to merge 1 commit intounikraft:stagingfrom
MahnoKropotkinvich:parse-network
Open

refactor(api/machine): Introduce ParseNetwork for network string parsing#2724
MahnoKropotkinvich wants to merge 1 commit intounikraft:stagingfrom
MahnoKropotkinvich:parse-network

Conversation

@MahnoKropotkinvich
Copy link
Copy Markdown

Prerequisite checklist

Description of changes

Resolves #1648

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

Introduces a machine API–level ParseNetwork utility for parsing CLI network strings, reducing leakage of Unikraft-specific network parsing types into CLI code (per issue #1648).

Changes:

  • Added MachineNetwork + ParseNetwork/String() to standardize network string parsing/formatting in the machine API.
  • Refactored kraft run network parsing to use machineapi.ParseNetwork instead of ad-hoc parsing.
  • Updated kraft compose create to emit network strings via machineapi.MachineNetwork rather than uknetdev.NetdevIp.

Reviewed changes

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

File Description
internal/cli/kraft/run/utils.go Switches network arg parsing to machineapi.ParseNetwork and maps parsed fields into the network interface spec.
internal/cli/kraft/compose/create/create.go Removes uknetdev dependency; builds network strings using machineapi.MachineNetwork.String().
api/machine/v1alpha1/network.go Adds ParseNetwork and MachineNetwork.String() for colon-separated network string handling.
api/machine/v1alpha1/machine.zip.go Introduces the MachineNetwork struct type in the machine API package.

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

Comment on lines +91 to 99
// Handle CIDR default netmask if not provided.
if interfaceSpec.CIDR != "" {
ipMaskSplit := strings.SplitN(interfaceSpec.CIDR, "/", 2)
if len(ipMaskSplit) != 2 {
sz, _ := net.IPMask(net.ParseIP(found.Spec.Netmask).To4()).Size()
interfaceSpec.CIDR = fmt.Sprintf("%s/%d", interfaceSpec.CIDR, sz)
}
opts.IP = ipMaskSplit[0]
}
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

The --ip flag is currently ineffective: the value is never applied to interfaceSpec.CIDR when the network arg omits an IP, and opts.IP is overwritten from the parsed CIDR unconditionally. This makes --ip confusing and prevents it from doing what the flag description suggests. Consider using opts.IP to populate the interface CIDR when parsed.CIDR is empty, and avoid overwriting opts.IP when it was explicitly provided by the user.

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

@MahnoKropotkinvich MahnoKropotkinvich Apr 3, 2026

Choose a reason for hiding this comment

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

@craciunoiuc The --ip flag is never used either in both upstream branch or my PR. In this PR, I just introduced a new struct with its serialization function to replace the original uknetdev.NetdevIp. I kept almost the same population logic as the original code.

Since this PR is mainly focused on introducing a new struct for network string parsing, should I also include a bug fix for the --ip flag here, or keep it separate?

Comment thread api/machine/v1alpha1/network.go Outdated
Signed-off-by: Mahno Kropotkinvich <mahno@libertarian.dev>
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.

Implement machine ParseNetwork string

2 participants