use env for cache mode

This commit is contained in:
fanyangyang 2020-06-11 11:49:29 +08:00
parent 9ef470895c
commit 639fb79d57
5 changed files with 13 additions and 15 deletions

View File

@ -79,7 +79,6 @@ type Request struct {
CachePVCName string CachePVCName string
CacheMode string CacheMode string
CachePath string CachePath string
BuilderInNode string
TenantID string TenantID string
SourceDir string SourceDir string
CacheDir string CacheDir string

View File

@ -307,10 +307,12 @@ func (s *slugBuild) runBuildJob(re *Request) error {
podSpec := corev1.PodSpec{RestartPolicy: corev1.RestartPolicyOnFailure} // only support never and onfailure podSpec := corev1.PodSpec{RestartPolicy: corev1.RestartPolicyOnFailure} // only support never and onfailure
// schedule builder // schedule builder
if re.BuilderInNode != "" { if re.CacheMode == "hostpath" {
logrus.Debugf("builder schedule to node: %s", re.BuilderInNode) logrus.Debugf("builder cache mode using hostpath, schedule job into current node")
hostIP := os.Getenv("HOST_IP")
if hostIP != "" {
podSpec.NodeSelector = map[string]string{ podSpec.NodeSelector = map[string]string{
"kubernetes.io/hostname": re.BuilderInNode, "kubernetes.io/hostname": hostIP,
} }
podSpec.Tolerations = []corev1.Toleration{ podSpec.Tolerations = []corev1.Toleration{
{ {
@ -318,6 +320,8 @@ func (s *slugBuild) runBuildJob(re *Request) error {
}, },
} }
} }
}
logrus.Debugf("request is: %+v", re) logrus.Debugf("request is: %+v", re)
podSpec.Volumes = []corev1.Volume{ podSpec.Volumes = []corev1.Volume{
{ {

View File

@ -53,7 +53,6 @@ type SourceCodeBuildItem struct {
CachePVCName string `json:"cache_pvc_name"` CachePVCName string `json:"cache_pvc_name"`
CacheMode string `json:"cache_mode"` CacheMode string `json:"cache_mode"`
CachePath string `json:"cache_path"` CachePath string `json:"cache_path"`
BuilderInNode string `json:"builder_in_node"`
ServiceAlias string `json:"service_alias"` ServiceAlias string `json:"service_alias"`
Action string `json:"action"` Action string `json:"action"`
DestImage string `json:"dest_image"` DestImage string `json:"dest_image"`
@ -261,7 +260,6 @@ func (i *SourceCodeBuildItem) codeBuild() (*build.Response, error) {
CachePVCName: i.CachePVCName, CachePVCName: i.CachePVCName,
CacheMode: i.CacheMode, CacheMode: i.CacheMode,
CachePath: i.CachePath, CachePath: i.CachePath,
BuilderInNode: i.BuilderInNode,
} }
res, err := codeBuild.Build(buildReq) res, err := codeBuild.Build(buildReq)
return res, err return res, err

View File

@ -328,7 +328,6 @@ func (e *exectorManager) buildFromSourceCode(task *pb.TaskMessage) {
i.GRDataPVCName = e.cfg.GRDataPVCName i.GRDataPVCName = e.cfg.GRDataPVCName
i.CacheMode = e.cfg.CacheMode i.CacheMode = e.cfg.CacheMode
i.CachePath = e.cfg.CachePath i.CachePath = e.cfg.CachePath
i.BuilderInNode = e.cfg.BuilderInNode
i.Logger.Info("Build app version from source code start", map[string]string{"step": "builder-exector", "status": "starting"}) i.Logger.Info("Build app version from source code start", map[string]string{"step": "builder-exector", "status": "starting"})
start := time.Now() start := time.Now()
defer event.GetManager().ReleaseLogger(i.Logger) defer event.GetManager().ReleaseLogger(i.Logger)

View File

@ -55,7 +55,6 @@ type Config struct {
CachePVCName string CachePVCName string
CacheMode string CacheMode string
CachePath string CachePath string
BuilderInNode string
} }
//Builder builder server //Builder builder server
@ -99,7 +98,6 @@ func (a *Builder) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&a.CachePVCName, "pvc-cache-name", "cache", "pvc name of cache") fs.StringVar(&a.CachePVCName, "pvc-cache-name", "cache", "pvc name of cache")
fs.StringVar(&a.CacheMode, "cache-mode", "pvc", "volume cache mount type, can be hostpath and sharefile, default is sharefile, which mount using pvc") fs.StringVar(&a.CacheMode, "cache-mode", "pvc", "volume cache mount type, can be hostpath and sharefile, default is sharefile, which mount using pvc")
fs.StringVar(&a.CachePath, "cache-path", "/cache", "volume cache mount path, when cache-mode using hostpath, default path is /cache") fs.StringVar(&a.CachePath, "cache-path", "/cache", "volume cache mount path, when cache-mode using hostpath, default path is /cache")
fs.StringVar(&a.BuilderInNode, "job-node", "", "where builder job running")
} }
//SetLog 设置log //SetLog 设置log