Skip to content

Refactor: Encapsulate net opts loading in internalLabels #3793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions pkg/cmd/container/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,7 @@ func Create(ctx context.Context, client *containerd.Client, args []string, netMa
envs = append(envs, "HOSTNAME="+netLabelOpts.Hostname)
opts = append(opts, oci.WithEnv(envs))

// TODO(aznashwan): more formal way to load net opts into internalLabels:
internalLabels.hostname = netLabelOpts.Hostname
internalLabels.ports = netLabelOpts.PortMappings
internalLabels.ipAddress = netLabelOpts.IPAddress
internalLabels.ip6Address = netLabelOpts.IP6Address
internalLabels.networks = netLabelOpts.NetworkSlice
internalLabels.macAddress = netLabelOpts.MACAddress
internalLabels.loadNetOpts(netLabelOpts)

// NOTE: OCI hooks are currently not supported on Windows so we skip setting them altogether.
// The OCI hooks we define (whose logic can be found in pkg/ocihook) primarily
Expand Down Expand Up @@ -732,6 +726,16 @@ func withInternalLabels(internalLabels internalLabels) (containerd.NewContainerO
return containerd.WithAdditionalContainerLabels(m), nil
}

// loadNetOpts loads network options into InternalLabels.
func (il *internalLabels) loadNetOpts(opts types.NetworkOptions) {
il.hostname = opts.Hostname
il.ports = opts.PortMappings
il.ipAddress = opts.IPAddress
il.ip6Address = opts.IP6Address
il.networks = opts.NetworkSlice
il.macAddress = opts.MACAddress
}

func dockercompatMounts(mountPoints []*mountutil.Processed) []dockercompat.MountPoint {
result := make([]dockercompat.MountPoint, len(mountPoints))
for i := range mountPoints {
Expand Down