Skip to content

Commit

Permalink
feature: mesos方案env支持ValueFrom TencentBlueKing#533
Browse files Browse the repository at this point in the history
  • Loading branch information
zmberg committed Jul 30, 2020
1 parent 0937c4c commit 61befb1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
15 changes: 15 additions & 0 deletions bcs-common/common/types/rc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ package types
type EnvVar struct {
Name string `json:"name"`
Value string `json:"value,omitempty"`
ValueFrom *EnvVarSource `json:"valueFrom,omitempty"`
}

// EnvVarSource represents a source for the value of an EnvVar.
type EnvVarSource struct {
// Selects a resource of the container: only resources limits and requests
// (limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu, requests.memory and requests.ephemeral-storage) are currently supported.
// +optional
ResourceFieldRef *ResourceFieldSelector `json:"resourceFieldRef,omitempty" protobuf:"bytes,2,opt,name=resourceFieldRef"`
}

// ResourceFieldSelector represents container resources (cpu, memory) and their output format
type ResourceFieldSelector struct {
// Required: resource to select
Resource string `json:"resource" protobuf:"bytes,2,opt,name=resource"`
}

//ContainerPort represents a network port in a single container
Expand Down
19 changes: 18 additions & 1 deletion bcs-mesos/bcs-mesos-driver/mesosdriver/backend/v4http/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package v4http

import (
"encoding/json"
"fmt"
"github.com/Tencent/bk-bcs/bcs-common/common"
"github.com/Tencent/bk-bcs/bcs-common/common/blog"
bhttp "github.com/Tencent/bk-bcs/bcs-common/common/http"
Expand Down Expand Up @@ -272,7 +273,23 @@ func (s *Scheduler) setVersionWithPodSpec(version *types.Version, spec *bcstype.
//env
container.Docker.Env = make(map[string]string)
for _, env := range c.Env {
container.Docker.Env[env.Name] = env.Value
if env.ValueFrom!=nil && env.ValueFrom.ResourceFieldRef!=nil && env.ValueFrom.ResourceFieldRef.Resource!="" {
switch env.ValueFrom.ResourceFieldRef.Resource {
case "requests.cpu":
container.Docker.Env[env.Name] = fmt.Sprintf("%f", container.Resources.Cpus*1000)
case "requests.memory":
container.Docker.Env[env.Name] = fmt.Sprintf("%f", container.Resources.Mem)
case "limits.cpu":
container.Docker.Env[env.Name] = fmt.Sprintf("%f", container.LimitResoures.Cpus*1000)
case "limits.memory":
container.Docker.Env[env.Name] = fmt.Sprintf("%f", container.LimitResoures.Mem)
default:
blog.Errorf("Deployment(%s:%s) Env(%s) ValueFrom(%s) is invalid",
version.ObjectMeta.NameSpace, version.ObjectMeta.Name, env.Name, env.ValueFrom.ResourceFieldRef.Resource)
}
}else {
container.Docker.Env[env.Name] = env.Value
}
}

//volume
Expand Down

0 comments on commit 61befb1

Please sign in to comment.