mirror of
https://github.com/openfaas/faasd.git
synced 2025-06-25 08:13:24 +00:00
Migrate to containerd 1.54
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
committed by
Alex Ellis
parent
4c9c66812a
commit
2ae8b31ac0
75
vendor/github.com/containerd/go-cni/README.md
generated
vendored
75
vendor/github.com/containerd/go-cni/README.md
generated
vendored
@ -1,7 +1,10 @@
|
||||
[](https://travis-ci.org/containerd/go-cni) [](https://godoc.org/github.com/containerd/go-cni)
|
||||
|
||||
# go-cni
|
||||
|
||||
[](https://pkg.go.dev/github.com/containerd/go-cni)
|
||||
[](https://github.com/containerd/go-cni/actions?query=workflow%3ACI)
|
||||
[](https://codecov.io/gh/containerd/go-cni)
|
||||
[](https://goreportcard.com/report/github.com/containerd/go-cni)
|
||||
|
||||
A generic CNI library to provide APIs for CNI plugin interactions. The library provides APIs to:
|
||||
|
||||
- Load CNI network config from different sources
|
||||
@ -13,35 +16,67 @@ go-cni aims to support plugins that implement [Container Network Interface](http
|
||||
|
||||
## Usage
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
gocni "github.com/containerd/go-cni"
|
||||
)
|
||||
|
||||
func main() {
|
||||
id := "123456"
|
||||
netns := "/proc/9999/ns/net"
|
||||
id := "example"
|
||||
netns := "/var/run/netns/example-ns-1"
|
||||
|
||||
// CNI allows multiple CNI configurations and the network interface
|
||||
// will be named by eth0, eth1, ..., ethN.
|
||||
ifPrefixName := "eth"
|
||||
defaultIfName := "eth0"
|
||||
// Initialize library
|
||||
l = gocni.New(gocni.WithMinNetworkCount(2),
|
||||
gocni.WithPluginConfDir("/etc/mycni/net.d"),
|
||||
gocni.WithPluginDir([]string{"/opt/mycni/bin", "/opt/cni/bin"}),
|
||||
gocni.WithDefaultIfName(defaultIfName))
|
||||
|
||||
// Load the cni configuration
|
||||
err:= l.Load(gocni.WithLoNetwork, gocni.WithDefaultConf)
|
||||
if err != nil{
|
||||
log.Errorf("failed to load cni configuration: %v", err)
|
||||
return
|
||||
|
||||
// Initializes library
|
||||
l, err := gocni.New(
|
||||
// one for loopback network interface
|
||||
gocni.WithMinNetworkCount(2),
|
||||
gocni.WithPluginConfDir("/etc/cni/net.d"),
|
||||
gocni.WithPluginDir([]string{"/opt/cni/bin"}),
|
||||
// Sets the prefix for network interfaces, eth by default
|
||||
gocni.WithInterfacePrefix(ifPrefixName))
|
||||
if err != nil {
|
||||
log.Fatalf("failed to initialize cni library: %v", err)
|
||||
}
|
||||
|
||||
|
||||
// Load the cni configuration
|
||||
if err := l.Load(gocni.WithLoNetwork, gocni.WithDefaultConf); err != nil {
|
||||
log.Fatalf("failed to load cni configuration: %v", err)
|
||||
}
|
||||
|
||||
// Setup network for namespace.
|
||||
labels := map[string]string{
|
||||
"K8S_POD_NAMESPACE": "namespace1",
|
||||
"K8S_POD_NAME": "pod1",
|
||||
"K8S_POD_INFRA_CONTAINER_ID": id,
|
||||
// Plugin tolerates all Args embedded by unknown labels, like
|
||||
// K8S_POD_NAMESPACE/NAME/INFRA_CONTAINER_ID...
|
||||
"IgnoreUnknown": "1",
|
||||
}
|
||||
result, err := l.Setup(id, netns, gocni.WithLabels(labels))
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Teardown network
|
||||
defer func() {
|
||||
if err := l.Remove(ctx, id, netns, gocni.WithLabels(labels)); err != nil {
|
||||
log.Fatalf("failed to teardown network: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Setup network
|
||||
result, err := l.Setup(ctx, id, netns, gocni.WithLabels(labels))
|
||||
if err != nil {
|
||||
log.Errorf("failed to setup network for namespace %q: %v",id, err)
|
||||
return
|
||||
log.Fatalf("failed to setup network for namespace: %v", err)
|
||||
}
|
||||
|
||||
|
||||
// Get IP of the default interface
|
||||
IP := result.Interfaces[defaultIfName].IPConfigs[0].IP.String()
|
||||
fmt.Printf("IP of the default interface %s:%s", defaultIfName, IP)
|
||||
|
Reference in New Issue
Block a user