Table of Contents

Class ContainerdNetworkManager

Namespace
Bielu.Microservices.Orchestrator.Containerd
Assembly
Bielu.Microservices.Orchestrator.Containerd.dll

containerd implementation of the network manager backed by CNI configuration files and CNI plugin binary invocations.

public class ContainerdNetworkManager : INetworkManager
Inheritance
ContainerdNetworkManager
Implements
Inherited Members

Remarks

CNI is required. containerd delegates all networking to the Container Network Interface (CNI) plugin framework. This implementation reads and writes CNI configuration files stored in CniConfigPath (default /etc/cni/net.d).

Before using any network operations you must install CNI plugins on the host, e.g.:

apt install containernetworking-plugins   # Debian / Ubuntu
dnf install containernetworking-plugins   # RHEL / Fedora

or download binaries from https://github.com/containernetworking/plugins/releases.

Connect / Disconnect invoke CNI plugin binaries using the CNI wire protocol (the same mechanism used by go-cni). The container's network namespace is resolved from its running task PID via /proc/{pid}/ns/net, so the container must have a running task before calling these methods.

Constructors

ContainerdNetworkManager(TasksClient, ContainerdOptions, ILogger<ContainerdNetworkManager>)

containerd implementation of the network manager backed by CNI configuration files and CNI plugin binary invocations.

public ContainerdNetworkManager(Tasks.TasksClient tasksClient, ContainerdOptions options, ILogger<ContainerdNetworkManager> logger)

Parameters

tasksClient Tasks.TasksClient
options ContainerdOptions
logger ILogger<ContainerdNetworkManager>

Remarks

CNI is required. containerd delegates all networking to the Container Network Interface (CNI) plugin framework. This implementation reads and writes CNI configuration files stored in CniConfigPath (default /etc/cni/net.d).

Before using any network operations you must install CNI plugins on the host, e.g.:

apt install containernetworking-plugins   # Debian / Ubuntu
dnf install containernetworking-plugins   # RHEL / Fedora

or download binaries from https://github.com/containernetworking/plugins/releases.

Connect / Disconnect invoke CNI plugin binaries using the CNI wire protocol (the same mechanism used by go-cni). The container's network namespace is resolved from its running task PID via /proc/{pid}/ns/net, so the container must have a running task before calling these methods.

Methods

ConnectAsync(string, string, IEnumerable<string>?, CancellationToken)

Connects a container to a network.

public Task ConnectAsync(string networkId, string containerId, IEnumerable<string>? aliases = null, CancellationToken cancellationToken = default)

Parameters

networkId string
containerId string
aliases IEnumerable<string>
cancellationToken CancellationToken

Returns

Task

Remarks

Invokes the CNI ADD command for the specified network, wiring the network interface into the container's network namespace. The container must have a running task so that its PID—and therefore its network namespace at /proc/{pid}/ns/net—can be resolved.

CreateAsync(string, string, CancellationToken)

Creates a new network.

public Task<string> CreateAsync(string name, string driver = "bridge", CancellationToken cancellationToken = default)

Parameters

name string
driver string
cancellationToken CancellationToken

Returns

Task<string>

Remarks

Creates a CNI bridge network configuration file in CniConfigPath. The driver parameter maps to the CNI plugin type (e.g. bridge, macvlan, ipvlan). The corresponding plugin binary must exist in CniBinPath.

DisconnectAsync(string, string, CancellationToken)

Disconnects a container from a network.

public Task DisconnectAsync(string networkId, string containerId, CancellationToken cancellationToken = default)

Parameters

networkId string
containerId string
cancellationToken CancellationToken

Returns

Task

Remarks

Invokes the CNI DEL command for the specified network, removing the network interface from the container's network namespace. The container must have a running task.

ListAsync(CancellationToken)

Lists all networks.

public Task<IReadOnlyList<NetworkInfo>> ListAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task<IReadOnlyList<NetworkInfo>>

RemoveAsync(string, CancellationToken)

Removes a network.

public Task RemoveAsync(string networkId, CancellationToken cancellationToken = default)

Parameters

networkId string
cancellationToken CancellationToken

Returns

Task

Remarks

Removes the CNI configuration file associated with the given network identifier (the file base-name returned by CreateAsync(string, string, CancellationToken) or the Id from ListAsync(CancellationToken)).