Skip to content

Commit

Permalink
perf: support for custom storage types (#1705)
Browse files Browse the repository at this point in the history
* perf: support for custom storage types

* perf: create volume failure

* fix: merge added redundant files
  • Loading branch information
ZhangSetSail authored Jul 20, 2023
1 parent 4b0755e commit c1b43e5
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 30 deletions.
2 changes: 2 additions & 0 deletions cmd/worker/option/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Config struct {
Listen string
HostIP string
ServerPort int
SharedStorageClass string
KubeClient kubernetes.Interface
LeaderElectionNamespace string
LeaderElectionIdentity string
Expand Down Expand Up @@ -106,6 +107,7 @@ func (a *Worker) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&a.RBDNamespace, "rbd-system-namespace", "rbd-system", "rbd components kubernetes namespace")
fs.StringVar(&a.GrdataPVCName, "grdata-pvc-name", "rbd-cpt-grdata", "The name of grdata persistent volume claim")
fs.StringVar(&a.Helm.DataDir, "/grdata/helm", "/grdata/helm", "The data directory of Helm.")
fs.StringVar(&a.SharedStorageClass, "shared-storageclass", "", "custom shared storage class.use the specified storageclass to create shared storage, if this parameter is not specified, it will use rainbondsssc by default")
a.Helm.RepoFile = path.Join(a.Helm.DataDir, "repo/repositories.yaml")
a.Helm.RepoCache = path.Join(a.Helm.DataDir, "cache")
a.Helm.ChartCache = path.Join(a.Helm.DataDir, "chart")
Expand Down
2 changes: 1 addition & 1 deletion cmd/worker/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func Run(s *option.Worker) error {
}

//step 5: create controller manager
controllerManager := controller.NewManager(cachestore, clientset, runtimeClient)
controllerManager := controller.NewManager(s.Config, cachestore, clientset, runtimeClient)
defer controllerManager.Stop()

//step 6 : start runtime master
Expand Down
6 changes: 5 additions & 1 deletion worker/appm/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package controller
import (
"context"
"fmt"
"github.com/goodrain/rainbond/cmd/worker/option"
"sync"

"github.com/goodrain/rainbond/util"
Expand Down Expand Up @@ -74,10 +75,11 @@ type Manager struct {
controllers map[string]Controller
store store.Storer
lock sync.Mutex
config option.Config
}

//NewManager new manager
func NewManager(store store.Storer, client kubernetes.Interface, runtimeClient client.Client) *Manager {
func NewManager(config option.Config, store store.Storer, client kubernetes.Interface, runtimeClient client.Client) *Manager {
ctx, cancel := context.WithCancel(context.Background())
return &Manager{
ctx: ctx,
Expand All @@ -87,6 +89,7 @@ func NewManager(store store.Storer, client kubernetes.Interface, runtimeClient c
runtimeClient: runtimeClient,
controllers: make(map[string]Controller),
store: store,
config: config,
}
}

Expand Down Expand Up @@ -165,6 +168,7 @@ func (m *Manager) StartController(controllerType TypeController, apps ...v1.AppS
manager: m,
stopChan: make(chan struct{}),
ctx: context.Background(),
cfg: m.config,
}
case TypeApplyRuleController:
controller = &applyRuleController{
Expand Down
9 changes: 5 additions & 4 deletions worker/appm/controller/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@ package controller
import (
"context"
"fmt"
"sync"
"time"

"github.com/goodrain/rainbond/cmd/worker/option"
"github.com/goodrain/rainbond/db"
"github.com/goodrain/rainbond/event"
"github.com/goodrain/rainbond/util"
"github.com/goodrain/rainbond/worker/appm/conversion"
v1 "github.com/goodrain/rainbond/worker/appm/types/v1"
"github.com/sirupsen/logrus"
"sync"
"time"
)

type restartController struct {
stopChan chan struct{}
cfg option.Config
controllerID string
appService []v1.AppService
manager *Manager
Expand Down Expand Up @@ -86,7 +87,7 @@ func (s *restartController) restartOne(app v1.AppService) error {
ctx: s.ctx,
controllerID: s.controllerID,
}
newAppService, err := conversion.InitAppService(false, db.GetManager(), app.ServiceID, app.ExtensionSet)
newAppService, err := conversion.InitAppService(s.cfg.SharedStorageClass, false, db.GetManager(), app.ServiceID, app.ExtensionSet)
if err != nil {
logrus.Errorf("Application model init create failure:%s", err.Error())
app.Logger.Error(util.Translation("(restart)Application model init create failure"), event.GetCallbackLoggerOption())
Expand Down
11 changes: 6 additions & 5 deletions worker/appm/conversion/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,18 @@ func RegistConversion(name string, fun Conversion) {
}

//InitAppService init a app service
func InitAppService(dryRun bool, dbmanager db.Manager, serviceID string, configs map[string]string, enableConversionList ...string) (*v1.AppService, error) {
func InitAppService(sharedStorageClass string, dryRun bool, dbmanager db.Manager, serviceID string, configs map[string]string, enableConversionList ...string) (*v1.AppService, error) {
if configs == nil {
configs = make(map[string]string)
}

appService := &v1.AppService{
AppServiceBase: v1.AppServiceBase{
ServiceID: serviceID,
ExtensionSet: configs,
GovernanceMode: model.GovernanceModeBuildInServiceMesh,
DryRun: dryRun,
ServiceID: serviceID,
ExtensionSet: configs,
GovernanceMode: model.GovernanceModeBuildInServiceMesh,
DryRun: dryRun,
SharedStorageClass: sharedStorageClass,
},
UpgradePatch: make(map[string][]byte, 2),
}
Expand Down
13 changes: 7 additions & 6 deletions worker/appm/types/v1/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,13 @@ type AppServiceBase struct {
IsWindowsService bool
CreaterID string
//depend all service id
Dependces []string
ExtensionSet map[string]string
GovernanceMode string
K8sApp string
K8sComponentName string
DryRun bool
Dependces []string
ExtensionSet map[string]string
GovernanceMode string
K8sApp string
K8sComponentName string
DryRun bool
SharedStorageClass string
}

//GetComponentDefinitionName get component definition name by component kind
Expand Down
22 changes: 16 additions & 6 deletions worker/appm/volume/other.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ package volume

import (
"fmt"

"github.com/goodrain/rainbond/db"
dbmodel "github.com/goodrain/rainbond/db/model"
"github.com/goodrain/rainbond/node/nodem/client"
workerutil "github.com/goodrain/rainbond/worker/util"
"github.com/sirupsen/logrus"
Expand All @@ -35,6 +35,11 @@ type OtherVolume struct {

// CreateVolume ceph rbd volume create volume
func (v *OtherVolume) CreateVolume(define *Define) error {
var shareFile bool
if v.svm.VolumeType == dbmodel.ShareFileVolumeType.String() {
v.svm.VolumeType = v.as.SharedStorageClass
shareFile = true
}
volumeType, err := db.GetManager().VolumeTypeDao().GetVolumeTypeByType(v.svm.VolumeType)
if err != nil {
logrus.Errorf("get volume type by type error: %s", err.Error())
Expand All @@ -44,6 +49,7 @@ func (v *OtherVolume) CreateVolume(define *Define) error {
logrus.Errorf("validate volume capacity[%v] error: %s", v.svm.VolumeCapacity, err.Error())
return err
}
v.svm.VolumeProviderName = volumeType.Provisioner
volumeMountName := fmt.Sprintf("manual%d", v.svm.ID)
volumeMountPath := v.svm.VolumePath
volumeReadOnly := v.svm.IsReadOnly
Expand All @@ -59,14 +65,18 @@ func (v *OtherVolume) CreateVolume(define *Define) error {
return "linux"
}(),
}
v.as.SetClaim(claim) // store claim to appService
statefulset := v.as.GetStatefulSet() //有状态组件
v.as.SetClaim(claim) // store claim to appService
vo := corev1.Volume{Name: volumeMountName}
vo.PersistentVolumeClaim = &corev1.PersistentVolumeClaimVolumeSource{ClaimName: claim.GetName(), ReadOnly: volumeReadOnly}
define.volumes = append(define.volumes, vo)
if statefulset != nil {
statefulset.Spec.VolumeClaimTemplates = append(statefulset.Spec.VolumeClaimTemplates, *claim)
logrus.Debugf("stateset.Spec.VolumeClaimTemplates: %+v", statefulset.Spec.VolumeClaimTemplates)
if shareFile {
v.as.SetClaimManually(claim)
} else {
statefulset := v.as.GetStatefulSet() //有状态组件
if statefulset != nil {
statefulset.Spec.VolumeClaimTemplates = append(statefulset.Spec.VolumeClaimTemplates, *claim)
logrus.Debugf("stateset.Spec.VolumeClaimTemplates: %+v", statefulset.Spec.VolumeClaimTemplates)
}
}

vm := corev1.VolumeMount{
Expand Down
5 changes: 5 additions & 0 deletions worker/appm/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func NewVolumeManager(as *v1.AppService,
}
if serviceMountR != nil {
volumeType = serviceMountR.VolumeType
as.SharedStorageClass = ""
}
if volumeType == "" {
logrus.Warn("unknown volume Type, can't create volume")
Expand All @@ -66,6 +67,10 @@ func NewVolumeManager(as *v1.AppService,
switch volumeType {
case dbmodel.ShareFileVolumeType.String():
v = new(ShareFileVolume)
css := as.SharedStorageClass
if css != "" {
v = new(OtherVolume)
}
case dbmodel.ConfigFileVolumeType.String():
v = &ConfigFileVolume{envs: envs, envVarSecrets: envVarSecrets}
case dbmodel.MemoryFSVolumeType.String():
Expand Down
14 changes: 7 additions & 7 deletions worker/handle/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (m *Manager) startExec(task *model.Task) error {
event.GetManager().ReleaseLogger(logger)
return nil
}
newAppService, err := conversion.InitAppService(false, m.dbmanager, body.ServiceID, body.Configs)
newAppService, err := conversion.InitAppService(m.cfg.SharedStorageClass, false, m.dbmanager, body.ServiceID, body.Configs)
if err != nil {
logrus.Errorf("component init create failure:%s", err.Error())
logger.Error("component init create failure", event.GetCallbackLoggerOption())
Expand Down Expand Up @@ -330,7 +330,7 @@ func (m *Manager) verticalScalingExec(task *model.Task) error {
appService.ContainerMemory = service.ContainerMemory
appService.ContainerGPU = service.ContainerGPU
appService.Logger = logger
newAppService, err := conversion.InitAppService(false, m.dbmanager, body.ServiceID, nil)
newAppService, err := conversion.InitAppService(m.cfg.SharedStorageClass, false, m.dbmanager, body.ServiceID, nil)
if err != nil {
logrus.Errorf("component init create failure:%s", err.Error())
logger.Error("component init create failure", event.GetCallbackLoggerOption())
Expand All @@ -357,7 +357,7 @@ func (m *Manager) rollingUpgradeExec(task *model.Task) error {
return fmt.Errorf("rolling_upgrade body convert to taskbody error")
}
logger := event.GetManager().GetLogger(body.EventID)
newAppService, err := conversion.InitAppService(body.DryRun, m.dbmanager, body.ServiceID, body.Configs)
newAppService, err := conversion.InitAppService(m.cfg.SharedStorageClass, body.DryRun, m.dbmanager, body.ServiceID, body.Configs)
if err != nil {
logrus.Errorf("component init create failure:%s", err.Error())
logger.Error("component init create failure", event.GetCallbackLoggerOption())
Expand Down Expand Up @@ -429,10 +429,10 @@ func (m *Manager) applyRuleExec(task *model.Task) error {
}
var newAppService *v1.AppService
if svc.Kind == dbmodel.ServiceKindThirdParty.String() {
newAppService, err = conversion.InitAppService(false, m.dbmanager, body.ServiceID, nil,
newAppService, err = conversion.InitAppService(m.cfg.SharedStorageClass, false, m.dbmanager, body.ServiceID, nil,
"ServiceSource", "TenantServiceBase", "TenantServiceRegist")
} else {
newAppService, err = conversion.InitAppService(false, m.dbmanager, body.ServiceID, nil)
newAppService, err = conversion.InitAppService(m.cfg.SharedStorageClass, false, m.dbmanager, body.ServiceID, nil)
}
if err != nil {
logrus.Errorf("component init create failure:%s", err.Error())
Expand Down Expand Up @@ -465,7 +465,7 @@ func (m *Manager) applyPluginConfig(task *model.Task) error {
logrus.Debugf("service is closed,no need handle")
return nil
}
newApp, err := conversion.InitAppService(false, m.dbmanager, body.ServiceID, nil, "ServiceSource", "TenantServiceBase", "TenantServicePlugin")
newApp, err := conversion.InitAppService(m.cfg.SharedStorageClass, false, m.dbmanager, body.ServiceID, nil, "ServiceSource", "TenantServiceBase", "TenantServicePlugin")
if err != nil {
logrus.Errorf("component apply plugin config controller failure:%s", err.Error())
return err
Expand Down Expand Up @@ -558,7 +558,7 @@ func (m *Manager) ExecRefreshHPATask(task *model.Task) error {
return nil
}

newAppService, err := conversion.InitAppService(false, m.dbmanager, body.ServiceID, nil)
newAppService, err := conversion.InitAppService(m.cfg.SharedStorageClass, false, m.dbmanager, body.ServiceID, nil)
if err != nil {
logrus.Errorf("component init create failure:%s", err.Error())
logger.Error("component init create failure", event.GetCallbackLoggerOption())
Expand Down

0 comments on commit c1b43e5

Please sign in to comment.