mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-11-29 18:27:58 +08:00
setup config file permission mode
This commit is contained in:
parent
ab2c9c84e1
commit
15417ca4cd
@ -25,6 +25,7 @@ import (
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/goodrain/rainbond/api/handler"
|
||||
api_model "github.com/goodrain/rainbond/api/model"
|
||||
"github.com/goodrain/rainbond/api/util/bcode"
|
||||
ctxutil "github.com/goodrain/rainbond/api/util/ctx"
|
||||
dbmodel "github.com/goodrain/rainbond/db/model"
|
||||
httputil "github.com/goodrain/rainbond/util/http"
|
||||
@ -186,6 +187,11 @@ func (t *TenantStruct) UpdVolume(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if req.Mode != nil && (*req.Mode > 777 || *req.Mode < 0) {
|
||||
httputil.ReturnBcodeError(r, w, bcode.NewBadRequest("mode be a number between 0 and 777 (octal)"))
|
||||
return
|
||||
}
|
||||
|
||||
sid := r.Context().Value(ctxutil.ContextKey("service_id")).(string)
|
||||
if err := handler.GetServiceManager().UpdVolume(sid, &req); err != nil {
|
||||
httputil.ReturnError(r, w, 500, err.Error())
|
||||
@ -354,6 +360,11 @@ func AddVolume(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if avs.Body.Mode != nil && (*avs.Body.Mode > 777 || *avs.Body.Mode < 0) {
|
||||
httputil.ReturnBcodeError(r, w, bcode.NewBadRequest("mode be a number between 0 and 777 (octal)"))
|
||||
return
|
||||
}
|
||||
|
||||
tsv := &dbmodel.TenantServiceVolume{
|
||||
ServiceID: serviceID,
|
||||
VolumeName: avs.Body.VolumeName,
|
||||
@ -368,6 +379,7 @@ func AddVolume(w http.ResponseWriter, r *http.Request) {
|
||||
BackupPolicy: avs.Body.BackupPolicy,
|
||||
ReclaimPolicy: avs.Body.ReclaimPolicy,
|
||||
AllowExpansion: avs.Body.AllowExpansion,
|
||||
Mode: avs.Body.Mode,
|
||||
}
|
||||
|
||||
// TODO fanyangyang validate VolumeCapacity AccessMode SharePolicy BackupPolicy ReclaimPolicy AllowExpansion
|
||||
|
@ -51,9 +51,7 @@ import (
|
||||
|
||||
api_model "github.com/goodrain/rainbond/api/model"
|
||||
dberr "github.com/goodrain/rainbond/db/errors"
|
||||
core_model "github.com/goodrain/rainbond/db/model"
|
||||
dbmodel "github.com/goodrain/rainbond/db/model"
|
||||
eventutil "github.com/goodrain/rainbond/eventlog/util"
|
||||
gclient "github.com/goodrain/rainbond/mq/client"
|
||||
core_util "github.com/goodrain/rainbond/util"
|
||||
typesv1 "github.com/goodrain/rainbond/worker/appm/types/v1"
|
||||
@ -713,10 +711,10 @@ func (s *ServiceAction) ServiceCreate(sc *api_model.ServiceStruct) error {
|
||||
if sc.OSType == "windows" {
|
||||
if err := db.GetManager().TenantServiceLabelDaoTransactions(tx).AddModel(&dbmodel.TenantServiceLable{
|
||||
ServiceID: ts.ServiceID,
|
||||
LabelKey: core_model.LabelKeyNodeSelector,
|
||||
LabelKey: dbmodel.LabelKeyNodeSelector,
|
||||
LabelValue: sc.OSType,
|
||||
}); err != nil {
|
||||
logrus.Errorf("add label %s=%s %v error, %v", core_model.LabelKeyNodeSelector, sc.OSType, ts.ServiceID, err)
|
||||
logrus.Errorf("add label %s=%s %v error, %v", dbmodel.LabelKeyNodeSelector, sc.OSType, ts.ServiceID, err)
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
@ -1745,6 +1743,7 @@ func (s *ServiceAction) UpdVolume(sid string, req *api_model.UpdVolumeReq) error
|
||||
return err
|
||||
}
|
||||
v.VolumePath = req.VolumePath
|
||||
v.Mode = req.Mode
|
||||
if err := db.GetManager().TenantServiceVolumeDaoTransactions(tx).UpdateModel(v); err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
@ -1939,7 +1938,7 @@ func (s *ServiceAction) GetStatus(serviceID string) (*api_model.StatusList, erro
|
||||
|
||||
//GetServicesStatus 获取一组应用状态,若 serviceIDs为空,获取租户所有应用状态
|
||||
func (s *ServiceAction) GetServicesStatus(tenantID string, serviceIDs []string) []map[string]interface{} {
|
||||
if serviceIDs == nil || len(serviceIDs) == 0 {
|
||||
if len(serviceIDs) == 0 {
|
||||
services, _ := db.GetManager().TenantServiceDao().GetServicesByTenantID(tenantID)
|
||||
for _, s := range services {
|
||||
serviceIDs = append(serviceIDs, s.ServiceID)
|
||||
@ -1950,11 +1949,9 @@ func (s *ServiceAction) GetServicesStatus(tenantID string, serviceIDs []string)
|
||||
}
|
||||
statusList := s.statusCli.GetStatuss(strings.Join(serviceIDs, ","))
|
||||
var info = make([]map[string]interface{}, 0)
|
||||
if statusList != nil {
|
||||
for k, v := range statusList {
|
||||
serviceInfo := map[string]interface{}{"service_id": k, "status": v, "status_cn": TransStatus(v), "used_mem": 0}
|
||||
info = append(info, serviceInfo)
|
||||
}
|
||||
for k, v := range statusList {
|
||||
serviceInfo := map[string]interface{}{"service_id": k, "status": v, "status_cn": TransStatus(v), "used_mem": 0}
|
||||
info = append(info, serviceInfo)
|
||||
}
|
||||
return info
|
||||
}
|
||||
@ -2019,7 +2016,7 @@ func (s *ServiceAction) CreateTenant(t *dbmodel.Tenants) error {
|
||||
|
||||
//CreateTenandIDAndName create tenant_id and tenant_name
|
||||
func (s *ServiceAction) CreateTenandIDAndName(eid string) (string, string, error) {
|
||||
id := fmt.Sprintf("%s", uuid.NewV4())
|
||||
id := uuid.NewV4().String()
|
||||
uid := strings.Replace(id, "-", "", -1)
|
||||
name := strings.Split(id, "-")[0]
|
||||
logrus.Debugf("uuid is %v, name is %v", uid, name)
|
||||
@ -2103,14 +2100,12 @@ func (s *ServiceAction) GetMultiServicePods(serviceIDs []string) (*K8sPodInfos,
|
||||
}
|
||||
convpod := func(serviceID string, pods []*pb.ServiceAppPod) []*K8sPodInfo {
|
||||
var podsInfoList []*K8sPodInfo
|
||||
var podNames []string
|
||||
for _, v := range pods {
|
||||
var podInfo K8sPodInfo
|
||||
podInfo.PodName = v.PodName
|
||||
podInfo.PodIP = v.PodIp
|
||||
podInfo.PodStatus = v.PodStatus
|
||||
podInfo.ServiceID = serviceID
|
||||
podNames = append(podNames, v.PodName)
|
||||
podsInfoList = append(podsInfoList, &podInfo)
|
||||
}
|
||||
return podsInfoList
|
||||
@ -2298,23 +2293,6 @@ func (s *ServiceAction) deleteThirdComponent(ctx context.Context, component *dbm
|
||||
return nil
|
||||
}
|
||||
|
||||
// delLogFile deletes persistent data related to the service based on serviceID.
|
||||
func (s *ServiceAction) delLogFile(serviceID string, eventIDs []string) {
|
||||
// log generated during service running
|
||||
dockerLogPath := eventutil.DockerLogFilePath(s.conf.LogPath, serviceID)
|
||||
if err := os.RemoveAll(dockerLogPath); err != nil {
|
||||
logrus.Warningf("remove docker log files: %v", err)
|
||||
}
|
||||
// log generated by the service event
|
||||
eventLogPath := eventutil.EventLogFilePath(s.conf.LogPath)
|
||||
for _, eventID := range eventIDs {
|
||||
eventLogFileName := eventutil.EventLogFileName(eventLogPath, eventID)
|
||||
if err := os.RemoveAll(eventLogFileName); err != nil {
|
||||
logrus.Warningf("file: %s; remove event log file: %v", eventLogFileName, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ServiceAction) gcTaskBody(tenantID, serviceID string) (map[string]interface{}, error) {
|
||||
events, err := db.GetManager().ServiceEventDao().ListByTargetID(serviceID)
|
||||
if err != nil {
|
||||
|
@ -60,7 +60,8 @@ type AddVolumeStruct struct {
|
||||
// ReclaimPolicy 回收策略
|
||||
ReclaimPolicy string `json:"reclaim_policy"`
|
||||
// AllowExpansion 是否支持扩展
|
||||
AllowExpansion bool `json:"allow_expansion"`
|
||||
AllowExpansion bool `json:"allow_expansion"`
|
||||
Mode *int32 `json:"mode"`
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,6 +244,7 @@ type UpdVolumeReq struct {
|
||||
VolumeType string `json:"volume_type" validate:"volume_type|required"`
|
||||
FileContent string `json:"file_content"`
|
||||
VolumePath string `json:"volume_path" validate:"volume_path|required"`
|
||||
Mode *int32 `json:"mode"`
|
||||
}
|
||||
|
||||
// VolumeWithStatusResp volume status
|
||||
|
@ -476,6 +476,7 @@ type TenantServiceVolume struct {
|
||||
AllowExpansion bool `gorm:"column:allow_expansion" json:"allow_expansion"`
|
||||
// VolumeProviderName 使用的存储驱动别名
|
||||
VolumeProviderName string `gorm:"column:volume_provider_name" json:"volume_provider_name"`
|
||||
Mode *int32 `gorm:"column:mode" json:"mode"`
|
||||
}
|
||||
|
||||
//TableName 表名
|
||||
|
1
go.mod
1
go.mod
@ -99,6 +99,7 @@ require (
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/genproto v0.0.0-20201201144952-b05cb90ed32e // indirect
|
||||
google.golang.org/grpc v1.33.2
|
||||
google.golang.org/protobuf v1.25.0
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6
|
||||
gopkg.in/src-d/go-git.v4 v4.13.1
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
|
@ -67,7 +67,7 @@ func (v *ConfigFileVolume) CreateVolume(define *Define) error {
|
||||
}
|
||||
cmap.Data[path.Base(v.svm.VolumePath)] = util.ParseVariable(cf.FileContent, configs)
|
||||
v.as.SetConfigMap(cmap)
|
||||
define.SetVolumeCMap(cmap, path.Base(v.svm.VolumePath), v.svm.VolumePath, false)
|
||||
define.SetVolumeCMap(cmap, path.Base(v.svm.VolumePath), v.svm.VolumePath, false, v.svm.Mode)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ func (v *ConfigFileVolume) CreateDependVolume(define *Define) error {
|
||||
for _, env := range v.envs {
|
||||
configs[env.Name] = env.Value
|
||||
}
|
||||
_, err := v.dbmanager.TenantServiceVolumeDao().GetVolumeByServiceIDAndName(v.smr.DependServiceID, v.smr.VolumeName)
|
||||
depVol, err := v.dbmanager.TenantServiceVolumeDao().GetVolumeByServiceIDAndName(v.smr.DependServiceID, v.smr.VolumeName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting TenantServiceVolume according to serviceID(%s) and volumeName(%s): %v",
|
||||
v.smr.DependServiceID, v.smr.VolumeName, err)
|
||||
@ -98,6 +98,6 @@ func (v *ConfigFileVolume) CreateDependVolume(define *Define) error {
|
||||
cmap.Data[path.Base(v.smr.VolumePath)] = util.ParseVariable(cf.FileContent, configs)
|
||||
v.as.SetConfigMap(cmap)
|
||||
|
||||
define.SetVolumeCMap(cmap, path.Base(v.smr.VolumePath), v.smr.VolumePath, false)
|
||||
define.SetVolumeCMap(cmap, path.Base(v.smr.VolumePath), v.smr.VolumePath, false, depVol.Mode)
|
||||
return nil
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/goodrain/rainbond/db"
|
||||
@ -211,8 +212,7 @@ func (v *Define) SetVolume(VolumeType dbmodel.VolumeType, name, mountPath, hostP
|
||||
}
|
||||
|
||||
// SetVolumeCMap sets volumes and volumeMounts. The type of volumes is configMap.
|
||||
func (v *Define) SetVolumeCMap(cmap *corev1.ConfigMap, k, p string, isReadOnly bool) {
|
||||
var configFileMode int32 = 0777
|
||||
func (v *Define) SetVolumeCMap(cmap *corev1.ConfigMap, k, p string, isReadOnly bool, mode *int32) {
|
||||
vm := corev1.VolumeMount{
|
||||
MountPath: p,
|
||||
Name: cmap.Name,
|
||||
@ -221,6 +221,11 @@ func (v *Define) SetVolumeCMap(cmap *corev1.ConfigMap, k, p string, isReadOnly b
|
||||
}
|
||||
v.volumeMounts = append(v.volumeMounts, vm)
|
||||
var defaultMode int32 = 0777
|
||||
if mode != nil {
|
||||
// convert int to octal
|
||||
octal, _ := strconv.ParseInt(strconv.Itoa(int(*mode)), 8, 64)
|
||||
defaultMode = int32(octal)
|
||||
}
|
||||
vo := corev1.Volume{
|
||||
Name: cmap.Name,
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
@ -233,7 +238,7 @@ func (v *Define) SetVolumeCMap(cmap *corev1.ConfigMap, k, p string, isReadOnly b
|
||||
{
|
||||
Key: k,
|
||||
Path: path.Base(p), // subpath
|
||||
Mode: &configFileMode,
|
||||
Mode: &defaultMode,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user