Shorten executor kubernetes objects name (#975)

This commit is contained in:
Ta-Ching Chen
2018-11-24 20:41:38 +08:00
committed by GitHub
parent 82af0e554a
commit 4b5ab0ad93
4 changed files with 41 additions and 22 deletions
+3 -4
View File
@@ -203,8 +203,8 @@ func (deploy *NewDeploy) getDeploymentSpec(fn *crd.Function, env *crd.Environmen
deployment := &v1beta1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Labels: deployLabels,
Name: deployName,
Labels: deployLabels,
},
Spec: v1beta1.DeploymentSpec{
Replicas: &replicas,
@@ -405,9 +405,8 @@ func (deploy *NewDeploy) createOrGetHpa(hpaName string, execStrategy *fission.Ex
if err != nil && k8s_err.IsNotFound(err) {
hpa := asv1.HorizontalPodAutoscaler{
ObjectMeta: metav1.ObjectMeta{
Name: hpaName,
Namespace: depl.ObjectMeta.Namespace,
Labels: depl.Labels,
Name: hpaName,
Labels: depl.Labels,
},
Spec: asv1.HorizontalPodAutoscalerSpec{
ScaleTargetRef: asv1.CrossVersionObjectReference{
+10 -8
View File
@@ -25,6 +25,7 @@ import (
"strings"
"time"
"github.com/dchest/uniuri"
"github.com/pkg/errors"
apiv1 "k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
@@ -547,19 +548,20 @@ func (deploy *NewDeploy) fnDelete(fn *crd.Function) (*fscache.FuncSvc, error) {
}
func (deploy *NewDeploy) getObjName(fn *crd.Function) string {
return fmt.Sprintf("%v-%v",
fn.Metadata.Name,
deploy.instanceID)
return strings.ToLower(fmt.Sprintf("newdeploy-%v-%v-%v",
fn.Metadata.Name, fn.Metadata.Namespace, uniuri.NewLen(8)))
}
func (deploy *NewDeploy) getDeployLabels(fn *crd.Function, env *crd.Environment) map[string]string {
return map[string]string{
"environmentName": env.Metadata.Name,
"environmentUid": string(env.Metadata.UID),
"functionName": fn.Metadata.Name,
"functionUid": string(fn.Metadata.UID),
fission.EXECUTOR_INSTANCEID_LABEL: deploy.instanceID,
"executorType": fission.ExecutorTypeNewdeploy,
fission.EXECUTOR_TYPE: fission.ExecutorTypeNewdeploy,
fission.ENVIRONMENT_NAME: env.Metadata.Name,
fission.ENVIRONMENT_NAMESPACE: env.Metadata.Namespace,
fission.ENVIRONMENT_UID: string(env.Metadata.UID),
fission.FUNCTION_NAME: fn.Metadata.Name,
fission.FUNCTION_NAMESPACE: fn.Metadata.Namespace,
fission.FUNCTION_UID: string(fn.Metadata.UID),
}
}
+17 -10
View File
@@ -157,12 +157,7 @@ func MakeGenericPool(
}
// Labels for generic deployment/RS/pods.
gp.labelsForPool = map[string]string{
"environmentName": gp.env.Metadata.Name,
"environmentUid": string(gp.env.Metadata.UID),
fission.EXECUTOR_INSTANCEID_LABEL: gp.instanceId,
"executorType": fission.ExecutorTypePoolmgr,
}
gp.labelsForPool = gp.getDeployLabels()
// create the pool
err = gp.createPool()
@@ -176,6 +171,16 @@ func MakeGenericPool(
return gp, nil
}
func (gp *GenericPool) getDeployLabels() map[string]string {
return map[string]string{
fission.EXECUTOR_INSTANCEID_LABEL: gp.instanceId,
fission.EXECUTOR_TYPE: fission.ExecutorTypePoolmgr,
fission.ENVIRONMENT_NAME: gp.env.Metadata.Name,
fission.ENVIRONMENT_NAMESPACE: gp.env.Metadata.Namespace,
fission.ENVIRONMENT_UID: string(gp.env.Metadata.UID),
}
}
// choosePodService serializes the choosing of pods
func (gp *GenericPool) choosePodService() {
for {
@@ -456,12 +461,14 @@ func (gp *GenericPool) specializePod(pod *apiv1.Pod, metadata *metav1.ObjectMeta
return nil
}
func (gp *GenericPool) getPoolName() string {
return strings.ToLower(fmt.Sprintf("poolmgr-%v-%v-%v",
gp.env.Metadata.Name, gp.env.Metadata.Namespace, uniuri.NewLen(8)))
}
// A pool is a deployment of generic containers for an env. This
// creates the pool but doesn't wait for any pods to be ready.
func (gp *GenericPool) createPool() error {
poolDeploymentName := fmt.Sprintf("%v-%v-%v",
gp.env.Metadata.Name, gp.env.Metadata.UID, strings.ToLower(gp.poolInstanceId))
fetcherResources, err := util.GetFetcherResources()
if err != nil {
return err
@@ -484,7 +491,7 @@ func (gp *GenericPool) createPool() error {
deployment := &v1beta1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: poolDeploymentName,
Name: gp.getPoolName(),
Labels: gp.labelsForPool,
},
Spec: v1beta1.DeploymentSpec{
+11
View File
@@ -123,6 +123,17 @@ const (
AllowedFunctionsPerContainerInfinite = fv1.AllowedFunctionsPerContainerInfinite
)
// executor kubernetes object label key
const (
ENVIRONMENT_NAMESPACE = "environmentNamespace"
ENVIRONMENT_NAME = "environmentName"
ENVIRONMENT_UID = "environmentUid"
FUNCTION_NAMESPACE = "functionNamespace"
FUNCTION_NAME = "functionName"
FUNCTION_UID = "functionUid"
EXECUTOR_TYPE = "executorType"
)
const (
ExecutorTypePoolmgr = fv1.ExecutorTypePoolmgr
ExecutorTypeNewdeploy = fv1.ExecutorTypeNewdeploy