Adds default resources for fetcher pod (#500)

The fetcher needs a relatively smaller set of resources and does not have to be same as the function container/defaults. This change adds defaults for fetcher containers in function pods.
This commit is contained in:
Vishal
2018-02-24 01:07:02 +05:30
committed by GitHub
parent 245506efe3
commit e5b137fe24
3 changed files with 70 additions and 2 deletions
+13 -2
View File
@@ -34,6 +34,7 @@ import (
"github.com/fission/fission"
"github.com/fission/fission/crd"
"github.com/fission/fission/environments/fetcher"
"github.com/fission/fission/executor/util"
)
const (
@@ -87,6 +88,12 @@ func (deploy *NewDeploy) createOrGetDeployment(fn *crd.Function, env *crd.Enviro
return nil, err
}
fetcherResources, err := util.GetFetcherResources()
if err != nil {
log.Printf("Error while parsing fetcher resources: %v", err)
return nil, err
}
deployment := &v1beta1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Labels: deployLabels,
@@ -148,7 +155,7 @@ func (deploy *NewDeploy) createOrGetDeployment(fn *crd.Function, env *crd.Enviro
},
},
// TBD Use smaller default resources, for now needed to make HPA work
Resources: env.Spec.Resources,
Resources: fetcherResources,
ReadinessProbe: &apiv1.Probe{
Handler: apiv1.Handler{
Exec: &apiv1.ExecAction{
@@ -182,7 +189,7 @@ func (deploy *NewDeploy) createOrGetDeployment(fn *crd.Function, env *crd.Enviro
}
time.Sleep(time.Second)
}
return nil, errors.New("Failed to create deployment within timeout window")
return nil, errors.New("failed to create deployment within timeout window")
}
return nil, err
@@ -214,6 +221,10 @@ func (deploy *NewDeploy) createOrGetHpa(hpaName string, execStrategy *fission.Ex
return existingHpa, err
}
if depl == nil {
return nil, errors.New("failed to create HPA, found empty deployment")
}
if err != nil && k8s_err.IsNotFound(err) {
hpa := asv1.HorizontalPodAutoscaler{
ObjectMeta: metav1.ObjectMeta{
+7
View File
@@ -45,6 +45,7 @@ import (
"github.com/fission/fission/environments/fetcher"
fetcherClient "github.com/fission/fission/environments/fetcher/client"
"github.com/fission/fission/executor/fscache"
"github.com/fission/fission/executor/util"
)
const POD_PHASE_RUNNING string = "Running"
@@ -433,6 +434,11 @@ 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
}
deployment := &v1beta1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: poolDeploymentName,
@@ -515,6 +521,7 @@ func (gp *GenericPool) createPool() error {
MountPath: gp.sharedCfgMapPath,
},
},
Resources: fetcherResources,
Command: []string{"/fetcher",
"-secret-dir", gp.sharedSecretPath,
"-cfgmap-dir", gp.sharedCfgMapPath,
+50
View File
@@ -0,0 +1,50 @@
/*
Copyright 2016 The Fission Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package util
import (
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/client-go/pkg/api/v1"
)
var resources map[string]resource.Quantity
func init() {
resources = make(map[string]resource.Quantity)
mincpu, _ := resource.ParseQuantity("10m")
resources["mincpu"] = mincpu
minmem, _ := resource.ParseQuantity("16Mi")
resources["minmem"] = minmem
maxcpu, _ := resource.ParseQuantity("40m")
resources["maxcpu"] = maxcpu
maxmem, _ := resource.ParseQuantity("128Mi")
resources["maxmem"] = maxmem
}
func GetFetcherResources() (v1.ResourceRequirements, error) {
fetcherResources := v1.ResourceRequirements{
Requests: map[v1.ResourceName]resource.Quantity{
v1.ResourceCPU: resources["mincpu"],
v1.ResourceMemory: resources["minmem"],
},
Limits: map[v1.ResourceName]resource.Quantity{
v1.ResourceCPU: resources["maxcpu"],
v1.ResourceMemory: resources["maxmem"],
},
}
return fetcherResources, nil
}