Skip to content

Commit

Permalink
Merge pull request #3793 from motinsa/main
Browse files Browse the repository at this point in the history
Refactor: Encapsulate net opts loading in internalLabels
  • Loading branch information
fahedouch authored Jan 10, 2025
2 parents f5e58de + d6248ac commit 751b33b
Showing 1 changed file with 11 additions and 7 deletions.
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

0 comments on commit 751b33b

Please sign in to comment.