Skip to content

Commit 842be9a

Browse files
authored
Refactor: Encapsulate net opts loading in internalLabels
Signed-off-by: Pedro Aibar <[email protected]>
1 parent f917e5c commit 842be9a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

pkg/cmd/container/create.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,7 @@ func Create(ctx context.Context, client *containerd.Client, args []string, netMa
248248
envs = append(envs, "HOSTNAME="+netLabelOpts.Hostname)
249249
opts = append(opts, oci.WithEnv(envs))
250250

251-
// TODO(aznashwan): more formal way to load net opts into internalLabels:
252-
internalLabels.hostname = netLabelOpts.Hostname
253-
internalLabels.ports = netLabelOpts.PortMappings
254-
internalLabels.ipAddress = netLabelOpts.IPAddress
255-
internalLabels.ip6Address = netLabelOpts.IP6Address
256-
internalLabels.networks = netLabelOpts.NetworkSlice
257-
internalLabels.macAddress = netLabelOpts.MACAddress
251+
internalLabels.LoadNetOpts(netLabelOpts)
258252

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

729+
// LoadNetOpts loads network options into InternalLabels.
730+
func (il *internalLabels) LoadNetOpts(opts types.NetworkOptions) {
731+
il.hostname = opts.Hostname
732+
il.ports = opts.PortMappings
733+
il.ipAddress = opts.IPAddress
734+
il.ip6Address = opts.IP6Address
735+
il.networks = opts.NetworkSlice
736+
il.macAddress = opts.MACAddress
737+
}
738+
735739
func dockercompatMounts(mountPoints []*mountutil.Processed) []dockercompat.MountPoint {
736740
result := make([]dockercompat.MountPoint, len(mountPoints))
737741
for i := range mountPoints {

0 commit comments

Comments
 (0)