MCPcopy Create free account
hub / github.com/containerd/nerdctl / ReconfigNetContainer

Function ReconfigNetContainer

pkg/containerutil/config.go:38–79  ·  view source on GitHub ↗

ReconfigNetContainer reconfigures the container's network namespace path.

(ctx context.Context, c containerd.Container, client *containerd.Client, lab map[string]string)

Source from the content-addressed store, hash-verified

36
37// ReconfigNetContainer reconfigures the container's network namespace path.
38func ReconfigNetContainer(ctx context.Context, c containerd.Container, client *containerd.Client, lab map[string]string) error {
39 networksJSON, ok := lab[labels.Networks]
40 if !ok {
41 return nil
42 }
43 var networks []string
44 if err := json.Unmarshal([]byte(networksJSON), &networks); err != nil {
45 return err
46 }
47 netType, err := nettype.Detect(networks)
48 if err != nil {
49 return err
50 }
51 if netType == nettype.Container {
52 network := strings.Split(networks[0], ":")
53 if len(network) != 2 {
54 return fmt.Errorf("invalid network: %s, should be \"container:<id|name>\"", networks[0])
55 }
56 targetCon, err := client.LoadContainer(ctx, network[1])
57 if err != nil {
58 return err
59 }
60 netNSPath, err := ContainerNetNSPath(ctx, targetCon)
61 if err != nil {
62 return err
63 }
64 spec, err := c.Spec(ctx)
65 if err != nil {
66 return err
67 }
68 err = c.Update(ctx, containerd.UpdateContainerOpts(
69 containerd.WithSpec(spec, oci.WithLinuxNamespace(
70 specs.LinuxNamespace{
71 Type: specs.NetworkNamespace,
72 Path: netNSPath,
73 }))))
74 if err != nil {
75 return err
76 }
77 }
78 return nil
79}
80
81// ReconfigPIDContainer reconfigures the container's spec options for sharing PID namespace.
82func ReconfigPIDContainer(ctx context.Context, c containerd.Container, client *containerd.Client, lab map[string]string) error {

Callers 1

StartFunction · 0.85

Calls 4

DetectFunction · 0.92
ContainerNetNSPathFunction · 0.85
UnmarshalMethod · 0.80
UpdateMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…