Use CNI cache to find container IP

This is an optimization that uses the results cache created by
CNI on the filesystem to store and fetch IP addresses for
containers in the core services and for functions. As part of
the change, the dependency on the syscall code from Weave net
has been removed, and the code should compile on MacOS again.

Updates and rebases the work in #38 by carlosedp

Tested in the original PR, further testing in the incoming
PR.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd)
2021-02-19 12:12:14 +00:00
committed by Alex Ellis
parent 6c0f91e810
commit e8c2eeb052
7 changed files with 57 additions and 196 deletions

View File

@ -3,10 +3,11 @@ package handlers
import (
"context"
"fmt"
"github.com/opencontainers/runtime-spec/specs-go"
"log"
"strings"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/containerd/containerd"
"github.com/containerd/containerd/namespaces"
"github.com/openfaas/faasd/pkg/cninetwork"
@ -106,11 +107,11 @@ func GetFunction(client *containerd.Client, name string) (Function, error) {
fn.pid = task.Pid()
// Get container IP address
ip, err := cninetwork.GetIPfromPID(int(task.Pid()))
ip, err := cninetwork.GetIPAddress(name, task.Pid())
if err != nil {
return Function{}, err
}
fn.IP = ip.String()
fn.IP = ip
}
} else {
replicas = 0