Fix no kubeobjs get created if fn created before env creation (#1428)

When a function is created before the creation of the environment it's used, the newdeploy will not be able to create kube objs. Hence no function service record is inserted into the cache.

When getFuncSvc is called, the newdeploy tries to find the record in service cache in order to create kube objs with the same name used in previous kubeobjs creation. However, due to no record in the cache, a NotFound error is returned directly and causes the problem. To solve this, we use fn meta UID to ensure we always get the same obj name instead of getting it from the cache.
This commit is contained in:
Ta-Ching Chen
2019-11-22 01:37:02 +08:00
committed by GitHub
parent 04654ca465
commit af73d0ce1a
2 changed files with 3 additions and 11 deletions
-1
View File
@@ -381,7 +381,6 @@ type (
TargetCPUPercent int
// This is the timeout setting for executor to wait for pod specialization.
// Currently, only newdeploy utilizes this value.
SpecializationTimeout int
}
+3 -10
View File
@@ -24,7 +24,6 @@ import (
"strings"
"time"
"github.com/dchest/uniuri"
"github.com/fission/fission/pkg/throttler"
"github.com/fission/fission/pkg/utils"
multierror "github.com/hashicorp/go-multierror"
@@ -316,14 +315,6 @@ func (deploy *NewDeploy) fnCreate(fn *fv1.Function, firstcreate bool) (*fscache.
}
objName := deploy.getObjName(fn)
if !firstcreate {
// retrieve back the previous obj name for later use.
fsvc, err := deploy.fsCache.GetByFunctionUID(fn.Metadata.UID)
if err != nil {
return nil, errors.Wrap(err, "error getting existed function service cache")
}
objName = fsvc.Name
}
deployLabels := deploy.getDeployLabels(fn.Metadata, env.Metadata)
// to support backward compatibility, if the function was created in default ns, we fall back to creating the
@@ -603,7 +594,9 @@ func (deploy *NewDeploy) fnDelete(fn *fv1.Function) error {
// getObjName returns a unique name for kubernetes objects of function
func (deploy *NewDeploy) getObjName(fn *fv1.Function) string {
return strings.ToLower(fmt.Sprintf("newdeploy-%v-%v-%v", fn.Metadata.Name, fn.Metadata.Namespace, uniuri.NewLen(8)))
// use meta uuid of function, this ensure we always get the same name for the same function.
uid := fn.Metadata.UID[len(fn.Metadata.UID)-17:]
return strings.ToLower(fmt.Sprintf("newdeploy-%v-%v-%v", fn.Metadata.Name, fn.Metadata.Namespace, uid))
}
func (deploy *NewDeploy) getDeployLabels(fnMeta metav1.ObjectMeta, envMeta metav1.ObjectMeta) map[string]string {