diff --git a/pkg/provider/handlers/cni_network.go b/pkg/provider/handlers/cni_network.go index 5cdfcb1..95e304a 100644 --- a/pkg/provider/handlers/cni_network.go +++ b/pkg/provider/handlers/cni_network.go @@ -161,8 +161,12 @@ func GetIPfromPID(pid int) (*net.IP, error) { if addrsErr != nil { return nil, fmt.Errorf("unable to find address for veth pair using: %v %s", peerIDs, addrsErr) } - return &addrs[0].CIDRs[0].IP, nil + if len(addrs) > 0 && len(addrs[0].CIDRs) > 0 { + return &addrs[0].CIDRs[0].IP, nil + } + + return nil, fmt.Errorf("no IP found for function") } // NetID generates the network IF based on task name and task PID diff --git a/pkg/provider/handlers/containers.go b/pkg/provider/handlers/containers.go index c441759..1092459 100644 --- a/pkg/provider/handlers/containers.go +++ b/pkg/provider/handlers/containers.go @@ -60,8 +60,13 @@ func GetFunction(client *containerd.Client, name string) (Function, error) { if svc.Status == "running" { replicas = 1 f.pid = task.Pid() + // Get container IP address - ip, _ := GetIPfromPID(int(task.Pid())) + ip, getIPErr := GetIPfromPID(int(task.Pid())) + if getIPErr != nil { + return Function{}, getIPErr + } + f.IP = ip.String() } } else { diff --git a/pkg/provider/handlers/delete.go b/pkg/provider/handlers/delete.go index fe6f85f..093dcaa 100644 --- a/pkg/provider/handlers/delete.go +++ b/pkg/provider/handlers/delete.go @@ -49,6 +49,8 @@ func MakeDeleteHandler(client *containerd.Client, cni gocni.CNI) func(w http.Res } ctx := namespaces.WithNamespace(context.Background(), FunctionNamespace) + + // TODO: this needs to still happen if the task is paused if function.replicas != 0 { err = DeleteCNINetwork(ctx, cni, client, name) if err != nil { diff --git a/pkg/provider/handlers/info.go b/pkg/provider/handlers/info.go index 59b43b5..aa1d13f 100644 --- a/pkg/provider/handlers/info.go +++ b/pkg/provider/handlers/info.go @@ -8,10 +8,11 @@ import ( ) const ( - //OrchestrationIdentifier identifier string for provider orchestration + // OrchestrationIdentifier identifier string for provider orchestration OrchestrationIdentifier = "containerd" - //ProviderName name of the provider - ProviderName = "faas-containerd" + + // ProviderName name of the provider + ProviderName = "faasd" ) //MakeInfoHandler creates handler for /system/info endpoint diff --git a/pkg/service/service.go b/pkg/service/service.go index 6529ec9..06f9877 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -53,8 +53,11 @@ func Remove(ctx context.Context, client *containerd.Client, name string) error { return nil } -// From Stellar +// Adapted from Stellar - https://github.com/stellar func killTask(ctx context.Context, task containerd.Task) error { + + killTimeout := 30 * time.Second + wg := &sync.WaitGroup{} wg.Add(1) var err error @@ -69,11 +72,12 @@ func killTask(ctx context.Context, task containerd.Task) error { if err := task.Kill(ctx, unix.SIGTERM, containerd.WithKillAll); err != nil { log.Printf("error killing container task: %s", err) } + select { case <-wait: task.Delete(ctx) return - case <-time.After(5 * time.Second): + case <-time.After(killTimeout): if err := task.Kill(ctx, unix.SIGKILL, containerd.WithKillAll); err != nil { log.Printf("error force killing container task: %s", err) }