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
+10 -16
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,31 +104,25 @@ 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(&env.Metadata, idlePodReapTime)
funcSvcs, err := fsCache.ListOld(idlePodReapTime)
if err != nil { if err != nil {
log.Printf("Error reaping idle pods: %v", err) log.Printf("Error reaping idle pods: %v", err)
continue continue
} }
for _, fsvc := range funcSvcs { for _, fsvc := range funcSvcs {
if _, ok := envList[fsvc.Environment.Metadata.UID]; !ok {
fn, err := fissionClient.Functions(fsvc.Function.Namespace).Get(fsvc.Function.Name) log.Printf("Environment %v for function %v no longer exists",
if err == nil { fsvc.Environment.Metadata.Name, fsvc.Name)
// Ignore functions of NewDeploy ExecutorType with MinScale > 0
if fn.Spec.InvokeStrategy.ExecutionStrategy.MinScale > 0 &&
fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType == fission.ExecutorTypeNewdeploy {
continue
}
} }
// Return errors not equal to "is not found" error if fsvc.Environment.Spec.AllowedFunctionsPerContainer == fission.AllowedFunctionsPerContainerInfinite {
if err != nil && !errors.IsNotFound(err) {
log.Printf("Error getting function: %v", fsvc.Function.Name)
continue continue
} }
@@ -147,6 +141,7 @@ func idleObjectReaper(kubeClient *kubernetes.Clientset,
if !deleted { if !deleted {
continue continue
} }
for _, kubeobj := range fsvc.KubernetesObjects { for _, kubeobj := range fsvc.KubernetesObjects {
deleteKubeobject(kubeClient, &kubeobj) deleteKubeobject(kubeClient, &kubeobj)
} }
@@ -154,7 +149,6 @@ func idleObjectReaper(kubeClient *kubernetes.Clientset,
} }
} }
} }
}
func deleteKubeobject(kubeClient *kubernetes.Clientset, kubeobj *api.ObjectReference) { func deleteKubeobject(kubeClient *kubernetes.Clientset, kubeobj *api.ObjectReference) {
switch strings.ToLower(kubeobj.Kind) { switch strings.ToLower(kubeobj.Kind) {
+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