Fix executor does not reap specialized function pod when env no longer exists (#633)

This commit is contained in:
Ta-Ching Chen
2018-04-19 07:39:37 +08:00
committed by GitHub
parent 0194f53e12
commit 400e19a48f
2 changed files with 31 additions and 40 deletions
+29 -35
View File
@@ -22,9 +22,9 @@ import (
"strings" "strings"
"time" "time"
"k8s.io/apimachinery/pkg/api/errors"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
"k8s.io/client-go/pkg/api" "k8s.io/client-go/pkg/api"
@@ -104,52 +104,46 @@ func idleObjectReaper(kubeClient *kubernetes.Clientset,
log.Fatalf("Failed to get environment list: %v", err) log.Fatalf("Failed to get environment list: %v", err)
} }
envList := make(map[types.UID]struct{})
for i := range envs.Items { for i := range envs.Items {
env := envs.Items[i] env := envs.Items[i]
if env.Spec.AllowedFunctionsPerContainer == fission.AllowedFunctionsPerContainerInfinite { envList[env.Metadata.UID] = struct{}{}
continue }
funcSvcs, err := fsCache.ListOld(idlePodReapTime)
if err != nil {
log.Printf("Error reaping idle pods: %v", err)
continue
}
for _, fsvc := range funcSvcs {
if _, ok := envList[fsvc.Environment.Metadata.UID]; !ok {
log.Printf("Environment %v for function %v no longer exists",
fsvc.Environment.Metadata.Name, fsvc.Name)
} }
funcSvcs, err := fsCache.ListOld(&env.Metadata, idlePodReapTime)
if err != nil { if fsvc.Environment.Spec.AllowedFunctionsPerContainer == fission.AllowedFunctionsPerContainerInfinite {
log.Printf("Error reaping idle pods: %v", err)
continue continue
} }
for _, fsvc := range funcSvcs { // Newdeploy manager handles the function delete event and clean cache/kubeobjs itself,
// so we ignore the function service cache with newdepoy executor type here.
fn, err := fissionClient.Functions(fsvc.Function.Namespace).Get(fsvc.Function.Name) if fsvc.Executor != fscache.NEWDEPLOY {
if err == nil { deleted, err := fsCache.DeleteOld(fsvc, idlePodReapTime)
// Ignore functions of NewDeploy ExecutorType with MinScale > 0 if err != nil {
if fn.Spec.InvokeStrategy.ExecutionStrategy.MinScale > 0 && log.Printf("Error deleting Kubernetes objects for fsvc '%v': %v", fsvc, err)
fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType == fission.ExecutorTypeNewdeploy { log.Printf("Object Name| Object Kind | Object Namespace")
continue for _, kubeobj := range fsvc.KubernetesObjects {
log.Printf("%v | %v | %v", kubeobj.Name, kubeobj.Kind, kubeobj.Namespace)
} }
} }
// Return errors not equal to "is not found" error if !deleted {
if err != nil && !errors.IsNotFound(err) {
log.Printf("Error getting function: %v", fsvc.Function.Name)
continue continue
} }
// Newdeploy manager handles the function delete event and clean cache/kubeobjs itself, for _, kubeobj := range fsvc.KubernetesObjects {
// so we ignore the function service cache with newdepoy executor type here. deleteKubeobject(kubeClient, &kubeobj)
if fsvc.Executor != fscache.NEWDEPLOY {
deleted, err := fsCache.DeleteOld(fsvc, idlePodReapTime)
if err != nil {
log.Printf("Error deleting Kubernetes objects for fsvc '%v': %v", fsvc, err)
log.Printf("Object Name| Object Kind | Object Namespace")
for _, kubeobj := range fsvc.KubernetesObjects {
log.Printf("%v | %v | %v", kubeobj.Name, kubeobj.Kind, kubeobj.Namespace)
}
}
if !deleted {
continue
}
for _, kubeobj := range fsvc.KubernetesObjects {
deleteKubeobject(kubeClient, &kubeobj)
}
} }
} }
} }
+2 -5
View File
@@ -68,7 +68,6 @@ type (
address string address string
kubernetesObjects []api.ObjectReference kubernetesObjects []api.ObjectReference
age time.Duration age time.Duration
env *metav1.ObjectMeta // used for ListOld
responseChannel chan *fscResponse responseChannel chan *fscResponse
} }
fscResponse struct { fscResponse struct {
@@ -117,8 +116,7 @@ func (fsc *FunctionServiceCache) service() {
funcObjects := make([]*FuncSvc, 0) funcObjects := make([]*FuncSvc, 0)
for _, funcSvc := range fscs { for _, funcSvc := range fscs {
fsvc := funcSvc.(*FuncSvc) fsvc := funcSvc.(*FuncSvc)
if fsvc.Environment.Metadata.UID == req.env.UID && if time.Since(fsvc.Atime) > req.age {
time.Since(fsvc.Atime) > req.age {
funcObjects = append(funcObjects, fsvc) funcObjects = append(funcObjects, fsvc)
} }
} }
@@ -263,12 +261,11 @@ func (fsc *FunctionServiceCache) DeleteOld(fsvc *FuncSvc, minAge time.Duration)
return true, nil return true, nil
} }
func (fsc *FunctionServiceCache) ListOld(env *metav1.ObjectMeta, age time.Duration) ([]*FuncSvc, error) { func (fsc *FunctionServiceCache) ListOld(age time.Duration) ([]*FuncSvc, error) {
responseChannel := make(chan *fscResponse) responseChannel := make(chan *fscResponse)
fsc.requestChannel <- &fscRequest{ fsc.requestChannel <- &fscRequest{
requestType: LISTOLD, requestType: LISTOLD,
age: age, age: age,
env: env,
responseChannel: responseChannel, responseChannel: responseChannel,
} }
resp := <-responseChannel resp := <-responseChannel