feat: v5.16.0 version (#1790)

* feat: support virtual machines (#1782)

* feat: support virtual machines

* perf: code make format

---------

Co-authored-by: 张启航 <zhangqh@goodrain.com>

* perf: solve go dependency problem

* fix: container disk information collection failed

* perf: some detailed optimizations in the virtual machine

* perf: adjust the maximum number of buildkit build retries

* perf: virtual machine function optimization

* perf: virtual machine image source detection

* fix: avoid using shared storage at the same address

* perf: local virtual machine image skips detection

* perf: optimize builder and runner image acquisition logic (#1789)

Co-authored-by: 张启航 <zhangqh@goodrain.com>

---------

Co-authored-by: 张启航 <zhangqh@goodrain.com>
This commit is contained in:
张启航 2023-11-30 13:56:09 +08:00 committed by GitHub
parent 6dd8ae6469
commit 469842f051
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
98 changed files with 2378 additions and 1244 deletions

View File

@ -143,6 +143,8 @@ type TenantInterfaceWithV1 interface {
VerticalService(w http.ResponseWriter, r *http.Request)
HorizontalService(w http.ResponseWriter, r *http.Request)
BuildService(w http.ResponseWriter, r *http.Request)
PauseService(w http.ResponseWriter, r *http.Request)
UNPauseService(w http.ResponseWriter, r *http.Request)
DeployService(w http.ResponseWriter, r *http.Request)
UpgradeService(w http.ResponseWriter, r *http.Request)
StatusService(w http.ResponseWriter, r *http.Request)

View File

@ -263,6 +263,8 @@ func (v2 *V2) serviceRouter() chi.Router {
// component build
r.Post("/build", middleware.WrapEL(controller.GetManager().BuildService, dbmodel.TargetTypeService, "build-service", dbmodel.ASYNEVENTTYPE))
// component start
r.Post("/pause", middleware.WrapEL(controller.GetManager().PauseService, dbmodel.TargetTypeService, "pause-service", dbmodel.ASYNEVENTTYPE))
r.Post("/un_pause", middleware.WrapEL(controller.GetManager().UNPauseService, dbmodel.TargetTypeService, "unpause-service", dbmodel.ASYNEVENTTYPE))
r.Post("/start", middleware.WrapEL(controller.GetManager().StartService, dbmodel.TargetTypeService, "start-service", dbmodel.ASYNEVENTTYPE))
// component stop event set to synchronous event, not wait.
r.Post("/stop", middleware.WrapEL(controller.GetManager().StopService, dbmodel.TargetTypeService, "stop-service", dbmodel.SYNEVENTTYPE))

View File

@ -24,7 +24,7 @@ import (
"github.com/go-chi/chi"
)
//Routes routes
// Routes routes
func Routes() chi.Router {
r := chi.NewRouter()
r.Get("/docker_console", controller.GetDockerConsole().Get)
@ -36,7 +36,7 @@ func Routes() chi.Router {
return r
}
//LogRoutes 日志下载路由
// LogRoutes 日志下载路由
func LogRoutes() chi.Router {
r := chi.NewRouter()
r.Get("/{gid}/{filename}", controller.GetLogFile().Get)
@ -44,7 +44,7 @@ func LogRoutes() chi.Router {
return r
}
//AppRoutes 应用导出包下载路由
// AppRoutes 应用导出包下载路由
func AppRoutes() chi.Router {
r := chi.NewRouter()
r.Get("/download/{format}/{fileName}", controller.GetManager().Download)
@ -53,7 +53,7 @@ func AppRoutes() chi.Router {
return r
}
//PackageBuildRoutes 本地文件上传路由
// PackageBuildRoutes 本地文件上传路由
func PackageBuildRoutes() chi.Router {
r := chi.NewRouter()
r.Post("/component/events/{eventID}", controller.GetManager().UploadPackage)

View File

@ -40,7 +40,7 @@ import (
"github.com/sirupsen/logrus"
)
//StartService StartService
// StartService StartService
// swagger:operation POST /v2/tenants/{tenant_name}/services/{service_alias}/start v2 startService
//
// 启动应用
@ -57,10 +57,11 @@ import (
// - application/xml
//
// responses:
// default:
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
//
// default:
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
func (t *TenantStruct) StartService(w http.ResponseWriter, r *http.Request) {
tenantID := r.Context().Value(ctxutil.ContextKey("tenant_id")).(string)
serviceID := r.Context().Value(ctxutil.ContextKey("service_id")).(string)
@ -88,7 +89,7 @@ func (t *TenantStruct) StartService(w http.ResponseWriter, r *http.Request) {
httputil.ReturnSuccess(r, w, sEvent)
}
//StopService StopService
// StopService StopService
// swagger:operation POST /v2/tenants/{tenant_name}/services/{service_alias}/stop v2 stopService
//
// 关闭应用
@ -105,10 +106,11 @@ func (t *TenantStruct) StartService(w http.ResponseWriter, r *http.Request) {
// - application/xml
//
// responses:
// default:
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
//
// default:
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
func (t *TenantStruct) StopService(w http.ResponseWriter, r *http.Request) {
tenantID := r.Context().Value(ctxutil.ContextKey("tenant_id")).(string)
serviceID := r.Context().Value(ctxutil.ContextKey("service_id")).(string)
@ -128,7 +130,7 @@ func (t *TenantStruct) StopService(w http.ResponseWriter, r *http.Request) {
httputil.ReturnSuccess(r, w, sEvent)
}
//RestartService RestartService
// RestartService RestartService
// swagger:operation POST /v2/tenants/{tenant_name}/services/{service_alias}/restart v2 restartService
//
// 重启应用
@ -145,10 +147,11 @@ func (t *TenantStruct) StopService(w http.ResponseWriter, r *http.Request) {
// - application/xml
//
// responses:
// default:
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
//
// default:
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
func (t *TenantStruct) RestartService(w http.ResponseWriter, r *http.Request) {
tenantID := r.Context().Value(ctxutil.ContextKey("tenant_id")).(string)
serviceID := r.Context().Value(ctxutil.ContextKey("service_id")).(string)
@ -180,7 +183,7 @@ func (t *TenantStruct) RestartService(w http.ResponseWriter, r *http.Request) {
httputil.ReturnSuccess(r, w, sEvent)
}
//VerticalService VerticalService
// VerticalService VerticalService
// swagger:operation PUT /v2/tenants/{tenant_name}/services/{service_alias}/vertical v2 verticalService
//
// 应用垂直伸缩
@ -197,10 +200,11 @@ func (t *TenantStruct) RestartService(w http.ResponseWriter, r *http.Request) {
// - application/xml
//
// responses:
// default:
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
//
// default:
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
func (t *TenantStruct) VerticalService(w http.ResponseWriter, r *http.Request) {
rules := validator.MapData{
"container_cpu": []string{"required"},
@ -249,7 +253,7 @@ func (t *TenantStruct) VerticalService(w http.ResponseWriter, r *http.Request) {
httputil.ReturnSuccess(r, w, sEvent)
}
//HorizontalService HorizontalService
// HorizontalService HorizontalService
// swagger:operation PUT /v2/tenants/{tenant_name}/services/{service_alias}/horizontal v2 horizontalService
//
// 应用水平伸缩
@ -266,10 +270,11 @@ func (t *TenantStruct) VerticalService(w http.ResponseWriter, r *http.Request) {
// - application/xml
//
// responses:
// default:
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
//
// default:
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
func (t *TenantStruct) HorizontalService(w http.ResponseWriter, r *http.Request) {
rules := validator.MapData{
"node_num": []string{"required"},
@ -305,7 +310,7 @@ func (t *TenantStruct) HorizontalService(w http.ResponseWriter, r *http.Request)
httputil.ReturnSuccess(r, w, sEvent)
}
//BuildService BuildService
// BuildService BuildService
// swagger:operation POST /v2/tenants/{tenant_name}/services/{service_alias}/build v2 serviceBuild
//
// 应用构建
@ -322,10 +327,11 @@ func (t *TenantStruct) HorizontalService(w http.ResponseWriter, r *http.Request)
// - application/xml
//
// responses:
// default:
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
//
// default:
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
func (t *TenantStruct) BuildService(w http.ResponseWriter, r *http.Request) {
var build api_model.ComponentBuildReq
ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &build, nil)
@ -356,7 +362,39 @@ func (t *TenantStruct) BuildService(w http.ResponseWriter, r *http.Request) {
httputil.ReturnSuccess(r, w, res)
}
//BuildList BuildList
// PauseService virtual machine paused
func (t *TenantStruct) PauseService(w http.ResponseWriter, r *http.Request) {
serviceID := r.Context().Value(ctxutil.ContextKey("service_id")).(string)
sEvent := r.Context().Value(ctxutil.ContextKey("event")).(*dbmodel.ServiceEvent)
if err := handler.GetServiceManager().PauseUNPauseService(serviceID, "pause"); err != nil {
httputil.ReturnError(r, w, 500, "get service info error.")
return
}
err := db.GetManager().ServiceEventDao().SetEventStatus(r.Context(), dbmodel.EventStatusSuccess)
if err != nil {
httputil.ReturnError(r, w, 500, fmt.Sprintf("pause update event failure: %v", err))
return
}
httputil.ReturnSuccess(r, w, sEvent)
}
// UNPauseService virtual machine unpaused
func (t *TenantStruct) UNPauseService(w http.ResponseWriter, r *http.Request) {
serviceID := r.Context().Value(ctxutil.ContextKey("service_id")).(string)
sEvent := r.Context().Value(ctxutil.ContextKey("event")).(*dbmodel.ServiceEvent)
if err := handler.GetServiceManager().PauseUNPauseService(serviceID, "unpause"); err != nil {
httputil.ReturnError(r, w, 500, "get service info error.")
return
}
err := db.GetManager().ServiceEventDao().SetEventStatus(r.Context(), dbmodel.EventStatusSuccess)
if err != nil {
httputil.ReturnError(r, w, 500, fmt.Sprintf("unpause update event failure: %v", err))
return
}
httputil.ReturnSuccess(r, w, sEvent)
}
// BuildList BuildList
func (t *TenantStruct) BuildList(w http.ResponseWriter, r *http.Request) {
serviceID := r.Context().Value(ctxutil.ContextKey("service_id")).(string)
@ -370,7 +408,7 @@ func (t *TenantStruct) BuildList(w http.ResponseWriter, r *http.Request) {
httputil.ReturnSuccess(r, w, resp)
}
//BuildVersionIsExist -
// BuildVersionIsExist -
func (t *TenantStruct) BuildVersionIsExist(w http.ResponseWriter, r *http.Request) {
statusMap := make(map[string]bool)
serviceID := r.Context().Value(ctxutil.ContextKey("service_id")).(string)
@ -389,7 +427,7 @@ func (t *TenantStruct) BuildVersionIsExist(w http.ResponseWriter, r *http.Reques
}
//DeleteBuildVersion -
// DeleteBuildVersion -
func (t *TenantStruct) DeleteBuildVersion(w http.ResponseWriter, r *http.Request) {
serviceID := r.Context().Value(ctxutil.ContextKey("service_id")).(string)
buildVersion := chi.URLParam(r, "build_version")
@ -430,7 +468,7 @@ func (t *TenantStruct) DeleteBuildVersion(w http.ResponseWriter, r *http.Request
}
//UpdateBuildVersion -
// UpdateBuildVersion -
func (t *TenantStruct) UpdateBuildVersion(w http.ResponseWriter, r *http.Request) {
var build api_model.UpdateBuildVersionReq
ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &build, nil)
@ -453,7 +491,7 @@ func (t *TenantStruct) UpdateBuildVersion(w http.ResponseWriter, r *http.Request
httputil.ReturnSuccess(r, w, nil)
}
//BuildVersionInfo -
// BuildVersionInfo -
func (t *TenantStruct) BuildVersionInfo(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "DELETE":
@ -466,7 +504,7 @@ func (t *TenantStruct) BuildVersionInfo(w http.ResponseWriter, r *http.Request)
}
//GetDeployVersion GetDeployVersion by service
// GetDeployVersion GetDeployVersion by service
func (t *TenantStruct) GetDeployVersion(w http.ResponseWriter, r *http.Request) {
service := r.Context().Value(ctxutil.ContextKey("service")).(*dbmodel.TenantServices)
version, err := db.GetManager().VersionInfoDao().GetVersionByDeployVersion(service.DeployVersion, service.ServiceID)
@ -481,7 +519,7 @@ func (t *TenantStruct) GetDeployVersion(w http.ResponseWriter, r *http.Request)
httputil.ReturnSuccess(r, w, version)
}
//GetManyDeployVersion GetDeployVersion by some service id
// GetManyDeployVersion GetDeployVersion by some service id
func (t *TenantStruct) GetManyDeployVersion(w http.ResponseWriter, r *http.Request) {
rules := validator.MapData{
"service_ids": []string{"required"},
@ -516,13 +554,13 @@ func (t *TenantStruct) GetManyDeployVersion(w http.ResponseWriter, r *http.Reque
httputil.ReturnSuccess(r, w, versionList)
}
//DeployService DeployService
// DeployService DeployService
func (t *TenantStruct) DeployService(w http.ResponseWriter, r *http.Request) {
logrus.Debugf("trans deploy service")
w.Write([]byte("deploy service"))
}
//UpgradeService UpgradeService
// UpgradeService UpgradeService
// swagger:operation POST /v2/tenants/{tenant_name}/services/{service_alias}/upgrade v2 upgradeService
//
// 升级应用
@ -539,10 +577,11 @@ func (t *TenantStruct) DeployService(w http.ResponseWriter, r *http.Request) {
// - application/xml
//
// responses:
// default:
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
//
// default:
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
func (t *TenantStruct) UpgradeService(w http.ResponseWriter, r *http.Request) {
var upgradeRequest api_model.ComponentUpgradeReq
ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &upgradeRequest, nil)
@ -574,7 +613,7 @@ func (t *TenantStruct) UpgradeService(w http.ResponseWriter, r *http.Request) {
httputil.ReturnSuccess(r, w, res)
}
//CheckCode CheckCode
// CheckCode CheckCode
// swagger:operation POST /v2/tenants/{tenant_name}/code-check v2 checkCode
//
// 应用代码检测
@ -591,10 +630,11 @@ func (t *TenantStruct) UpgradeService(w http.ResponseWriter, r *http.Request) {
// - application/xml
//
// responses:
// default:
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
//
// default:
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
func (t *TenantStruct) CheckCode(w http.ResponseWriter, r *http.Request) {
var ccs api_model.CheckCodeStruct
@ -614,7 +654,7 @@ func (t *TenantStruct) CheckCode(w http.ResponseWriter, r *http.Request) {
httputil.ReturnSuccess(r, w, nil)
}
//RollBack RollBack
// RollBack RollBack
// swagger:operation Post /v2/tenants/{tenant_name}/services/{service_alias}/rollback v2 rollback
//
// 应用版本回滚
@ -631,10 +671,11 @@ func (t *TenantStruct) CheckCode(w http.ResponseWriter, r *http.Request) {
// - application/xml
//
// responses:
// default:
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
//
// default:
// schema:
// "$ref": "#/responses/commandResponse"
// description: 统一返回格式
func (t *TenantStruct) RollBack(w http.ResponseWriter, r *http.Request) {
var rollbackRequest api_model.RollbackInfoRequestStruct
ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &rollbackRequest, nil)
@ -664,7 +705,7 @@ type limitMemory struct {
LimitMemory int `json:"limit_memory"`
}
//LimitTenantMemory -
// LimitTenantMemory -
func (t *TenantStruct) LimitTenantMemory(w http.ResponseWriter, r *http.Request) {
var lm limitMemory
body, err := ioutil.ReadAll(r.Body)
@ -693,7 +734,7 @@ func (t *TenantStruct) LimitTenantMemory(w http.ResponseWriter, r *http.Request)
}
//SourcesInfo -
// SourcesInfo -
type SourcesInfo struct {
TenantID string `json:"tenant_id"`
AvailableMemory int `json:"available_memory"`
@ -704,7 +745,7 @@ type SourcesInfo struct {
CPUUsed int `json:"cpu_used"`
}
//TenantResourcesStatus tenant resources status
// TenantResourcesStatus tenant resources status
func (t *TenantStruct) TenantResourcesStatus(w http.ResponseWriter, r *http.Request) {
tenantID := r.Context().Value(ctxutil.ContextKey("tenant_id")).(string)
@ -763,7 +804,7 @@ func (t *TenantStruct) TenantResourcesStatus(w http.ResponseWriter, r *http.Requ
}
}
//GetServiceDeployInfo get service deploy info
// GetServiceDeployInfo get service deploy info
func GetServiceDeployInfo(w http.ResponseWriter, r *http.Request) {
tenantID := r.Context().Value(ctxutil.ContextKey("tenant_id")).(string)
serviceID := r.Context().Value(ctxutil.ContextKey("service_id")).(string)

View File

@ -55,7 +55,7 @@ type GatewayAction struct {
kubeClient kubernetes.Interface
}
//CreateGatewayManager creates gateway manager.
// CreateGatewayManager creates gateway manager.
func CreateGatewayManager(dbmanager db.Manager, mqclient client.MQClient, etcdCli *clientv3.Client, gatewayClient *gateway.GatewayV1beta1Client, kubeClient kubernetes.Interface) *GatewayAction {
return &GatewayAction{
dbmanager: dbmanager,
@ -66,7 +66,7 @@ func CreateGatewayManager(dbmanager db.Manager, mqclient client.MQClient, etcdCl
}
}
//BatchGetGatewayHTTPRoute batch get gateway http route
// BatchGetGatewayHTTPRoute batch get gateway http route
func (g *GatewayAction) BatchGetGatewayHTTPRoute(namespace, appID string) ([]*apimodel.GatewayHTTPRouteConcise, error) {
var httpRoutes []v1beta1.HTTPRoute
if appID != "" {
@ -115,7 +115,7 @@ func (g *GatewayAction) BatchGetGatewayHTTPRoute(namespace, appID string) ([]*ap
return HTTPRouteConcise, nil
}
//AddGatewayCertificate create gateway certificate
// AddGatewayCertificate create gateway certificate
func (g *GatewayAction) AddGatewayCertificate(req *apimodel.GatewayCertificate) error {
_, err := g.kubeClient.CoreV1().Secrets(req.Namespace).Create(context.Background(), &corev1.Secret{
TypeMeta: metav1.TypeMeta{
@ -139,7 +139,7 @@ func (g *GatewayAction) AddGatewayCertificate(req *apimodel.GatewayCertificate)
return nil
}
//UpdateGatewayCertificate update gateway certificate
// UpdateGatewayCertificate update gateway certificate
func (g *GatewayAction) UpdateGatewayCertificate(req *apimodel.GatewayCertificate) error {
secret, err := g.kubeClient.CoreV1().Secrets(req.Namespace).Get(context.Background(), req.Name, metav1.GetOptions{})
if err != nil {
@ -180,7 +180,7 @@ func (g *GatewayAction) UpdateGatewayCertificate(req *apimodel.GatewayCertificat
return nil
}
//DeleteGatewayCertificate delete gateway certificate
// DeleteGatewayCertificate delete gateway certificate
func (g *GatewayAction) DeleteGatewayCertificate(name, namespace string) error {
err := g.kubeClient.CoreV1().Secrets(namespace).Delete(context.Background(), name, metav1.DeleteOptions{})
if err != nil {
@ -312,7 +312,7 @@ func handleGatewayRules(req *apimodel.GatewayHTTPRouteStruct) []v1beta1.HTTPRout
return rules
}
//AddGatewayHTTPRoute create gateway http route
// AddGatewayHTTPRoute create gateway http route
func (g *GatewayAction) AddGatewayHTTPRoute(req *apimodel.GatewayHTTPRouteStruct) (*model.K8sResource, error) {
gatewayNamespace := v1beta1.Namespace(req.GatewayNamespace)
var hosts []v1beta1.Hostname
@ -376,7 +376,7 @@ func (g *GatewayAction) AddGatewayHTTPRoute(req *apimodel.GatewayHTTPRouteStruct
return k8sresource[0], nil
}
//GetGatewayHTTPRoute get gateway http route
// GetGatewayHTTPRoute get gateway http route
func (g *GatewayAction) GetGatewayHTTPRoute(name, namespace string) (*apimodel.GatewayHTTPRouteStruct, error) {
var req apimodel.GatewayHTTPRouteStruct
route, err := g.gatewayClient.HTTPRoutes(namespace).Get(context.Background(), name, metav1.GetOptions{})
@ -548,7 +548,7 @@ func (g *GatewayAction) GetGatewayHTTPRoute(name, namespace string) (*apimodel.G
return &req, nil
}
//UpdateGatewayHTTPRoute update gateway http route
// UpdateGatewayHTTPRoute update gateway http route
func (g *GatewayAction) UpdateGatewayHTTPRoute(req *apimodel.GatewayHTTPRouteStruct) (*model.K8sResource, error) {
rules := handleGatewayRules(req)
gatewayNamespace := v1beta1.Namespace(req.GatewayNamespace)
@ -597,7 +597,7 @@ func (g *GatewayAction) UpdateGatewayHTTPRoute(req *apimodel.GatewayHTTPRouteStr
return &res, nil
}
//DeleteGatewayHTTPRoute delete gateway http route
// DeleteGatewayHTTPRoute delete gateway http route
func (g *GatewayAction) DeleteGatewayHTTPRoute(name, namespace, appID string) error {
err := g.gatewayClient.HTTPRoutes(namespace).Delete(context.Background(), name, metav1.DeleteOptions{})
if err != nil {
@ -1407,13 +1407,13 @@ func (g *GatewayAction) ListHTTPRulesByCertID(certID string) ([]*model.HTTPRule,
return db.GetManager().HTTPRuleDao().ListByCertID(certID)
}
//IPAndAvailablePort ip and advice available port
// IPAndAvailablePort ip and advice available port
type IPAndAvailablePort struct {
IP string `json:"ip"`
AvailablePort int `json:"available_port"`
}
//GetGatewayIPs get all gateway node ips
// GetGatewayIPs get all gateway node ips
func (g *GatewayAction) GetGatewayIPs() []IPAndAvailablePort {
defaultAvailablePort, _ := g.GetAvailablePort("0.0.0.0", false)
defaultIps := []IPAndAvailablePort{{

View File

@ -42,7 +42,7 @@ import (
v1 "github.com/goodrain/rainbond/worker/appm/types/v1"
)
//Backup GroupBackup
// Backup GroupBackup
// swagger:parameters groupBackup
type Backup struct {
// in: path
@ -69,19 +69,19 @@ type Backup struct {
}
}
//BackupHandle group app backup handle
// BackupHandle group app backup handle
type BackupHandle struct {
mqcli mqclient.MQClient
statusCli *client.AppRuntimeSyncClient
etcdCli *clientv3.Client
}
//CreateBackupHandle CreateBackupHandle
// CreateBackupHandle CreateBackupHandle
func CreateBackupHandle(MQClient mqclient.MQClient, statusCli *client.AppRuntimeSyncClient, etcdCli *clientv3.Client) *BackupHandle {
return &BackupHandle{mqcli: MQClient, statusCli: statusCli, etcdCli: etcdCli}
}
//NewBackup new backup task
// NewBackup new backup task
func (h *BackupHandle) NewBackup(b Backup) (*dbmodel.AppBackup, *util.APIHandleError) {
logger := event.GetManager().GetLogger(b.Body.EventID)
var appBackup = dbmodel.AppBackup{
@ -147,7 +147,7 @@ func (h *BackupHandle) NewBackup(b Backup) (*dbmodel.AppBackup, *util.APIHandleE
return &appBackup, nil
}
//GetBackup get one backup info
// GetBackup get one backup info
func (h *BackupHandle) GetBackup(backupID string) (*dbmodel.AppBackup, *util.APIHandleError) {
backup, err := db.GetManager().AppBackupDao().GetAppBackup(backupID)
if err != nil {
@ -156,7 +156,7 @@ func (h *BackupHandle) GetBackup(backupID string) (*dbmodel.AppBackup, *util.API
return backup, nil
}
//DeleteBackup delete backup
// DeleteBackup delete backup
func (h *BackupHandle) DeleteBackup(backupID string) error {
backup, err := db.GetManager().AppBackupDao().GetAppBackup(backupID)
if err != nil {
@ -182,7 +182,7 @@ func (h *BackupHandle) DeleteBackup(backupID string) error {
return tx.Commit().Error
}
//GetBackupByGroupID get some backup info by group id
// GetBackupByGroupID get some backup info by group id
func (h *BackupHandle) GetBackupByGroupID(groupID string) ([]*dbmodel.AppBackup, *util.APIHandleError) {
backups, err := db.GetManager().AppBackupDao().GetAppBackups(groupID)
if err != nil {
@ -198,7 +198,7 @@ type AppSnapshot struct {
PluginBuildVersions []*dbmodel.TenantPluginBuildVersion
}
//RegionServiceSnapshot RegionServiceSnapshot
// RegionServiceSnapshot RegionServiceSnapshot
type RegionServiceSnapshot struct {
ServiceID string
Service *dbmodel.TenantServices
@ -220,7 +220,7 @@ type RegionServiceSnapshot struct {
PluginStreamPorts []*dbmodel.TenantServicesStreamPluginPort
}
//snapshot
// snapshot
func (h *BackupHandle) snapshot(ids []string, sourceDir string, force bool) error {
var pluginIDs []string
var services []*RegionServiceSnapshot
@ -353,7 +353,7 @@ func (h *BackupHandle) snapshot(ids []string, sourceDir string, force bool) erro
return nil
}
//BackupRestore BackupRestore
// BackupRestore BackupRestore
type BackupRestore struct {
BackupID string `json:"backup_id"`
Body struct {
@ -375,7 +375,7 @@ type BackupRestore struct {
}
}
//RestoreResult RestoreResult
// RestoreResult RestoreResult
type RestoreResult struct {
Status string `json:"status"`
Message string `json:"message"`
@ -389,7 +389,7 @@ type RestoreResult struct {
CacheDir string `json:"cache_dir"`
}
//Info service cache info
// Info service cache info
type Info struct {
ServiceID string
ServiceAlias string
@ -397,8 +397,8 @@ type Info struct {
LBPorts map[int]int
}
//RestoreBackup restore a backup version
//all app could be closed before restore
// RestoreBackup restore a backup version
// all app could be closed before restore
func (h *BackupHandle) RestoreBackup(br BackupRestore) (*RestoreResult, *util.APIHandleError) {
logger := event.GetManager().GetLogger(br.Body.EventID)
backup, Aerr := h.GetBackup(br.BackupID)
@ -448,7 +448,7 @@ func (h *BackupHandle) RestoreBackup(br BackupRestore) (*RestoreResult, *util.AP
return rr, nil
}
//RestoreBackupResult RestoreBackupResult
// RestoreBackupResult RestoreBackupResult
func (h *BackupHandle) RestoreBackupResult(restoreID string) (*RestoreResult, *util.APIHandleError) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@ -474,7 +474,7 @@ func (h *BackupHandle) RestoreBackupResult(restoreID string) (*RestoreResult, *u
return &rr, nil
}
//BackupCopy BackupCopy
// BackupCopy BackupCopy
type BackupCopy struct {
Body struct {
EventID string `json:"event_id" validate:"event_id|required"`
@ -489,7 +489,7 @@ type BackupCopy struct {
}
}
//BackupCopy BackupCopy
// BackupCopy BackupCopy
func (h *BackupHandle) BackupCopy(b BackupCopy) (*dbmodel.AppBackup, *util.APIHandleError) {
var ab dbmodel.AppBackup
ab.BackupID = core_util.NewUUID()

View File

@ -34,6 +34,7 @@ import (
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"kubevirt.io/client-go/kubecli"
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
gateway "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned/typed/apis/v1beta1"
)
@ -50,6 +51,7 @@ func InitHandle(conf option.Config,
mapper meta.RESTMapper,
dynamicClient dynamic.Interface,
gatewayClient *gateway.GatewayV1beta1Client,
kubevirtCli kubecli.KubevirtClient,
) error {
mq := api_db.MQManager{
EtcdClientArgs: etcdClientArgs,
@ -68,7 +70,7 @@ func InitHandle(conf option.Config,
return err
}
dbmanager := db.GetManager()
defaultServieHandler = CreateManager(conf, mqClient, etcdcli, statusCli, prometheusCli, rainbondClient, kubeClient)
defaultServieHandler = CreateManager(conf, mqClient, etcdcli, statusCli, prometheusCli, rainbondClient, kubeClient, kubevirtCli, dbmanager)
defaultPluginHandler = CreatePluginManager(mqClient)
defaultAppHandler = CreateAppManager(mqClient)
defaultTenantHandler = CreateTenManager(mqClient, statusCli, &conf, kubeClient, prometheusCli, k8sClient)

View File

@ -31,19 +31,19 @@ import (
"github.com/sirupsen/logrus"
)
//NetRulesAction rules action struct
// NetRulesAction rules action struct
type NetRulesAction struct {
etcdCli *clientv3.Client
}
//CreateNetRulesManager get net rules manager
// CreateNetRulesManager get net rules manager
func CreateNetRulesManager(etcdCli *clientv3.Client) *NetRulesAction {
return &NetRulesAction{
etcdCli: etcdCli,
}
}
//CreateDownStreamNetRules CreateDownStreamNetRules
// CreateDownStreamNetRules CreateDownStreamNetRules
func (n *NetRulesAction) CreateDownStreamNetRules(
tenantID string,
rs *api_model.SetNetDownStreamRuleStruct) *util.APIHandleError {
@ -70,7 +70,7 @@ func (n *NetRulesAction) CreateDownStreamNetRules(
return nil
}
//GetDownStreamNetRule GetDownStreamNetRule
// GetDownStreamNetRule GetDownStreamNetRule
func (n *NetRulesAction) GetDownStreamNetRule(
tenantID,
serviceAlias,
@ -103,7 +103,7 @@ func (n *NetRulesAction) GetDownStreamNetRule(
return nil, nil
}
//UpdateDownStreamNetRule UpdateDownStreamNetRule
// UpdateDownStreamNetRule UpdateDownStreamNetRule
func (n *NetRulesAction) UpdateDownStreamNetRule(
tenantID string,
urs *api_model.UpdateNetDownStreamRuleStruct) *util.APIHandleError {

View File

@ -23,7 +23,6 @@ import (
"fmt"
"time"
"github.com/coreos/etcd/clientv3"
api_model "github.com/goodrain/rainbond/api/model"
"testing"

View File

@ -194,6 +194,12 @@ func (n *nodesHandle) GetNodeInfo(ctx context.Context, nodeName string) (res mod
break
}
}
if containerDiskCap == 0 {
containerDiskCap = diskCap
}
if containerDiskAvail == 0 {
containerDiskAvail = diskAvail
}
res.Resource.CapDisk = diskCap
res.Resource.ReqDisk = diskCap - diskAvail

View File

@ -34,7 +34,7 @@ type RegistryAuthSecretAction struct {
etcdCli *clientv3.Client
}
//CreateRegistryAuthSecretManager creates registry auth secret manager
// CreateRegistryAuthSecretManager creates registry auth secret manager
func CreateRegistryAuthSecretManager(dbmanager db.Manager, mqclient client.MQClient, etcdCli *clientv3.Client) *RegistryAuthSecretAction {
return &RegistryAuthSecretAction{
dbmanager: dbmanager,
@ -43,7 +43,7 @@ func CreateRegistryAuthSecretManager(dbmanager db.Manager, mqclient client.MQCli
}
}
//AddOrUpdateRegistryAuthSecret adds or updates registry auth secret
// AddOrUpdateRegistryAuthSecret adds or updates registry auth secret
func (g *RegistryAuthSecretAction) AddOrUpdateRegistryAuthSecret(req *apimodel.AddOrUpdateRegistryAuthSecretStruct) error {
body := make(map[string]interface{})
body["action"] = "apply"

View File

@ -24,6 +24,8 @@ import (
"fmt"
"github.com/goodrain/rainbond/util/constants"
"io"
v1 "kubevirt.io/api/core/v1"
"kubevirt.io/client-go/kubecli"
"net/http"
"os"
"strconv"
@ -64,7 +66,7 @@ import (
// ErrServiceNotClosed -
var ErrServiceNotClosed = errors.New("Service has not been closed")
//ServiceAction service act
// ServiceAction service act
type ServiceAction struct {
MQClient gclient.MQClient
EtcdCli *clientv3.Client
@ -73,6 +75,8 @@ type ServiceAction struct {
conf option.Config
rainbondClient versioned.Interface
kubeClient kubernetes.Interface
kubevirtClient kubecli.KubevirtClient
dbmanager db.Manager
}
type dCfg struct {
@ -83,14 +87,16 @@ type dCfg struct {
Password string `json:"password"`
}
//CreateManager create Manger
// CreateManager create Manger
func CreateManager(conf option.Config,
mqClient gclient.MQClient,
etcdCli *clientv3.Client,
statusCli *client.AppRuntimeSyncClient,
prometheusCli prometheus.Interface,
rainbondClient versioned.Interface,
kubeClient kubernetes.Interface) *ServiceAction {
kubeClient kubernetes.Interface,
kubevirtClient kubecli.KubevirtClient,
dbmanager db.Manager) *ServiceAction {
return &ServiceAction{
MQClient: mqClient,
EtcdCli: etcdCli,
@ -99,10 +105,12 @@ func CreateManager(conf option.Config,
prometheusCli: prometheusCli,
rainbondClient: rainbondClient,
kubeClient: kubeClient,
kubevirtClient: kubevirtClient,
dbmanager: dbmanager,
}
}
//ServiceBuild service build
// ServiceBuild service build
func (s *ServiceAction) ServiceBuild(tenantID, serviceID string, r *api_model.BuildServiceStruct) error {
eventID := r.Body.EventID
logger := event.GetManager().GetLogger(eventID)
@ -260,7 +268,7 @@ func (s *ServiceAction) isWindowsService(serviceID string) bool {
return true
}
//AddLabel add labels
// AddLabel add labels
func (s *ServiceAction) AddLabel(l *api_model.LabelsStruct, serviceID string) error {
tx := db.GetManager().Begin()
@ -289,7 +297,7 @@ func (s *ServiceAction) AddLabel(l *api_model.LabelsStruct, serviceID string) er
return nil
}
//UpdateLabel updates labels
// UpdateLabel updates labels
func (s *ServiceAction) UpdateLabel(l *api_model.LabelsStruct, serviceID string) error {
tx := db.GetManager().Begin()
defer func() {
@ -328,7 +336,7 @@ func (s *ServiceAction) UpdateLabel(l *api_model.LabelsStruct, serviceID string)
return nil
}
//DeleteLabel deletes label
// DeleteLabel deletes label
func (s *ServiceAction) DeleteLabel(l *api_model.LabelsStruct, serviceID string) error {
tx := db.GetManager().Begin()
defer func() {
@ -353,7 +361,7 @@ func (s *ServiceAction) DeleteLabel(l *api_model.LabelsStruct, serviceID string)
return nil
}
//StartStopService start service
// StartStopService start service
func (s *ServiceAction) StartStopService(sss *api_model.StartStopStruct) error {
services, err := db.GetManager().TenantServiceDao().GetServiceByID(sss.ServiceID)
if err != nil {
@ -379,7 +387,29 @@ func (s *ServiceAction) StartStopService(sss *api_model.StartStopStruct) error {
return nil
}
//ServiceVertical vertical service
// PauseUNPauseService -
func (s *ServiceAction) PauseUNPauseService(serviceID string, pauseORunpause string) error {
vmis, err := s.kubevirtClient.VirtualMachineInstance("").List(context.Background(), &metav1.ListOptions{LabelSelector: "service_id=" + serviceID})
if err != nil {
return err
}
if vmis.Items != nil && len(vmis.Items) > 0 {
vm := vmis.Items[0]
if pauseORunpause == "pause" {
err = s.kubevirtClient.VirtualMachineInstance(vm.Namespace).Pause(context.Background(), vm.Name, &v1.PauseOptions{})
} else if pauseORunpause == "unpause" {
err = s.kubevirtClient.VirtualMachineInstance(vm.Namespace).Unpause(context.Background(), vm.Name, &v1.UnpauseOptions{})
}
if err != nil {
return err
}
} else {
return fmt.Errorf("service id is %v vm is not exist", serviceID)
}
return nil
}
// ServiceVertical vertical service
func (s *ServiceAction) ServiceVertical(ctx context.Context, vs *model.VerticalScalingTaskBody) error {
service, err := db.GetManager().TenantServiceDao().GetServiceByID(vs.ServiceID)
if err != nil {
@ -435,7 +465,7 @@ func (s *ServiceAction) ServiceVertical(ctx context.Context, vs *model.VerticalS
return nil
}
//ServiceHorizontal Service Horizontal
// ServiceHorizontal Service Horizontal
func (s *ServiceAction) ServiceHorizontal(hs *model.HorizontalScalingTaskBody) error {
service, err := db.GetManager().TenantServiceDao().GetServiceByID(hs.ServiceID)
if err != nil {
@ -483,7 +513,7 @@ func (s *ServiceAction) ServiceHorizontal(hs *model.HorizontalScalingTaskBody) e
return nil
}
//ServiceUpgrade service upgrade
// ServiceUpgrade service upgrade
func (s *ServiceAction) ServiceUpgrade(ru *model.RollingUpgradeTaskBody) error {
services, err := db.GetManager().TenantServiceDao().GetServiceByID(ru.ServiceID)
if err != nil {
@ -524,7 +554,7 @@ func (s *ServiceAction) ServiceUpgrade(ru *model.RollingUpgradeTaskBody) error {
return nil
}
//ServiceCreate create service
// ServiceCreate create service
func (s *ServiceAction) ServiceCreate(sc *api_model.ServiceStruct) error {
jsonSC, err := ffjson.Marshal(sc)
if err != nil {
@ -880,7 +910,7 @@ func (s *ServiceAction) convertProbeModel(req *api_model.ServiceProbe, serviceID
}
}
//ServiceUpdate update service
// ServiceUpdate update service
func (s *ServiceAction) ServiceUpdate(sc map[string]interface{}) error {
ts, err := db.GetManager().TenantServiceDao().GetServiceByID(sc["service_id"].(string))
if err != nil {
@ -947,7 +977,7 @@ func (s *ServiceAction) ServiceUpdate(sc map[string]interface{}) error {
return nil
}
//LanguageSet language set
// LanguageSet language set
func (s *ServiceAction) LanguageSet(langS *api_model.LanguageSet) error {
logrus.Debugf("service id is %s, language is %s", langS.ServiceID, langS.Language)
services, err := db.GetManager().TenantServiceDao().GetServiceByID(langS.ServiceID)
@ -965,7 +995,7 @@ func (s *ServiceAction) LanguageSet(langS *api_model.LanguageSet) error {
return nil
}
//GetService get service(s)
// GetService get service(s)
func (s *ServiceAction) GetService(tenantID string) ([]*dbmodel.TenantServices, error) {
services, err := db.GetManager().TenantServiceDao().GetServicesAllInfoByTenantID(tenantID)
if err != nil {
@ -985,7 +1015,7 @@ func (s *ServiceAction) GetService(tenantID string) ([]*dbmodel.TenantServices,
return services, nil
}
//GetServicesByAppID get service(s) by appID
// GetServicesByAppID get service(s) by appID
func (s *ServiceAction) GetServicesByAppID(appID string, page, pageSize int) (*api_model.ListServiceResponse, error) {
var resp api_model.ListServiceResponse
services, total, err := db.GetManager().TenantServiceDao().GetServicesInfoByAppID(appID, page, pageSize)
@ -1015,7 +1045,7 @@ func (s *ServiceAction) GetServicesByAppID(appID string, page, pageSize int) (*a
return &resp, nil
}
//GetPagedTenantRes get pagedTenantServiceRes(s)
// GetPagedTenantRes get pagedTenantServiceRes(s)
func (s *ServiceAction) GetPagedTenantRes(offset, len int) ([]*api_model.TenantResource, int, error) {
allstatus := s.statusCli.GetAllStatus()
var serviceIDs []string
@ -1044,7 +1074,7 @@ func (s *ServiceAction) GetPagedTenantRes(offset, len int) ([]*api_model.TenantR
return result, count, nil
}
//GetTenantRes get pagedTenantServiceRes(s)
// GetTenantRes get pagedTenantServiceRes(s)
func (s *ServiceAction) GetTenantRes(uuid string) (*api_model.TenantResource, error) {
if logrus.IsLevelEnabled(logrus.DebugLevel) {
defer core_util.Elapsed("[ServiceAction] get tenant resource")()
@ -1125,7 +1155,7 @@ func (s *ServiceAction) GetTenantRes(uuid string) (*api_model.TenantResource, er
// return &res, nil
// }
//GetServicesDiskDeprecated get service disk
// GetServicesDiskDeprecated get service disk
//
// Deprecated
func GetServicesDiskDeprecated(ids []string, prometheusCli prometheus.Interface) map[string]float64 {
@ -1146,7 +1176,7 @@ func GetServicesDiskDeprecated(ids []string, prometheusCli prometheus.Interface)
return result
}
//CodeCheck code check
// CodeCheck code check
func (s *ServiceAction) CodeCheck(c *api_model.CheckCodeStruct) error {
err := s.MQClient.SendBuilderTopic(gclient.TaskStruct{
TaskType: "code_check",
@ -1160,7 +1190,7 @@ func (s *ServiceAction) CodeCheck(c *api_model.CheckCodeStruct) error {
return nil
}
//ServiceDepend service depend
// ServiceDepend service depend
func (s *ServiceAction) ServiceDepend(action string, ds *api_model.DependService) error {
switch action {
case "add":
@ -1188,7 +1218,7 @@ func (s *ServiceAction) ServiceDepend(action string, ds *api_model.DependService
return nil
}
//EnvAttr env attr
// EnvAttr env attr
func (s *ServiceAction) EnvAttr(action string, at *dbmodel.TenantServiceEnvVar) error {
switch action {
case "add":
@ -1296,7 +1326,7 @@ func (s *ServiceAction) SyncComponentPorts(tx *gorm.DB, app *dbmodel.Application
return db.GetManager().TenantServicesPortDaoTransactions(tx).CreateOrUpdatePortsInBatch(ports)
}
//PortVar port var
// PortVar port var
func (s *ServiceAction) PortVar(action, tenantID, serviceID string, vps *api_model.ServicePorts, oldPort int) error {
crt, err := db.GetManager().TenantServicePluginRelationDao().CheckSomeModelPluginByServiceID(
serviceID,
@ -1386,7 +1416,7 @@ func (s *ServiceAction) PortVar(action, tenantID, serviceID string, vps *api_mod
return nil
}
//PortOuter 端口对外服务操作
// PortOuter 端口对外服务操作
func (s *ServiceAction) PortOuter(tenantName, serviceID string, containerPort int,
servicePort *api_model.ServicePortInnerOrOuter) (*dbmodel.TenantServiceLBMappingPort, string, error) {
p, err := db.GetManager().TenantServicesPortDao().GetPort(serviceID, containerPort)
@ -1513,8 +1543,8 @@ func (s *ServiceAction) PortOuter(tenantName, serviceID string, containerPort in
return vsPort, p.Protocol, nil
}
//PortInner 端口对内服务操作
//TODO: send task to worker
// PortInner 端口对内服务操作
// TODO: send task to worker
func (s *ServiceAction) PortInner(tenantName, serviceID, operation string, port int) error {
p, err := db.GetManager().TenantServicesPortDao().GetPort(serviceID, port)
if err != nil {
@ -1629,7 +1659,7 @@ func (s *ServiceAction) PortInner(tenantName, serviceID, operation string, port
return nil
}
//VolumnVar var volumn
// VolumnVar var volumn
func (s *ServiceAction) VolumnVar(tsv *dbmodel.TenantServiceVolume, tenantID, fileContent, action string) *util.APIHandleError {
localPath := os.Getenv("LOCAL_DATA_PATH")
sharePath := os.Getenv("SHARE_DATA_PATH")
@ -1659,6 +1689,8 @@ func (s *ServiceAction) VolumnVar(tsv *dbmodel.TenantServiceVolume, tenantID, fi
return util.CreateAPIHandleError(400, fmt.Errorf("应用类型为'无状态'.不支持本地存储"))
}
tsv.HostPath = fmt.Sprintf("%s/tenant/%s/service/%s%s", localPath, tenantID, tsv.ServiceID, tsv.VolumePath)
case dbmodel.VMVolumeType.String():
tsv.HostPath = fmt.Sprintf("%s/tenant/%s/service/%s%s", sharePath, tenantID, tsv.ServiceID, tsv.VolumePath)
}
}
util.SetVolumeDefaultValue(tsv)
@ -1781,7 +1813,7 @@ func (s *ServiceAction) UpdVolume(sid string, req *api_model.UpdVolumeReq) error
return nil
}
//GetVolumes 获取应用全部存储
// GetVolumes 获取应用全部存储
func (s *ServiceAction) GetVolumes(serviceID string) ([]*api_model.VolumeWithStatusStruct, *util.APIHandleError) {
volumeWithStatusList := make([]*api_model.VolumeWithStatusStruct, 0)
vs, err := db.GetManager().TenantServiceVolumeDao().GetTenantServiceVolumesByServiceID(serviceID)
@ -1835,7 +1867,7 @@ func (s *ServiceAction) GetVolumes(serviceID string) ([]*api_model.VolumeWithSta
return volumeWithStatusList, nil
}
//VolumeDependency VolumeDependency
// VolumeDependency VolumeDependency
func (s *ServiceAction) VolumeDependency(tsr *dbmodel.TenantServiceMountRelation, action string) *util.APIHandleError {
switch action {
case "add":
@ -1870,7 +1902,7 @@ func (s *ServiceAction) VolumeDependency(tsr *dbmodel.TenantServiceMountRelation
return nil
}
//GetDepVolumes 获取依赖存储
// GetDepVolumes 获取依赖存储
func (s *ServiceAction) GetDepVolumes(serviceID string) ([]*dbmodel.TenantServiceMountRelation, *util.APIHandleError) {
dbManager := db.GetManager()
mounts, err := dbManager.TenantServiceMountRelationDao().GetTenantServiceMountRelationsByService(serviceID)
@ -1880,7 +1912,7 @@ func (s *ServiceAction) GetDepVolumes(serviceID string) ([]*dbmodel.TenantServic
return mounts, nil
}
//ServiceProbe ServiceProbe
// ServiceProbe ServiceProbe
func (s *ServiceAction) ServiceProbe(tsp *dbmodel.TenantServiceProbe, action string) error {
switch action {
case "add":
@ -1899,7 +1931,7 @@ func (s *ServiceAction) ServiceProbe(tsp *dbmodel.TenantServiceProbe, action str
return nil
}
//RollBack RollBack
// RollBack RollBack
func (s *ServiceAction) RollBack(rs *api_model.RollbackStruct) error {
service, err := db.GetManager().TenantServiceDao().GetServiceByID(rs.ServiceID)
if err != nil {
@ -1931,7 +1963,7 @@ func (s *ServiceAction) RollBack(rs *api_model.RollbackStruct) error {
return nil
}
//GetStatus GetStatus
// GetStatus GetStatus
func (s *ServiceAction) GetStatus(serviceID string) (*api_model.StatusList, error) {
services, errS := db.GetManager().TenantServiceDao().GetServiceByID(serviceID)
if errS != nil {
@ -1962,7 +1994,7 @@ func (s *ServiceAction) GetStatus(serviceID string) (*api_model.StatusList, erro
return sl, nil
}
//GetServicesStatus 获取一组应用状态,若 serviceIDs为空,获取租户所有应用状态
// GetServicesStatus 获取一组应用状态,若 serviceIDs为空,获取租户所有应用状态
func (s *ServiceAction) GetServicesStatus(tenantID string, serviceIDs []string) []map[string]interface{} {
if len(serviceIDs) == 0 {
services, _ := db.GetManager().TenantServiceDao().GetServicesByTenantID(tenantID)
@ -2009,7 +2041,7 @@ func (s *ServiceAction) GetEnterpriseServicesStatus(enterpriseID string) (map[st
return statusList, nil
}
//CreateTenant create tenant
// CreateTenant create tenant
func (s *ServiceAction) CreateTenant(t *dbmodel.Tenants) error {
tenant, _ := db.GetManager().TenantDao().GetTenantIDByName(t.Name)
if tenant != nil {
@ -2050,7 +2082,7 @@ func (s *ServiceAction) CreateTenant(t *dbmodel.Tenants) error {
})
}
//CreateTenandIDAndName create tenant_id and tenant_name
// CreateTenandIDAndName create tenant_id and tenant_name
func (s *ServiceAction) CreateTenandIDAndName(eid string) (string, string, error) {
id := uuid.NewV4().String()
uid := strings.Replace(id, "-", "", -1)
@ -2059,13 +2091,13 @@ func (s *ServiceAction) CreateTenandIDAndName(eid string) (string, string, error
return uid, name, nil
}
//K8sPodInfos -
// K8sPodInfos -
type K8sPodInfos struct {
NewPods []*K8sPodInfo `json:"new_pods"`
OldPods []*K8sPodInfo `json:"old_pods"`
}
//K8sPodInfo for api
// K8sPodInfo for api
type K8sPodInfo struct {
PodName string `json:"pod_name"`
PodIP string `json:"pod_ip"`
@ -2074,7 +2106,7 @@ type K8sPodInfo struct {
Container map[string]map[string]string `json:"container"`
}
//GetPods get pods
// GetPods get pods
func (s *ServiceAction) GetPods(serviceID string) (*K8sPodInfos, error) {
pods, err := s.statusCli.GetServicePods(serviceID)
if err != nil && !strings.Contains(err.Error(), server.ErrAppServiceNotFound.Error()) &&
@ -2123,7 +2155,7 @@ func (s *ServiceAction) GetPods(serviceID string) (*K8sPodInfos, error) {
}, nil
}
//GetMultiServicePods get pods
// GetMultiServicePods get pods
func (s *ServiceAction) GetMultiServicePods(serviceIDs []string) (*K8sPodInfos, error) {
mpods, err := s.statusCli.GetMultiServicePods(serviceIDs)
if err != nil && !strings.Contains(err.Error(), server.ErrAppServiceNotFound.Error()) &&
@ -2170,7 +2202,7 @@ func (s *ServiceAction) GetComponentPodNums(ctx context.Context, componentIDs []
return podNums, nil
}
//GetPodContainerMemory Use Prometheus to query memory resources
// GetPodContainerMemory Use Prometheus to query memory resources
func (s *ServiceAction) GetPodContainerMemory(podNames []string) (map[string]map[string]string, error) {
memoryUsageMap := make(map[string]map[string]string, 10)
queryName := strings.Join(podNames, "|")
@ -2195,7 +2227,7 @@ func (s *ServiceAction) GetPodContainerMemory(podNames []string) (map[string]map
return memoryUsageMap, nil
}
//TransServieToDelete trans service info to delete table
// TransServieToDelete trans service info to delete table
func (s *ServiceAction) TransServieToDelete(ctx context.Context, tenantID, serviceID string) error {
_, err := db.GetManager().TenantServiceDao().GetServiceByID(serviceID)
if err != nil && gorm.ErrRecordNotFound == err {
@ -2352,7 +2384,7 @@ func (s *ServiceAction) gcTaskBody(tenantID, serviceID string) (map[string]inter
}, nil
}
//GetServiceDeployInfo get service deploy info
// GetServiceDeployInfo get service deploy info
func (s *ServiceAction) GetServiceDeployInfo(tenantID, serviceID string) (*pb.DeployInfo, *util.APIHandleError) {
info, err := s.statusCli.GetServiceDeployInfo(serviceID)
if err != nil {
@ -2861,7 +2893,7 @@ func (s *ServiceAction) SyncComponentPlugins(tx *gorm.DB, app *dbmodel.Applicati
return db.GetManager().TenantPluginVersionConfigDaoTransactions(tx).CreateOrUpdatePluginVersionConfigsInBatch(pluginVersionConfigs)
}
//handlePluginMappingPort -
// handlePluginMappingPort -
func (s *ServiceAction) handlePluginMappingPort(tenantID, componentID, pluginModel string, ports []*api_model.BasePort) []*dbmodel.TenantServicesStreamPluginPort {
existPorts := make(map[int]struct{})
for _, port := range ports {
@ -3013,7 +3045,7 @@ func (s *ServiceAction) Log(w http.ResponseWriter, r *http.Request, component *d
return nil
}
//TransStatus trans service status
// TransStatus trans service status
func TransStatus(eStatus string) string {
switch eStatus {
case "starting":
@ -3040,6 +3072,8 @@ func TransStatus(eStatus string) string {
return "已部署"
case "succeeded":
return "已完成"
case "paused":
return "挂起"
}
return ""
}

View File

@ -31,13 +31,14 @@ import (
"github.com/jinzhu/gorm"
)
//ServiceHandler service handler
// ServiceHandler service handler
type ServiceHandler interface {
ServiceBuild(tenantID, serviceID string, r *api_model.BuildServiceStruct) error
AddLabel(l *api_model.LabelsStruct, serviceID string) error
DeleteLabel(l *api_model.LabelsStruct, serviceID string) error
UpdateLabel(l *api_model.LabelsStruct, serviceID string) error
StartStopService(s *api_model.StartStopStruct) error
PauseUNPauseService(serviceID string, pauseORunpause string) error
ServiceVertical(ctx context.Context, v *model.VerticalScalingTaskBody) error
ServiceHorizontal(h *model.HorizontalScalingTaskBody) error
ServiceUpgrade(r *model.RollingUpgradeTaskBody) error

View File

@ -33,7 +33,7 @@ import (
"github.com/sirupsen/logrus"
)
//OperationHandler operation handler
// OperationHandler operation handler
type OperationHandler struct {
mqCli gclient.MQClient
dryRun bool
@ -42,7 +42,7 @@ type OperationHandler struct {
end bool
}
//OperationResult batch operation result
// OperationResult batch operation result
type OperationResult struct {
ServiceID string `json:"service_id"`
Operation string `json:"operation"`
@ -52,14 +52,14 @@ type OperationResult struct {
DeployVersion string `json:"deploy_version"`
}
//CreateOperationHandler create operation handler
// CreateOperationHandler create operation handler
func CreateOperationHandler(mqCli gclient.MQClient) *OperationHandler {
return &OperationHandler{
mqCli: mqCli,
}
}
//SetHelmParameter pass the helm parameter
// SetHelmParameter pass the helm parameter
func (o *OperationHandler) SetHelmParameter(dryRun bool, helmChart *model.HelmChart, eventIDs []string, end bool) {
o.helmChart = helmChart
o.dryRun = dryRun
@ -67,8 +67,8 @@ func (o *OperationHandler) SetHelmParameter(dryRun bool, helmChart *model.HelmCh
o.end = end
}
//Build service build,will create new version
//if deploy version not define, will create by time
// Build service build,will create new version
// if deploy version not define, will create by time
func (o *OperationHandler) Build(batchOpReq model.ComponentOpReq) (*model.ComponentOpResult, error) {
res := batchOpReq.BatchOpFailureItem()
if err := o.build(batchOpReq); err != nil {
@ -148,13 +148,19 @@ func (o *OperationHandler) build(batchOpReq model.ComponentOpReq) error {
if err = o.exportHelmChart(buildReq, service); err != nil {
return err
}
case model.FromVMBuildKing:
version.ImageName = buildReq.ImageInfo.ImageURL
err = db.GetManager().VersionInfoDao().UpdateModel(&version)
if err := o.buildFromVM(buildReq, service); err != nil {
return err
}
default:
return errors.New("unsupported build kind: " + buildReq.Kind)
}
return nil
}
//Stop service stop
// Stop service stop
func (o *OperationHandler) Stop(batchOpReq model.ComponentOpReq) error {
service, err := db.GetManager().TenantServiceDao().GetServiceByID(batchOpReq.GetComponentID())
if err != nil {
@ -172,7 +178,7 @@ func (o *OperationHandler) Stop(batchOpReq model.ComponentOpReq) error {
return nil
}
//Start service start
// Start service start
func (o *OperationHandler) Start(batchOpReq model.ComponentOpReq) error {
service, err := db.GetManager().TenantServiceDao().GetServiceByID(batchOpReq.GetComponentID())
if err != nil {
@ -191,7 +197,7 @@ func (o *OperationHandler) Start(batchOpReq model.ComponentOpReq) error {
return nil
}
//Upgrade service upgrade
// Upgrade service upgrade
func (o *OperationHandler) Upgrade(batchOpReq model.ComponentOpReq) (*model.ComponentOpResult, error) {
res := batchOpReq.BatchOpFailureItem()
if err := o.upgrade(batchOpReq); err != nil {
@ -244,7 +250,7 @@ func (o *OperationHandler) upgrade(batchOpReq model.ComponentOpReq) error {
return nil
}
//RollBack service rollback
// RollBack service rollback
func (o *OperationHandler) RollBack(rollback model.RollbackInfoRequestStruct) (re OperationResult) {
re.Operation = "rollback"
re.ServiceID = rollback.ServiceID
@ -403,3 +409,24 @@ func (o *OperationHandler) isWindowsService(serviceID string) bool {
}
return true
}
func (o *OperationHandler) buildFromVM(r *model.ComponentBuildReq, service *dbmodel.TenantServices) error {
if logrus.IsLevelEnabled(logrus.DebugLevel) {
util.Elapsed(fmt.Sprintf("[buildFromImage] build component(%s)", r.GetComponentID()))()
}
if r.ImageInfo.ImageURL == "" || r.DeployVersion == "" {
return fmt.Errorf("build from image failure, args error")
}
body := make(map[string]interface{})
body["arch"] = r.Arch
body["vm_image_source"] = r.ImageInfo.VMImageSource
body["service_id"] = r.ServiceID
body["deploy_version"] = r.DeployVersion
body["tenant_id"] = service.TenantID
body["configs"] = r.Configs
body["action"] = r.Action
body["event_id"] = r.EventID
body["image"] = r.ImageInfo.ImageURL
return o.sendBuildTopic(service.ServiceID, "build_from_vm", body, r.Arch)
}

View File

@ -33,20 +33,20 @@ import (
"github.com/twinj/uuid"
)
//PluginShareHandle plugin share
// PluginShareHandle plugin share
type PluginShareHandle struct {
MQClient client.MQClient
EtcdCli *clientv3.Client
}
//PluginResult share plugin api return
// PluginResult share plugin api return
type PluginResult struct {
EventID string `json:"event_id"`
ShareID string `json:"share_id"`
ImageName string `json:"image_name"`
}
//PluginShare PluginShare
// PluginShare PluginShare
type PluginShare struct {
// in: path
// required: true
@ -74,7 +74,7 @@ type PluginShare struct {
}
}
//Share share app
// Share share app
func (s *PluginShareHandle) Share(ss PluginShare) (*PluginResult, *util.APIHandleError) {
_, err := db.GetManager().TenantPluginDao().GetPluginByID(ss.PluginID, ss.TenantID)
if err != nil {
@ -111,7 +111,7 @@ func (s *PluginShareHandle) Share(ss PluginShare) (*PluginResult, *util.APIHandl
return &PluginResult{EventID: ss.Body.EventID, ShareID: shareID, ImageName: shareImageName}, nil
}
//ShareResult 分享应用结果查询
// ShareResult 分享应用结果查询
func (s *PluginShareHandle) ShareResult(shareID string) (i exector.ShareStatus, e *util.APIHandleError) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

View File

@ -38,13 +38,13 @@ import (
"github.com/sirupsen/logrus"
)
//ServiceShareHandle service share
// ServiceShareHandle service share
type ServiceShareHandle struct {
MQClient client.MQClient
EtcdCli *clientv3.Client
}
//APIResult 分享接口返回
// APIResult 分享接口返回
type APIResult struct {
EventID string `json:"event_id"`
ShareID string `json:"share_id"`
@ -52,7 +52,7 @@ type APIResult struct {
SlugPath string `json:"slug_path,omitempty"`
}
//Share 分享应用
// Share 分享应用
func (s *ServiceShareHandle) Share(serviceID string, ss api_model.ServiceShare) (*APIResult, *util.APIHandleError) {
service, err := db.GetManager().TenantServiceDao().GetServiceByID(serviceID)
if err != nil {
@ -121,7 +121,7 @@ func (s *ServiceShareHandle) Share(serviceID string, ss api_model.ServiceShare)
return &APIResult{EventID: ss.Body.EventID, ShareID: shareID, ImageName: shareImageName, SlugPath: slugPath}, nil
}
//ShareResult 分享应用结果查询
// ShareResult 分享应用结果查询
func (s *ServiceShareHandle) ShareResult(shareID string) (i exector.ShareStatus, e *util.APIHandleError) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

View File

@ -1099,7 +1099,7 @@ type ServiceCheckStruct struct {
//检测来源类型
// in: body
// required: true
SourceType string `json:"source_type" validate:"source_type|required|in:docker-run,docker-compose,sourcecode,third-party-service,package_build"`
SourceType string `json:"source_type" validate:"source_type|required|in:docker-run,vm-run,docker-compose,sourcecode,third-party-service,package_build"`
CheckOS string `json:"check_os"`
// 检测来源定义,
@ -1671,10 +1671,11 @@ type BuildImageInfo struct {
// 镜像地址
// in: body
// required: false
ImageURL string `json:"image_url" validate:"image_url"`
User string `json:"user" validate:"user"`
Password string `json:"password" validate:"password"`
Cmd string `json:"cmd"`
ImageURL string `json:"image_url" validate:"image_url"`
User string `json:"user" validate:"user"`
Password string `json:"password" validate:"password"`
Cmd string `json:"cmd"`
VMImageSource string `json:"vm_image_source"`
}
// BuildCodeInfo -
@ -1714,6 +1715,9 @@ type BuildSlugInfo struct {
// FromImageBuildKing build from image
var FromImageBuildKing = "build_from_image"
// FromVMBuildKing build from vm
var FromVMBuildKing = "build_from_vm"
// FromCodeBuildKing build from code
var FromCodeBuildKing = "build_from_source_code"

View File

@ -22,6 +22,7 @@ import (
"context"
"crypto/tls"
"crypto/x509"
"github.com/coreos/etcd/clientv3"
"io/ioutil"
"log"
"net/http"
@ -36,7 +37,6 @@ import (
"github.com/goodrain/rainbond/util"
"github.com/coreos/etcd/clientv3"
"github.com/goodrain/rainbond/cmd/api/option"
"github.com/goodrain/rainbond/api/api_routers/doc"

View File

@ -50,6 +50,7 @@ func init() {
buildcreaters[code.Golang] = slugBuilder
buildcreaters[code.OSS] = slugBuilder
buildcreaters[code.NodeJSDockerfile] = customDockerBuilder
buildcreaters[code.VMDockerfile] = customDockerBuilder
}
var buildcreaters map[code.Lang]CreaterBuild
@ -112,6 +113,7 @@ type Request struct {
HostAlias []HostAlias
Ctx context.Context
Arch string
BRVersion string
}
// HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the

View File

@ -138,7 +138,7 @@ func (s *slugBuild) buildRunnerImage(slugPackage string) (string, error) {
return "", fmt.Errorf("write default runtime dockerfile error:%s", err.Error())
}
//build runtime image
if err := s.re.ImageClient.ImagesPullAndPush(builder.RUNNERIMAGENAME, builder.ONLINERUNNERIMAGENAME, "", "", s.re.Logger); err != nil {
if err := s.re.ImageClient.ImagesPullAndPush(builder.RUNNERIMAGENAME, builder.GetRunnerImage(s.re.BRVersion), "", "", s.re.Logger); err != nil {
return "", fmt.Errorf("pull image %s: %v", builder.RUNNERIMAGENAME, err)
}
logrus.Infof("pull image %s successfully.", builder.RUNNERIMAGENAME)
@ -472,7 +472,7 @@ func (s *slugBuild) runBuildJob(re *Request) error {
defer cancel()
// Get builder image at build time
if err := s.re.ImageClient.ImagesPullAndPush(builder.BUILDERIMAGENAME, builder.ONLINEBUILDERIMAGENAME, "", "", re.Logger); err != nil {
if err := s.re.ImageClient.ImagesPullAndPush(builder.BUILDERIMAGENAME, builder.GetBuilderImage(s.re.BRVersion), "", "", re.Logger); err != nil {
return err
}

View File

@ -32,13 +32,14 @@ import (
"github.com/tidwall/gjson"
)
//ImageBuildItem ImageBuildItem
// ImageBuildItem ImageBuildItem
type ImageBuildItem struct {
Namespace string `json:"namespace"`
TenantName string `json:"tenant_name"`
ServiceAlias string `json:"service_alias"`
Image string `json:"image"`
DestImage string `json:"dest_image"`
VMImageSource string `json:"vm_image_source"`
Logger event.Logger `json:"logger"`
EventID string `json:"event_id"`
ImageClient sources.ImageClient
@ -52,7 +53,7 @@ type ImageBuildItem struct {
FailCause string
}
//NewImageBuildItem 创建实体
// NewImageBuildItem 创建实体
func NewImageBuildItem(in []byte) *ImageBuildItem {
eventID := gjson.GetBytes(in, "event_id").String()
logger := event.GetManager().GetLogger(eventID)
@ -72,7 +73,7 @@ func NewImageBuildItem(in []byte) *ImageBuildItem {
}
}
//Run Run
// Run Run
func (i *ImageBuildItem) Run(timeout time.Duration) error {
user, pass := builder.GetImageUserInfoV2(i.Image, i.HubUser, i.HubPassword)
_, err := i.ImageClient.ImagePull(i.Image, user, pass, i.Logger, 30)
@ -119,7 +120,7 @@ func (i *ImageBuildItem) Run(timeout time.Duration) error {
return nil
}
//StorageVersionInfo 存储version信息
// StorageVersionInfo 存储version信息
func (i *ImageBuildItem) StorageVersionInfo(imageURL string) error {
version, err := db.GetManager().VersionInfoDao().GetVersionByDeployVersion(i.DeployVersion, i.ServiceID)
if err != nil {
@ -137,7 +138,7 @@ func (i *ImageBuildItem) StorageVersionInfo(imageURL string) error {
return nil
}
//UpdateVersionInfo 更新任务执行结果
// UpdateVersionInfo 更新任务执行结果
func (i *ImageBuildItem) UpdateVersionInfo(status string) error {
version, err := db.GetManager().VersionInfoDao().GetVersionByEventID(i.EventID)
if err != nil {

View File

@ -79,6 +79,7 @@ type SourceCodeBuildItem struct {
Configs map[string]gjson.Result `json:"configs"`
Ctx context.Context
FailCause string
BRVersion string
}
// Commit code Commit
@ -365,6 +366,7 @@ func (i *SourceCodeBuildItem) codeBuild() (*build.Response, error) {
CacheMode: i.CacheMode,
CachePath: i.CachePath,
Arch: i.Arch,
BRVersion: i.BRVersion,
}
res, err := codeBuild.Build(buildReq)
return res, err

View File

@ -0,0 +1,170 @@
package exector
import (
"fmt"
humanize "github.com/dustin/go-humanize"
"github.com/goodrain/rainbond/builder"
"github.com/goodrain/rainbond/builder/sources"
"github.com/goodrain/rainbond/event"
"github.com/goodrain/rainbond/util"
"github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
"io"
"io/ioutil"
"k8s.io/client-go/kubernetes"
"net/http"
"os"
"path"
"path/filepath"
"strings"
)
var vmDockerfileTmpl = `
FROM scratch
ADD ${VM_PATH} /disk/
`
// VMBuildItem -
type VMBuildItem struct {
Logger event.Logger `json:"logger"`
Arch string `json:"arch"`
VMImageSource string `json:"vm_image_source"`
ImageClient sources.ImageClient
Configs map[string]gjson.Result `json:"configs"`
ServiceID string `json:"service_id"`
DeployVersion string `json:"deploy_version"`
Image string `json:"image"`
BuildKitImage string
BuildKitArgs []string
BuildKitCache bool
Action string `json:"action"`
EventID string `json:"event_id"`
TenantID string `json:"tenant_id"`
kubeClient kubernetes.Interface
}
// NewVMBuildItem -
func NewVMBuildItem(in []byte) *VMBuildItem {
eventID := gjson.GetBytes(in, "event_id").String()
logger := event.GetManager().GetLogger(eventID)
return &VMBuildItem{
Logger: logger,
Arch: gjson.GetBytes(in, "arch").String(),
VMImageSource: gjson.GetBytes(in, "vm_image_source").String(),
ServiceID: gjson.GetBytes(in, "service_id").String(),
DeployVersion: gjson.GetBytes(in, "deploy_version").String(),
TenantID: gjson.GetBytes(in, "tenant_id").String(),
Configs: gjson.GetBytes(in, "configs").Map(),
Action: gjson.GetBytes(in, "action").String(),
EventID: gjson.GetBytes(in, "event_id").String(),
Image: gjson.GetBytes(in, "image").String(),
}
}
func (v *VMBuildItem) vmBuild(sourcePath string) error {
envs := make(map[string]string)
fileInfoList, err := ioutil.ReadDir(sourcePath)
if err != nil {
return err
}
if len(fileInfoList) != 1 {
return fmt.Errorf("%v file len is not 1", sourcePath)
}
envs["VM_PATH"] = path.Join("./", fileInfoList[0].Name())
dockerfile := util.ParseVariable(vmDockerfileTmpl, envs)
dfpath := path.Join(sourcePath, "Dockerfile")
logrus.Debugf("dest: %s; write dockerfile: %s", dfpath, dockerfile)
err = ioutil.WriteFile(dfpath, []byte(dockerfile), 0755)
if err != nil {
return err
}
imageName := fmt.Sprintf("%v/%v", builder.REGISTRYDOMAIN, v.Image)
err = sources.ImageBuild(v.Arch, sourcePath, "", "", "rbd-system", v.ServiceID, v.DeployVersion, v.Logger, "vm-build", imageName, v.BuildKitImage, v.BuildKitArgs, v.BuildKitCache, v.kubeClient)
if err != nil {
v.Logger.Error(fmt.Sprintf("build image %s failure, find log in rbd-chaos", imageName), map[string]string{"step": "builder-exector", "status": "failure"})
logrus.Errorf("build image error: %s", err.Error())
return err
}
v.Logger.Info("push image to push local image registry success", map[string]string{"step": "builder-exector"})
if err := v.ImageClient.ImageRemove(imageName); err != nil {
logrus.Errorf("remove image %s failure %s", imageName, err.Error())
}
return nil
}
// RunVMBuild -
func (v *VMBuildItem) RunVMBuild() error {
if strings.HasPrefix(v.VMImageSource, "/grdata") {
defer os.RemoveAll(v.VMImageSource)
return v.vmBuild(v.VMImageSource)
}
vmImageSource := fmt.Sprintf("/grdata/package_build/temp/events/%v", v.ServiceID)
err := downloadFile(vmImageSource, v.VMImageSource, v.Logger)
if err != nil {
return err
}
defer os.RemoveAll(vmImageSource)
return v.vmBuild(vmImageSource)
}
func downloadFile(downPath, url string, Logger event.Logger) error {
rsp, err := http.Get(url)
defer func() {
_ = rsp.Body.Close()
}()
baseURL := filepath.Base(url)
fileName := strings.Split(baseURL, "?")[0]
downPath = path.Join(downPath, fileName)
dir := filepath.Dir(downPath)
// 递归创建目录
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return err
}
f, err := os.OpenFile(downPath, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
if err != nil {
return err
}
defer func() {
_ = f.Close()
}()
myDownloader := &MyDownloader{
Reader: rsp.Body,
Total: rsp.ContentLength,
Logger: Logger,
Pace: 10,
}
Logger.Info(fmt.Sprintf("begin download vm image %v, image name is %v", url, fileName), map[string]string{"step": "builder-exector"})
Logger.Info(fmt.Sprintf("image size is %v, downloading will take some time, please be patient.", humanize.Bytes(uint64(rsp.ContentLength))), map[string]string{"step": "builder-exector"})
_, err = io.Copy(f, myDownloader)
if err != nil {
downError := fmt.Sprintf("download vm image %v failre: %v", url, err.Error())
Logger.Error(downError, map[string]string{"step": "builder-exector", "status": "failure"})
}
return err
}
type MyDownloader struct {
io.Reader // 读取器
Total int64 // 总大小
Current int64 // 当前大小
Logger event.Logger
Pace float64
}
func (d *MyDownloader) Read(p []byte) (n int, err error) {
n, err = d.Reader.Read(p)
d.Current += int64(n)
if float64(d.Current*10000/d.Total)/100 == d.Pace {
downLog := fmt.Sprintf("virtual machine image is being downloaded.current download progress is:%.2f%%", float64(d.Current*10000/d.Total)/100)
d.Logger.Info(downLog, map[string]string{"step": "builder-exector"})
d.Pace += 10
}
if float64(d.Current*10000/d.Total)/100 == 100 {
d.Logger.Info("download vm image success", map[string]string{"step": "builder-exector"})
}
return
}

View File

@ -245,6 +245,8 @@ func (e *exectorManager) RunTask(task *pb.TaskMessage) {
switch task.TaskType {
case "build_from_image":
go e.runTask(e.buildFromImage, task, false)
case "build_from_vm":
go e.runTask(e.buildFromVM, task, false)
case "build_from_source_code":
go e.runTask(e.buildFromSourceCode, task, true)
case "build_from_market_slug":
@ -360,6 +362,7 @@ func (e *exectorManager) buildFromSourceCode(task *pb.TaskMessage) {
i.GRDataPVCName = e.cfg.GRDataPVCName
i.CacheMode = e.cfg.CacheMode
i.CachePath = e.cfg.CachePath
i.BRVersion = e.cfg.BRVersion
i.Logger.Info("Build app version from source code start", map[string]string{"step": "builder-exector", "status": "starting"})
start := time.Now()
defer event.GetManager().ReleaseLogger(i.Logger)
@ -406,6 +409,45 @@ func (e *exectorManager) buildFromSourceCode(task *pb.TaskMessage) {
}
}
// buildFromVM build app from vm
func (e *exectorManager) buildFromVM(task *pb.TaskMessage) {
v := NewVMBuildItem(task.TaskBody)
v.ImageClient = e.imageClient
v.BuildKitImage = e.BuildKitImage
v.BuildKitArgs = e.BuildKitArgs
v.BuildKitCache = e.BuildKitCache
v.kubeClient = e.KubeClient
v.Logger.Info("Start with the vm build application task", map[string]string{"step": "builder-exector", "status": "starting"})
defer event.GetManager().ReleaseLogger(v.Logger)
defer func() {
if r := recover(); r != nil {
debug.PrintStack()
v.Logger.Error("Back end service drift. Please check the rbd-chaos log", map[string]string{"step": "builder-exector", "status": "starting"})
}
}()
start := time.Now()
defer func() {
logrus.Debugf("complete build from source code, consuming time %s", time.Since(start).String())
}()
if v.VMImageSource != "" {
err := v.RunVMBuild()
if err != nil {
logrus.Errorf("failure")
}
}
var configs = make(map[string]string, len(v.Configs))
for k, u := range v.Configs {
configs[k] = u.String()
}
if err := e.UpdateDeployVersion(v.ServiceID, v.DeployVersion); err != nil {
logrus.Errorf("Update app service deploy version failure %s, service %s do not auto upgrade", err.Error(), v.ServiceID)
}
err := e.sendAction(v.TenantID, v.ServiceID, v.EventID, v.DeployVersion, v.Action, configs, v.Logger)
if err != nil {
v.Logger.Error("Send upgrade action failed", map[string]string{"step": "callback", "status": "failure"})
}
}
// buildFromMarketSlug build app from market slug
func (e *exectorManager) buildFromMarketSlug(task *pb.TaskMessage) {
eventID := gjson.GetBytes(task.TaskBody, "event_id").String()

View File

@ -25,7 +25,6 @@ import (
"testing"
"time"
"github.com/coreos/etcd/clientv3"
"github.com/docker/docker/client"
"k8s.io/client-go/kubernetes"

View File

@ -44,7 +44,7 @@ import (
"github.com/tidwall/gjson"
)
//BackupAPPRestore restrore the group app backup
// BackupAPPRestore restrore the group app backup
type BackupAPPRestore struct {
//full-online,full-offline
EventID string
@ -72,7 +72,7 @@ type BackupAPPRestore struct {
} `json:"s3_config"`
}
//Info service cache info
// Info service cache info
type Info struct {
ServiceID string
ServiceAlias string
@ -84,7 +84,7 @@ func init() {
RegisterWorker("backup_apps_restore", BackupAPPRestoreCreater)
}
//BackupAPPRestoreCreater create
// BackupAPPRestoreCreater create
func BackupAPPRestoreCreater(in []byte, m *exectorManager) (TaskWorker, error) {
eventID := gjson.GetBytes(in, "event_id").String()
logger := event.GetManager().GetLogger(eventID)
@ -102,7 +102,7 @@ func BackupAPPRestoreCreater(in []byte, m *exectorManager) (TaskWorker, error) {
return backupRestore, nil
}
//Run Run
// Run Run
func (b *BackupAPPRestore) Run(timeout time.Duration) error {
//download or copy backup data
backup, err := db.GetManager().AppBackupDao().GetAppBackup(b.BackupID)
@ -410,7 +410,7 @@ func (b *BackupAPPRestore) downloadImage(backup *dbmodel.AppBackup, app *RegionS
return nil
}
//if restore error, will clear
// if restore error, will clear
func (b *BackupAPPRestore) clear() {
//clear db
manager := db.GetManager()
@ -769,22 +769,22 @@ func (b *BackupAPPRestore) downloadFromS3(sourceDir string) error {
return nil
}
//Stop stop
// Stop stop
func (b *BackupAPPRestore) Stop() error {
return nil
}
//Name return worker name
// Name return worker name
func (b *BackupAPPRestore) Name() string {
return "backup_apps_restore"
}
//GetLogger GetLogger
// GetLogger GetLogger
func (b *BackupAPPRestore) GetLogger() event.Logger {
return b.Logger
}
//ErrorCallBack if run error will callback
// ErrorCallBack if run error will callback
func (b *BackupAPPRestore) ErrorCallBack(err error) {
if err != nil {
logrus.Errorf("restore backup group app failure %s", err)
@ -794,7 +794,7 @@ func (b *BackupAPPRestore) ErrorCallBack(err error) {
}
}
//RestoreResult RestoreResult
// RestoreResult RestoreResult
type RestoreResult struct {
Status string `json:"status"`
Message string `json:"message"`

View File

@ -32,7 +32,7 @@ import (
"github.com/sirupsen/logrus"
)
//ServiceCheckInput 任务输入数据
// ServiceCheckInput 任务输入数据
type ServiceCheckInput struct {
CheckUUID string `json:"uuid"`
//检测来源类型
@ -49,7 +49,7 @@ type ServiceCheckInput struct {
EventID string `json:"event_id"`
}
//ServiceCheckResult 应用检测结果
// ServiceCheckResult 应用检测结果
type ServiceCheckResult struct {
//检测状态 Success Failure
CheckStatus string `json:"check_status"`
@ -57,7 +57,7 @@ type ServiceCheckResult struct {
ServiceInfo []parser.ServiceInfo `json:"service_info"`
}
//CreateResult 创建检测结果
// CreateResult 创建检测结果
func CreateResult(ErrorInfos parser.ParseErrorList, ServiceInfo []parser.ServiceInfo) (ServiceCheckResult, error) {
var sr ServiceCheckResult
if ErrorInfos != nil && ErrorInfos.IsFatalError() {
@ -77,7 +77,7 @@ func CreateResult(ErrorInfos parser.ParseErrorList, ServiceInfo []parser.Service
return sr, nil
}
//serviceCheck 应用创建源检测
// serviceCheck 应用创建源检测
func (e *exectorManager) serviceCheck(task *pb.TaskMessage) {
//step1 判断应用源类型
//step2 获取应用源介质镜像Or源码
@ -121,6 +121,8 @@ func (e *exectorManager) serviceCheck(task *pb.TaskMessage) {
pr = parser.CreateThirdPartyServiceParse(input.SourceBody, logger)
case "package_build":
pr = parser.CreateSourceCodeParse(input.SourceBody, logger)
case "vm-run":
pr = parser.CreateVMServiceParse(input.SourceBody, logger)
}
if pr == nil {
logger.Error("Creating component source types is not supported", map[string]string{"step": "callback", "status": "failure"})
@ -128,7 +130,10 @@ func (e *exectorManager) serviceCheck(task *pb.TaskMessage) {
}
errList := pr.Parse()
for i, err := range errList {
if err.SolveAdvice == "" && input.SourceType != "sourcecode" {
if err.SolveAdvice == "" && input.SourceType == "vm-run" {
errList[i].SolveAdvice = "镜像地址或镜像格式不正确,请检查镜像地址和镜像格式"
}
if err.SolveAdvice == "" && input.SourceType != "sourcecode" && input.SourceType != "vm-run" {
errList[i].SolveAdvice = fmt.Sprintf("解析器认为镜像名为:%s,请确认是否正确或镜像是否存在", pr.GetImage())
}
if err.SolveAdvice == "" && input.SourceType == "sourcecode" {

View File

@ -21,16 +21,16 @@ package exector
import (
"context"
"fmt"
"github.com/coreos/etcd/clientv3"
"github.com/goodrain/rainbond/builder"
"github.com/coreos/etcd/clientv3"
"github.com/goodrain/rainbond/builder/sources"
"github.com/goodrain/rainbond/event"
"github.com/pquerna/ffjson/ffjson"
"github.com/sirupsen/logrus"
)
//ImageShareItem ImageShareItem
// ImageShareItem ImageShareItem
type ImageShareItem struct {
Namespace string `json:"namespace"`
TenantName string `json:"tenant_name"`
@ -60,7 +60,7 @@ type ImageShareItem struct {
EtcdCli *clientv3.Client
}
//NewImageShareItem 创建实体
// NewImageShareItem 创建实体
func NewImageShareItem(in []byte, imageClient sources.ImageClient, EtcdCli *clientv3.Client) (*ImageShareItem, error) {
var isi ImageShareItem
if err := ffjson.Unmarshal(in, &isi); err != nil {
@ -75,7 +75,7 @@ func NewImageShareItem(in []byte, imageClient sources.ImageClient, EtcdCli *clie
return &isi, nil
}
//ShareService ShareService
// ShareService ShareService
func (i *ImageShareItem) ShareService() error {
hubuser, hubpass := builder.GetImageUserInfoV2(i.LocalImageName, i.LocalImageUsername, i.LocalImagePassword)
_, err := i.ImageClient.ImagePull(i.LocalImageName, hubuser, hubpass, i.Logger, 20)
@ -107,8 +107,8 @@ func (i *ImageShareItem) ShareService() error {
return nil
}
//ShareStatus share status result
//ShareStatus share status result
// ShareStatus share status result
// ShareStatus share status result
type ShareStatus struct {
ShareID string `json:"share_id,omitempty"`
Status string `json:"status,omitempty"`
@ -119,7 +119,7 @@ func (s ShareStatus) String() string {
return string(b)
}
//UpdateShareStatus 更新任务执行结果
// UpdateShareStatus 更新任务执行结果
func (i *ImageShareItem) UpdateShareStatus(status string) error {
var ss = ShareStatus{
ShareID: i.ShareID,

View File

@ -33,7 +33,7 @@ import (
"github.com/tidwall/gjson"
)
//PluginShareItem PluginShareItem
// PluginShareItem PluginShareItem
type PluginShareItem struct {
EventID string `json:"event_id"`
ImageName string `json:"image_name"`
@ -55,7 +55,7 @@ func init() {
RegisterWorker("share-plugin", SharePluginItemCreater)
}
//SharePluginItemCreater create
// SharePluginItemCreater create
func SharePluginItemCreater(in []byte, m *exectorManager) (TaskWorker, error) {
eventID := gjson.GetBytes(in, "event_id").String()
logger := event.GetManager().GetLogger(eventID)
@ -72,7 +72,7 @@ func SharePluginItemCreater(in []byte, m *exectorManager) (TaskWorker, error) {
return pluginShare, nil
}
//Run Run
// Run Run
func (i *PluginShareItem) Run(timeout time.Duration) error {
_, err := i.ImageClient.ImagePull(i.LocalImageName, builder.REGISTRYUSER, builder.REGISTRYPASS, i.Logger, 10)
if err != nil {
@ -103,27 +103,27 @@ func (i *PluginShareItem) Run(timeout time.Duration) error {
return i.updateShareStatus("success")
}
//Stop
// Stop -
func (i *PluginShareItem) Stop() error {
return nil
}
//Name return worker name
// Name return worker name
func (i *PluginShareItem) Name() string {
return "share-plugin"
}
//GetLogger GetLogger
// GetLogger GetLogger
func (i *PluginShareItem) GetLogger() event.Logger {
return i.Logger
}
//ErrorCallBack if run error will callback
// ErrorCallBack if run error will callback
func (i *PluginShareItem) ErrorCallBack(err error) {
i.updateShareStatus("failure")
}
//updateShareStatus update share task result
// updateShareStatus update share task result
func (i *PluginShareItem) updateShareStatus(status string) error {
var ss = ShareStatus{
ShareID: i.ShareID,

View File

@ -33,7 +33,7 @@ import (
"github.com/sirupsen/logrus"
)
//SlugShareItem SlugShareItem
// SlugShareItem SlugShareItem
type SlugShareItem struct {
Namespace string `json:"namespace"`
TenantName string `json:"tenant_name"`
@ -61,7 +61,7 @@ type SlugShareItem struct {
PackageName string
}
//NewSlugShareItem 创建实体
// NewSlugShareItem 创建实体
func NewSlugShareItem(in []byte, etcdCli *clientv3.Client) (*SlugShareItem, error) {
var ssi SlugShareItem
if err := ffjson.Unmarshal(in, &ssi); err != nil {
@ -73,7 +73,7 @@ func NewSlugShareItem(in []byte, etcdCli *clientv3.Client) (*SlugShareItem, erro
return &ssi, nil
}
//ShareService Run
// ShareService Run
func (i *SlugShareItem) ShareService() error {
logrus.Debugf("share app local slug path: %s ,target path: %s", i.LocalSlugPath, i.SlugPath)
@ -111,7 +111,7 @@ func createMD5(packageName string) (string, error) {
return md5Path, nil
}
//ShareToFTP ShareToFTP
// ShareToFTP ShareToFTP
func (i *SlugShareItem) ShareToFTP() error {
i.Logger.Info("开始上传应用介质到FTP服务器", map[string]string{"step": "slug-share"})
sFTPClient, err := sources.NewSFTPClient(i.ShareInfo.SlugInfo.FTPUser, i.ShareInfo.SlugInfo.FTPPassword, i.ShareInfo.SlugInfo.FTPHost, i.ShareInfo.SlugInfo.FTPPort)
@ -128,7 +128,7 @@ func (i *SlugShareItem) ShareToFTP() error {
return nil
}
//ShareToLocal ShareToLocal
// ShareToLocal ShareToLocal
func (i *SlugShareItem) ShareToLocal() error {
file := i.LocalSlugPath
i.Logger.Info("开始分享应用到本地目录", map[string]string{"step": "slug-share"})
@ -154,7 +154,7 @@ func (i *SlugShareItem) ShareToLocal() error {
return nil
}
//UpdateShareStatus 更新任务执行结果
// UpdateShareStatus 更新任务执行结果
func (i *SlugShareItem) UpdateShareStatus(status string) error {
var ss = ShareStatus{
ShareID: i.ShareID,
@ -175,7 +175,7 @@ func (i *SlugShareItem) UpdateShareStatus(status string) error {
return nil
}
//CheckMD5FileExist CheckMD5FileExist
// CheckMD5FileExist CheckMD5FileExist
func (i *SlugShareItem) CheckMD5FileExist(md5path, packageName string) bool {
return false
}

View File

@ -44,84 +44,87 @@ func init() {
checkFuncList = append(checkFuncList, netcore)
}
//ErrCodeNotExist 代码为空错误
// ErrCodeNotExist 代码为空错误
var ErrCodeNotExist = fmt.Errorf("code is not exist")
//ErrCodeDirNotExist 代码目录不存在
// ErrCodeDirNotExist 代码目录不存在
var ErrCodeDirNotExist = fmt.Errorf("code dir is not exist")
//ErrCodeUnableIdentify 代码无法识别语言
// ErrCodeUnableIdentify 代码无法识别语言
var ErrCodeUnableIdentify = fmt.Errorf("code lang unable to identify")
//ErrRainbondFileNotFound rainbond file not found
// ErrRainbondFileNotFound rainbond file not found
var ErrRainbondFileNotFound = fmt.Errorf("rainbond file not found")
//Lang 语言类型
// Lang 语言类型
type Lang string
//String return lang string
// String return lang string
func (l Lang) String() string {
return string(l)
}
//NO 空语言类型
// NO 空语言类型
var NO Lang = "no"
//Dockerfile Lang
// Dockerfile Lang
var Dockerfile Lang = "dockerfile"
//Docker Lang
// Docker Lang
var Docker Lang = "docker"
//Python Lang
// Python Lang
var Python Lang = "Python"
//Ruby Lang
// Ruby Lang
var Ruby Lang = "Ruby"
//PHP Lang
// PHP Lang
var PHP Lang = "PHP"
//JavaMaven Lang
// JavaMaven Lang
var JavaMaven Lang = "Java-maven"
//JaveWar Lang
// JaveWar Lang
var JaveWar Lang = "Java-war"
//JavaJar Lang
// JavaJar Lang
var JavaJar Lang = "Java-jar"
//Nodejs Lang
// Nodejs Lang
var Nodejs Lang = "Node.js"
//NodeJSDockerfile Lang
// NodeJSDockerfile Lang
var NodeJSDockerfile Lang = "NodeJSDockerfile"
//NodeJSStatic static Lang
// VMDockerfile Lang
var VMDockerfile Lang = "VMDockerfile"
// NodeJSStatic static Lang
var NodeJSStatic Lang = "NodeJSStatic"
//Static Lang
// Static Lang
var Static Lang = "static"
//Clojure Lang
// Clojure Lang
var Clojure Lang = "Clojure"
//Golang Lang
// Golang Lang
var Golang Lang = "Go"
//Gradle Lang
// Gradle Lang
var Gradle Lang = "Gradle"
//Grails Lang
// Grails Lang
var Grails Lang = "Grails"
//NetCore Lang
// NetCore Lang
var NetCore Lang = ".NetCore"
//OSS Lang
// OSS Lang
var OSS Lang = "OSS"
//GetLangType check code lang
// GetLangType check code lang
func GetLangType(homepath string) (Lang, error) {
if ok, _ := util.FileExists(homepath); !ok {
return NO, ErrCodeDirNotExist
@ -212,7 +215,7 @@ func javaWar(homepath string) Lang {
return NO
}
//javaJar Procfile必须定义
// javaJar Procfile必须定义
func javaJar(homepath string) Lang {
if ok := util.FileExistsWithSuffix(homepath, ".jar"); ok {
return JavaJar
@ -293,7 +296,7 @@ func grails(homepath string) Lang {
return NO
}
//netcore
// netcore
func netcore(homepath string) Lang {
if ok := util.FileExistsWithSuffix(homepath, ".sln"); ok {
return NetCore
@ -304,7 +307,7 @@ func netcore(homepath string) Lang {
return NO
}
//暂时不支持
// 暂时不支持
func scala(homepath string) Lang {
return NO
}

View File

@ -44,7 +44,7 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing/transport" //"github.com/docker/docker/client"
)
//SourceCodeParse docker run 命令解析或直接镜像名解析
// SourceCodeParse docker run 命令解析或直接镜像名解析
type SourceCodeParse struct {
ports map[int]*types.Port
volumes map[string]*types.Volume
@ -66,7 +66,7 @@ type SourceCodeParse struct {
services []*types.Service
}
//CreateSourceCodeParse create parser
// CreateSourceCodeParse create parser
func CreateSourceCodeParse(source string, logger event.Logger) Parser {
return &SourceCodeParse{
source: source,
@ -79,7 +79,7 @@ func CreateSourceCodeParse(source string, logger event.Logger) Parser {
}
}
//Parse 获取代码 解析代码 检验代码
// Parse 获取代码 解析代码 检验代码
func (d *SourceCodeParse) Parse() ParseErrorList {
if d.source == "" {
d.logger.Error("源码检查输入参数错误", map[string]string{"step": "parse"})
@ -481,7 +481,7 @@ func (d *SourceCodeParse) Parse() ParseErrorList {
return d.errors
}
//ReadRbdConfigAndLang read rainbondfile and lang
// ReadRbdConfigAndLang read rainbondfile and lang
func ReadRbdConfigAndLang(buildInfo *sources.RepostoryBuildInfo) (*code.RainbondFileConfig, code.Lang, error) {
rbdfileConfig, err := code.ReadRainbondFile(buildInfo.GetCodeBuildAbsPath())
if err != nil {
@ -520,12 +520,12 @@ func (d *SourceCodeParse) errappend(pe ParseError) {
d.errors = append(d.errors, pe)
}
//GetBranchs 获取分支列表
// GetBranchs 获取分支列表
func (d *SourceCodeParse) GetBranchs() []string {
return d.branchs
}
//GetPorts 获取端口列表
// GetPorts 获取端口列表
func (d *SourceCodeParse) GetPorts() (ports []types.Port) {
for _, cv := range d.ports {
ports = append(ports, *cv)
@ -533,7 +533,7 @@ func (d *SourceCodeParse) GetPorts() (ports []types.Port) {
return ports
}
//GetVolumes 获取存储列表
// GetVolumes 获取存储列表
func (d *SourceCodeParse) GetVolumes() (volumes []types.Volume) {
for _, cv := range d.volumes {
volumes = append(volumes, *cv)
@ -541,12 +541,12 @@ func (d *SourceCodeParse) GetVolumes() (volumes []types.Volume) {
return
}
//GetValid 获取源是否合法
// GetValid 获取源是否合法
func (d *SourceCodeParse) GetValid() bool {
return false
}
//GetEnvs 环境变量
// GetEnvs 环境变量
func (d *SourceCodeParse) GetEnvs() (envs []types.Env) {
for _, cv := range d.envs {
envs = append(envs, *cv)
@ -554,12 +554,12 @@ func (d *SourceCodeParse) GetEnvs() (envs []types.Env) {
return
}
//GetImage 获取镜像
// GetImage 获取镜像
func (d *SourceCodeParse) GetImage() Image {
return d.image
}
//GetArgs 启动参数
// GetArgs 启动参数
func (d *SourceCodeParse) GetArgs() []string {
if d.Lang == code.Nodejs {
return nil
@ -567,17 +567,17 @@ func (d *SourceCodeParse) GetArgs() []string {
return d.args
}
//GetMemory 获取内存
// GetMemory 获取内存
func (d *SourceCodeParse) GetMemory() int {
return d.memory
}
//GetLang 获取识别语言
// GetLang 获取识别语言
func (d *SourceCodeParse) GetLang() code.Lang {
return d.Lang
}
//GetServiceInfo 获取service info
// GetServiceInfo 获取service info
func (d *SourceCodeParse) GetServiceInfo() []ServiceInfo {
serviceInfo := ServiceInfo{
Ports: d.GetPorts(),

View File

@ -0,0 +1,115 @@
// Copyright (C) 2014-2018 Goodrain Co., Ltd.
// RAINBOND, Application Management Platform
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. For any non-GPL usage of Rainbond,
// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd.
// must be obtained first.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package parser
import (
"github.com/goodrain/rainbond/builder/parser/discovery"
"github.com/goodrain/rainbond/event"
"github.com/sirupsen/logrus"
"io/ioutil"
"net/http"
"path"
"path/filepath"
"strings"
)
// VMServiceParse is one of the implematation of parser.Parser
type VMServiceParse struct {
sourceBody string
endpoints []*discovery.Endpoint
errors []ParseError
logger event.Logger
}
// CreateVMServiceParse creates a new CreateVMServiceParse.
func CreateVMServiceParse(sourceBody string, logger event.Logger) Parser {
return &VMServiceParse{
sourceBody: sourceBody,
logger: logger,
}
}
// Parse blablabla
func (t *VMServiceParse) Parse() ParseErrorList {
if t.sourceBody == "" {
return []ParseError{}
}
var fileExt string
if strings.HasPrefix(t.sourceBody, "/grdata") {
fileInfoList, err := ioutil.ReadDir(t.sourceBody)
if err != nil {
logrus.Errorf("read package path %v failure: %v", t.sourceBody, err)
t.errappend(Errorf(FatalError, "http get failure"))
return t.errors
}
if len(fileInfoList) != 1 {
logrus.Errorf("the current directory contains multiple files: %v", t.sourceBody)
t.logger.Error("镜像只可以拥有一个,当前上传了多个文件", map[string]string{"step": "parse"})
t.errappend(Errorf(FatalError, "http get failure"))
return t.errors
}
fileExt = path.Ext(fileInfoList[0].Name())
} else {
rsp, err := http.Get(t.sourceBody)
if err != nil {
logrus.Errorf("http get %v failure: %v", t.sourceBody, err)
t.errappend(Errorf(FatalError, "http get failure"))
return t.errors
}
if rsp.StatusCode != http.StatusOK {
logrus.Errorf("url %v cannot be accessed", t.sourceBody)
t.logger.Error("镜像下载地址不可用", map[string]string{"step": "parse"})
t.errappend(Errorf(FatalError, "url address cannot be accessed"))
return t.errors
}
defer func() {
_ = rsp.Body.Close()
}()
baseURL := filepath.Base(t.sourceBody)
fileName := strings.Split(baseURL, "?")[0]
fileExt = path.Ext(fileName)
}
if fileExt != ".iso" && fileExt != ".qcow2" && fileExt != ".img" && fileExt != ".tar" && fileExt != ".gz" && fileExt != ".xz" {
t.logger.Error("上传包格式校验失败,不符合包要求", map[string]string{"step": "parse"})
t.errappend(Errorf(FatalError, "image package format verification failed"))
return t.errors
}
return []ParseError{}
}
// GetServiceInfo returns information of third-party service from
// the receiver *ThirdPartyServiceParse.
func (t *VMServiceParse) GetServiceInfo() []ServiceInfo {
serviceInfo := ServiceInfo{
Image: t.GetImage(),
}
return []ServiceInfo{serviceInfo}
}
// GetImage is a dummy method. there is no image for Third-party service.
func (t *VMServiceParse) GetImage() Image {
return Image{}
}
func (t *VMServiceParse) errappend(pe ParseError) {
t.errors = append(t.errors, pe)
}

View File

@ -53,8 +53,13 @@ func init() {
if os.Getenv("ABROAD") != "" {
ONLINEREGISTRYDOMAIN = "docker.io/rainbond"
}
ONLINEBUILDERIMAGENAME = fmt.Sprintf("%s:%s-%s", path.Join(ONLINEREGISTRYDOMAIN, "builder"), CIVERSION, arch)
ONLINERUNNERIMAGENAME = fmt.Sprintf("%s:%s-%s", path.Join(ONLINEREGISTRYDOMAIN, "runner"), CIVERSION, arch)
if release := os.Getenv("RELEASE_DESC"); release != "" {
releaseList := strings.Split(release, "-")
if len(releaseList) > 0 {
CIVERSION = fmt.Sprintf("%v-%v", releaseList[0], releaseList[1])
}
}
}
// GetImageUserInfoV2 -
@ -68,7 +73,7 @@ func GetImageUserInfoV2(domain, user, pass string) (string, string) {
return "", ""
}
//GetImageRepo -
// GetImageRepo -
func GetImageRepo(imageRepo string) string {
if imageRepo == "" {
return REGISTRYDOMAIN
@ -76,29 +81,41 @@ func GetImageRepo(imageRepo string) string {
return imageRepo
}
//REGISTRYDOMAIN REGISTRY_DOMAIN
// REGISTRYDOMAIN REGISTRY_DOMAIN
var REGISTRYDOMAIN = constants.DefImageRepository
//REGISTRYUSER REGISTRY USER NAME
// REGISTRYUSER REGISTRY USER NAME
var REGISTRYUSER = ""
//REGISTRYPASS REGISTRY PASSWORD
// REGISTRYPASS REGISTRY PASSWORD
var REGISTRYPASS = ""
//RUNNERIMAGENAME runner image name
// RUNNERIMAGENAME runner image name
var RUNNERIMAGENAME string
//BUILDERIMAGENAME builder image name
// BUILDERIMAGENAME builder image name
var BUILDERIMAGENAME string
// ONLINEREGISTRYDOMAIN online REGISTRY_DOMAIN
var ONLINEREGISTRYDOMAIN = constants.DefOnlineImageRepository
// ONLINEBUILDERIMAGENAME online builder image name
var ONLINEBUILDERIMAGENAME string
// GetBuilderImage GetBuilderImage
func GetBuilderImage(brVersion string) string {
arch := runtime.GOARCH
if brVersion == "" {
brVersion = CIVERSION
}
return fmt.Sprintf("%s:%s-%s", path.Join(ONLINEREGISTRYDOMAIN, "builder"), brVersion, arch)
}
// ONLINERUNNERIMAGENAME online runner image name
var ONLINERUNNERIMAGENAME string
// GetRunnerImage GetRunnerImage
func GetRunnerImage(brVersion string) string {
arch := runtime.GOARCH
if brVersion == "" {
brVersion = CIVERSION
}
return fmt.Sprintf("%s:%s-%s", path.Join(ONLINEREGISTRYDOMAIN, "runner"), brVersion, arch)
}
// CIVERSION -
var CIVERSION = "v5.14.0-release"
var CIVERSION = "v5.16.0-release"

View File

@ -6,7 +6,7 @@ import (
"github.com/docker/docker/api/types"
dockercli "github.com/docker/docker/client"
"github.com/sirupsen/logrus"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
"time"
)
@ -38,7 +38,7 @@ const (
CONTAINER_ACTION_DIE = "die"
)
//ContainerDesc -
// ContainerDesc -
type ContainerDesc struct {
ContainerRuntime string
// Info is extra information of the Container. The key could be arbitrary string, and
@ -51,7 +51,7 @@ type ContainerDesc struct {
*types.ContainerJSON
}
//GetLogPath -
// GetLogPath -
func (c *ContainerDesc) GetLogPath() string {
if c.ContainerRuntime == ContainerRuntimeDocker {
logrus.Debugf("docker container log path %s", c.ContainerJSON.LogPath)
@ -61,7 +61,7 @@ func (c *ContainerDesc) GetLogPath() string {
return c.ContainerStatus.GetLogPath()
}
//GetId -
// GetId -
func (c *ContainerDesc) GetId() string {
if c.ContainerRuntime == ContainerRuntimeDocker {
logrus.Debugf("docker container id %s", c.ContainerJSON.ID)
@ -107,13 +107,13 @@ func NewContainerImageClient(containerRuntime, endpoint string, timeout time.Dur
return
}
//ContainerEvent container event
// ContainerEvent container event
type ContainerEvent struct {
Action string
Container *ContainerDesc
}
//CacheContainer cache container
// CacheContainer cache container
func CacheContainer(cchan chan ContainerEvent, cs ...ContainerEvent) {
for _, container := range cs {
logrus.Debugf("found a container %s %s", container.Container.GetMetadata().GetName(), container.Action)

View File

@ -14,7 +14,7 @@ import (
"strings"
"github.com/goodrain/rainbond/util/criutil"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
"time"
)

View File

@ -8,7 +8,7 @@ import (
"github.com/docker/docker/api/types/filters"
dockercli "github.com/docker/docker/client"
"github.com/sirupsen/logrus"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
"os"
"strings"
"time"

View File

@ -64,16 +64,16 @@ import (
"time"
)
//ErrorNoAuth error no auth
// ErrorNoAuth error no auth
var ErrorNoAuth = fmt.Errorf("pull image require docker login")
//ErrorNoImage error no image
// ErrorNoImage error no image
var ErrorNoImage = fmt.Errorf("image not exist")
//Namespace containerd image namespace
// Namespace containerd image namespace
var Namespace = "k8s.io"
//ImagePull pull docker image
// ImagePull pull docker image
// Deprecated: use sources.ImageClient.ImagePull instead
func ImagePull(client *containerd.Client, ref string, username, password string, logger event.Logger, timeout int) (*containerd.Image, error) {
printLog(logger, "info", fmt.Sprintf("start get image:%s", ref), map[string]string{"step": "pullimage"})
@ -171,7 +171,7 @@ func ImageTag(containerdClient *containerd.Client, source, target string, logger
return nil
}
//ImageNameHandle 解析imagename
// ImageNameHandle 解析imagename
func ImageNameHandle(imageName string) *model.ImageName {
var i model.ImageName
if strings.Contains(imageName, "/") {
@ -199,7 +199,7 @@ func ImageNameHandle(imageName string) *model.ImageName {
return &i
}
//ImageNameWithNamespaceHandle if have namespace,will parse namespace
// ImageNameWithNamespaceHandle if have namespace,will parse namespace
func ImageNameWithNamespaceHandle(imageName string) *model.ImageName {
var i model.ImageName
if strings.Contains(imageName, "/") {
@ -231,8 +231,8 @@ func ImageNameWithNamespaceHandle(imageName string) *model.ImageName {
return &i
}
//ImagePush push image to registry
//timeout minutes of the unit
// ImagePush push image to registry
// timeout minutes of the unit
// Deprecated: use sources.ImageClient.ImagePush instead
func ImagePush(client *containerd.Client, rawRef, user, pass string, logger event.Logger, timeout int) error {
printLog(logger, "info", fmt.Sprintf("start push image%s", rawRef), map[string]string{"step": "pushimage"})
@ -325,7 +325,7 @@ func ImagePush(client *containerd.Client, rawRef, user, pass string, logger even
return nil
}
//TrustedImagePush push image to trusted registry
// TrustedImagePush push image to trusted registry
func TrustedImagePush(containerdClient *containerd.Client, image, user, pass string, logger event.Logger, timeout int) error {
if err := CheckTrustedRepositories(image, user, pass); err != nil {
return err
@ -333,7 +333,7 @@ func TrustedImagePush(containerdClient *containerd.Client, image, user, pass str
return ImagePush(containerdClient, image, user, pass, logger, timeout)
}
//CheckTrustedRepositories check Repositories is exist ,if not create it.
// CheckTrustedRepositories check Repositories is exist ,if not create it.
func CheckTrustedRepositories(image, user, pass string) error {
ref, err := reference.ParseNormalizedNamed(image)
if err != nil {
@ -391,11 +391,11 @@ func EncodeAuthToBase64(authConfig types.AuthConfig) (string, error) {
return base64.URLEncoding.EncodeToString(buf), nil
}
//ImageBuild use buildkit build image
// ImageBuild use buildkit build image
func ImageBuild(arch, contextDir, cachePVCName, cacheMode, RbdNamespace, ServiceID, DeployVersion string, logger event.Logger, buildType, plugImageName, BuildKitImage string, BuildKitArgs []string, BuildKitCache bool, kubeClient kubernetes.Interface) error {
// create image name
var buildImageName string
if buildType == "plug-build" {
if buildType == "plug-build" || buildType == "vm-build" {
buildImageName = plugImageName
} else {
buildImageName = CreateImageName(ServiceID, DeployVersion)
@ -459,6 +459,11 @@ func ImageBuild(arch, contextDir, cachePVCName, cacheMode, RbdNamespace, Service
Stdin: true,
StdinOnce: true,
Command: []string{"buildctl-daemonless.sh"},
Env: []corev1.EnvVar{{
Name: "BUILDCTL_CONNECT_RETRIES_MAX",
Value: "20",
},
},
Args: []string{
"build",
"--frontend",
@ -500,7 +505,7 @@ func ImageBuild(arch, contextDir, cachePVCName, cacheMode, RbdNamespace, Service
return nil
}
//ImageInspectWithRaw get image inspect
// ImageInspectWithRaw get image inspect
func ImageInspectWithRaw(dockerCli *client.Client, image string) (*types.ImageInspect, error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@ -511,7 +516,7 @@ func ImageInspectWithRaw(dockerCli *client.Client, image string) (*types.ImageIn
return &ins, nil
}
//ImageSave save image to tar file
// ImageSave save image to tar file
// destination destination file name eg. /tmp/xxx.tar
func ImageSave(dockerCli *client.Client, image, destination string, logger event.Logger) error {
ctx, cancel := context.WithCancel(context.Background())
@ -524,7 +529,7 @@ func ImageSave(dockerCli *client.Client, image, destination string, logger event
return CopyToFile(destination, rc)
}
//MultiImageSave save multi image to tar file
// MultiImageSave save multi image to tar file
// destination destination file name eg. /tmp/xxx.tar
func MultiImageSave(ctx context.Context, dockerCli *client.Client, destination string, logger event.Logger, images ...string) error {
rc, err := dockerCli.ImageSave(ctx, images)
@ -535,7 +540,7 @@ func MultiImageSave(ctx context.Context, dockerCli *client.Client, destination s
return CopyToFile(destination, rc)
}
//ImageLoad load image from tar file
// ImageLoad load image from tar file
// destination destination file name eg. /tmp/xxx.tar
func ImageLoad(dockerCli *client.Client, tarFile string, logger event.Logger) error {
ctx, cancel := context.WithCancel(context.Background())
@ -577,7 +582,7 @@ func ImageLoad(dockerCli *client.Client, tarFile string, logger event.Logger) er
return nil
}
//ImageImport save image to tar file
// ImageImport save image to tar file
// source source file name eg. /tmp/xxx.tar
func ImageImport(dockerCli *client.Client, image, source string, logger event.Logger) error {
ctx, cancel := context.WithCancel(context.Background())
@ -648,7 +653,7 @@ func CopyToFile(outfile string, r io.Reader) error {
return nil
}
//ImageRemove remove image
// ImageRemove remove image
func ImageRemove(containerdClient *containerd.Client, image string) error {
ctx := namespaces.WithNamespace(context.Background(), Namespace)
imageStore := containerdClient.ImageService()
@ -769,7 +774,7 @@ func CreateImageName(ServiceID, DeployVersion string) string {
return strings.ToLower(fmt.Sprintf("%s/%s:%s", builder.REGISTRYDOMAIN, workloadName, DeployVersion))
}
//GetImageFirstPart -
// GetImageFirstPart -
func GetImageFirstPart(str string) (string, string) {
imageDomain, imageName := str, ""
if strings.Contains(str, "/") {
@ -781,7 +786,7 @@ func GetImageFirstPart(str string) (string, string) {
return imageDomain, imageName
}
//PrepareBuildKitTomlCM -
// PrepareBuildKitTomlCM -
func PrepareBuildKitTomlCM(ctx context.Context, kubeClient kubernetes.Interface, namespace, buildKitTomlCMName, imageDomain string) error {
buildKitTomlCM, err := kubeClient.CoreV1().ConfigMaps(namespace).Get(ctx, buildKitTomlCMName, metav1.GetOptions{})
if err != nil && !k8serror.IsNotFound(err) {
@ -923,7 +928,7 @@ func CreateVolumesAndMounts(ServiceID, contextDir, buildType, cacheMode, cachePV
}
volumeMounts = append(volumeMounts, volumeMount)
}
if buildType == "run-build" {
if buildType == "run-build" || buildType == "vm-build" {
volume := corev1.Volume{
Name: "run-build",
VolumeSource: corev1.VolumeSource{

View File

@ -29,7 +29,7 @@ import (
"github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
"os"
"sync"
"time"
@ -111,7 +111,6 @@ func (c *containerdImageCliImpl) ImagePull(image string, username, password stri
pctx, stopProgress := context.WithCancel(ctx)
progress := make(chan struct{})
go func() {
ShowProgress(pctx, ongoing, c.client.ContentStore(), logger)
close(progress)
@ -262,7 +261,7 @@ func (c *containerdImageCliImpl) ImagePush(image, user, pass string, logger even
return nil
}
//ImageTag change docker image tag
// ImageTag change docker image tag
func (c *containerdImageCliImpl) ImageTag(source, target string, logger event.Logger, timeout int) error {
srcNamed, err := refdocker.ParseDockerRef(source)
if err != nil {
@ -330,7 +329,7 @@ func (c *containerdImageCliImpl) ImagesPullAndPush(sourceImage, targetImage, use
return nil
}
//ImageRemove remove image
// ImageRemove remove image
func (c *containerdImageCliImpl) ImageRemove(image string) error {
named, err := refdocker.ParseDockerRef(image)
if err != nil {
@ -346,7 +345,7 @@ func (c *containerdImageCliImpl) ImageRemove(image string) error {
return err
}
//ImageSave save image to tar file
// ImageSave save image to tar file
// destination destination file name eg. /tmp/xxx.tar
func (c *containerdImageCliImpl) ImageSave(image, destination string) error {
named, err := refdocker.ParseDockerRef(image)
@ -363,7 +362,7 @@ func (c *containerdImageCliImpl) ImageSave(image, destination string) error {
return c.client.Export(ctx, w, exportOpts...)
}
//TrustedImagePush push image to trusted registry
// TrustedImagePush push image to trusted registry
func (c *containerdImageCliImpl) TrustedImagePush(image, user, pass string, logger event.Logger, timeout int) error {
if err := CheckTrustedRepositories(image, user, pass); err != nil {
return err
@ -371,7 +370,7 @@ func (c *containerdImageCliImpl) TrustedImagePush(image, user, pass string, logg
return c.ImagePush(image, user, pass, logger, timeout)
}
//ImageLoad load image from tar file
// ImageLoad load image from tar file
// destination destination file name eg. /tmp/xxx.tar
func (c *containerdImageCliImpl) ImageLoad(tarFile string, logger event.Logger) error {
ctx := namespaces.WithNamespace(context.Background(), Namespace)
@ -581,7 +580,7 @@ func Display(statuses []ctrcontent.StatusInfo, start time.Time, logger event.Log
}
}
func containerdLogFormat(status ctrcontent.StatusInfo, barFormat string, logger event.Logger) {
func containerdLogFormat(status ctrcontent.StatusInfo, barFormat string, logger event.Logger) {
var jm JSONMessage
jm = JSONMessage{
Status: status.Status,
@ -590,7 +589,7 @@ func containerdLogFormat(status ctrcontent.StatusInfo, barFormat string, logger
Total: status.Total,
},
ProgressMessage: barFormat,
ID: status.Ref,
ID: status.Ref,
}
printLog(logger, "debug", fmt.Sprintf(jm.JSONString()), map[string]string{"step": "progress"})
}

View File

@ -39,6 +39,7 @@ import (
"k8s.io/client-go/kubernetes"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/restmapper"
"kubevirt.io/client-go/kubecli"
"os"
"os/signal"
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
@ -134,10 +135,16 @@ func Run(s *option.APIServer) error {
return err
}
kubevirtCli, err := kubecli.GetKubevirtClientFromRESTConfig(config)
if err != nil {
logrus.Errorf("create kubevirt cli failure: %v", err)
return err
}
//初始化 middleware
handler.InitProxy(s.Config)
//创建handle
if err := handler.InitHandle(s.Config, etcdClientArgs, cli, etcdcli, clientset, rainbondClient, k8sClient, config, mapper, dynamicClient, gatewayClient); err != nil {
if err := handler.InitHandle(s.Config, etcdClientArgs, cli, etcdcli, clientset, rainbondClient, k8sClient, config, mapper, dynamicClient, gatewayClient, kubevirtCli); err != nil {
logrus.Errorf("init all handle error, %v", err)
return err
}

View File

@ -62,6 +62,7 @@ type Config struct {
RuntimeEndpoint string
KeepCount int
CleanInterval int
BRVersion string
}
// Builder builder server
@ -112,7 +113,7 @@ func (a *Builder) AddFlags(fs *pflag.FlagSet) {
fs.BoolVar(&a.BuildKitCache, "buildkit-cache", false, "whether to enable the buildkit image cache")
fs.IntVar(&a.KeepCount, "keep-count", 5, "default number of reserved copies for images")
fs.IntVar(&a.CleanInterval, "clean-interval", 60, "clean image interval,default 60 minute")
fs.StringVar(&a.BRVersion, "br-version", "v5.16.0-release", "builder and runner version")
}
// SetLog 设置log

View File

@ -50,7 +50,7 @@ var (
exitChan = make(chan struct{})
)
//Init init config
// Init init config
func Init() error {
if initialized {
return nil
@ -64,7 +64,7 @@ func Init() error {
return nil
}
//Conf Conf
// Conf Conf
type Conf struct {
APIAddr string //api server listen port
GrpcAPIAddr string //grpc api server listen port
@ -135,7 +135,7 @@ type Conf struct {
HostsFile string
}
//StatsdConfig StatsdConfig
// StatsdConfig StatsdConfig
type StatsdConfig struct {
StatsdListenAddress string
StatsdListenUDP string
@ -144,13 +144,13 @@ type StatsdConfig struct {
ReadBuffer int
}
//UDPMonitorConfig UDPMonitorConfig
// UDPMonitorConfig UDPMonitorConfig
type UDPMonitorConfig struct {
ListenHost string
ListenPort string
}
//AddFlags AddFlags
// AddFlags AddFlags
func (a *Conf) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&a.LogLevel, "log-level", "info", "the log level")
fs.StringVar(&a.LogFile, "log-file", "", "the log file path that log output")
@ -201,7 +201,7 @@ func (a *Conf) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&a.RuntimeEndpoint, "runtime-endpoint", sources.RuntimeEndpointContainerd, "container runtime endpoint")
}
//SetLog 设置log
// SetLog 设置log
func (a *Conf) SetLog() {
level, err := logrus.ParseLevel(a.LogLevel)
if err != nil {
@ -234,7 +234,7 @@ func newClient(namespace, address string, opts ...containerd.ClientOpt) (*contai
return client, ctx, cancel, nil
}
//ParseClient handle config and create some api
// ParseClient handle config and create some api
func (a *Conf) ParseClient(ctx context.Context, etcdClientArgs *etcdutil.ClientArgs) (err error) {
logrus.Infof("begin create container image client, runtime [%s] runtime endpoint [%s]", a.ContainerRuntime, a.RuntimeEndpoint, a.EtcdEndpoints)
containerImageCli, err := sources.NewContainerImageClient(a.ContainerRuntime, a.RuntimeEndpoint, time.Second*3)
@ -257,7 +257,7 @@ func (a *Conf) ParseClient(ctx context.Context, etcdClientArgs *etcdutil.ClientA
return nil
}
//parse parse
// parse parse
func (a *Conf) parse() error {
if a.TTL <= 0 {
a.TTL = 10

View File

@ -20,6 +20,7 @@ package server
import (
"k8s.io/client-go/restmapper"
"kubevirt.io/client-go/kubecli"
"os"
"os/signal"
"syscall"
@ -47,7 +48,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)
//Run start run
// Run start run
func Run(s *option.Worker) error {
errChan := make(chan error, 2)
dbconfig := config.Config{
@ -82,6 +83,7 @@ func Run(s *option.Worker) error {
return err
}
restConfig.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(float32(s.Config.KubeAPIQPS), s.Config.KubeAPIBurst)
kubevirtCli, err := kubecli.GetKubevirtClientFromRESTConfig(restConfig)
clientset, err := kubernetes.NewForConfig(restConfig)
if err != nil {
logrus.Errorf("create kube client error: %s", err.Error())
@ -106,14 +108,14 @@ func Run(s *option.Worker) error {
//step 4: create component resource store
updateCh := channels.NewRingChannel(1024)
k8sVersion := k8sutil.GetKubeVersion()
cachestore := store.NewStore(restConfig, clientset, rainbondClient, db.GetManager(), s.Config, k8sVersion)
cachestore := store.NewStore(restConfig, clientset, rainbondClient, db.GetManager(), s.Config, k8sVersion, kubevirtCli)
if err := cachestore.Start(); err != nil {
logrus.Error("start kube cache store error", err)
return err
}
//step 5: create controller manager
controllerManager := controller.NewManager(s.Config, cachestore, clientset, runtimeClient)
controllerManager := controller.NewManager(s.Config, cachestore, clientset, runtimeClient, kubevirtCli)
defer controllerManager.Stop()
//step 6 : start runtime master

View File

@ -27,11 +27,10 @@ import (
etcdutil "github.com/goodrain/rainbond/util/etcd"
"github.com/coreos/etcd/clientv3"
"github.com/sirupsen/logrus"
)
//Manager db manager
// Manager db manager
type Manager struct {
client *clientv3.Client
config config.Config
@ -39,7 +38,7 @@ type Manager struct {
models []model.Interface
}
//CreateManager 创建manager
// CreateManager 创建manager
func CreateManager(config config.Config) (*Manager, error) {
etcdClientArgs := &etcdutil.ClientArgs{
Endpoints: config.EtcdEndPoints,
@ -61,7 +60,7 @@ func CreateManager(config config.Config) (*Manager, error) {
return manager, nil
}
//CloseManager 关闭管理器
// CloseManager 关闭管理器
func (m *Manager) CloseManager() error {
return m.client.Close()
}

View File

@ -57,6 +57,10 @@ const (
K8sAttributeNameENVFromSource = "envFromSource"
//K8sAttributeNameSecurityContext -
K8sAttributeNameSecurityContext = "securityContext"
//K8sAttributeNameReadinessProbe -
K8sAttributeNameReadinessProbe = "readinessProbe"
//K8sAttributeNameLiveNessProbe -
K8sAttributeNameLiveNessProbe = "livenessProbe"
)
// ComponentK8sAttributes -

View File

@ -27,18 +27,18 @@ import (
"github.com/goodrain/rainbond/util/commonutil"
)
//Model 默认字段
// Model 默认字段
type Model struct {
ID uint `gorm:"column:ID;primary_key"`
CreatedAt time.Time `gorm:"column:create_time" json:"create_time"`
}
//IDModel 默认ID字段
// IDModel 默认ID字段
type IDModel struct {
ID uint `gorm:"column:ID;primary_key"`
}
//Interface model interface
// Interface model interface
type Interface interface {
TableName() string
}
@ -59,7 +59,7 @@ func (t TenantStatus) String() string {
return string(t)
}
//Tenants 租户信息
// Tenants 租户信息
type Tenants struct {
Model
Name string `gorm:"column:name;size:40;unique_index"`
@ -70,7 +70,7 @@ type Tenants struct {
Namespace string `gorm:"column:namespace;size:32;unique_index"`
}
//TableName 返回租户表名称
// TableName 返回租户表名称
func (t *Tenants) TableName() string {
return "tenants"
}
@ -81,6 +81,9 @@ type ServiceKind string
// ServiceKindThirdParty means third-party service
var ServiceKindThirdParty ServiceKind = "third_party"
// ServiceKindVirtualMachine -
var ServiceKindVirtualMachine ServiceKind = "virtualmachine"
// ServiceKindInternal means internal service
var ServiceKindInternal ServiceKind = "internal"
@ -107,6 +110,14 @@ func (s ServiceType) IsState() bool {
return false
}
// IsVM is vm type or not
func (s ServiceType) IsVM() bool {
if s == ServiceTypeVM {
return true
}
return false
}
// IsJob is job
func (s ServiceType) IsJob() bool {
if s == ServiceTypeJob {
@ -143,6 +154,13 @@ func (t *TenantServices) IsState() bool {
return ServiceType(t.ExtendMethod).IsState()
}
func (t *TenantServices) IsVM() bool {
if t.ExtendMethod == "" {
return false
}
return ServiceType(t.ExtendMethod).IsVM()
}
// IsJob is job
func (t *TenantServices) IsJob() bool {
if ServiceType(t.ExtendMethod).IsJob() {
@ -170,7 +188,7 @@ func (t *TenantServices) IsSingleton() bool {
// ServiceTypeUnknown unknown
var ServiceTypeUnknown ServiceType = "unknown"
//ServiceTypeStatelessSingleton stateless_singleton
// ServiceTypeStatelessSingleton stateless_singleton
var ServiceTypeStatelessSingleton ServiceType = "stateless_singleton"
// ServiceTypeStatelessMultiple stateless_multiple
@ -182,13 +200,16 @@ var ServiceTypeStateSingleton ServiceType = "state_singleton"
// ServiceTypeStateMultiple state_multiple
var ServiceTypeStateMultiple ServiceType = "state_multiple"
// ServiceTypeVM vm
var ServiceTypeVM ServiceType = "vm"
// ServiceTypeJob job
var ServiceTypeJob ServiceType = "job"
// ServiceTypeCronJob cronjob
var ServiceTypeCronJob ServiceType = "cronjob"
//TenantServices app service base info
// TenantServices app service base info
type TenantServices struct {
Model
TenantID string `gorm:"column:tenant_id;size:32" json:"tenant_id"`
@ -253,7 +274,7 @@ type ComponentWorkload struct {
ServiceAlias string `gorm:"column:service_alias"`
}
//Image 镜像
// Image 镜像
type Image struct {
Host string
Namespace string
@ -267,7 +288,7 @@ func (i Image) String() string {
return fmt.Sprintf("%s/%s/%s", i.Host, i.Namespace, i.Name)
}
//ParseImage 简单解析镜像名
// ParseImage 简单解析镜像名
func ParseImage(name string) (image Image) {
i := strings.IndexRune(name, '/')
if i == -1 || (!strings.ContainsAny(name[:i], ".:") && name[:i] != "localhost") {
@ -284,19 +305,19 @@ func ParseImage(name string) (image Image) {
return
}
//CreateShareSlug 生成源码包分享的地址
// CreateShareSlug 生成源码包分享的地址
func (t *TenantServices) CreateShareSlug(servicekey, namespace, version string) string {
return fmt.Sprintf("%s/%s/%s_%s.tgz", namespace, servicekey, version, t.DeployVersion)
}
//ChangeDelete ChangeDelete
// ChangeDelete ChangeDelete
func (t *TenantServices) ChangeDelete() *TenantServicesDelete {
delete := TenantServicesDelete(*t)
delete.UpdateTime = time.Now()
return &delete
}
//Autodomain 构建默认域名
// Autodomain 构建默认域名
func (t *TenantServices) Autodomain(tenantName string, containerPort int) string {
exDomain := os.Getenv("EX_DOMAIN")
if exDomain == "" {
@ -308,12 +329,12 @@ func (t *TenantServices) Autodomain(tenantName string, containerPort int) string
return fmt.Sprintf("%d.%s.%s.%s", containerPort, t.ServiceAlias, tenantName, exDomain)
}
//TableName 表名
// TableName 表名
func (t *TenantServices) TableName() string {
return "tenant_services"
}
//TenantServicesDelete 已删除的应用表
// TenantServicesDelete 已删除的应用表
type TenantServicesDelete struct {
Model
TenantID string `gorm:"column:tenant_id;size:32" json:"tenant_id"`
@ -368,12 +389,12 @@ type TenantServicesDelete struct {
JobStrategy string `gorm:"column:job_strategy" json:"job_strategy"`
}
//TableName 表名
// TableName 表名
func (t *TenantServicesDelete) TableName() string {
return "tenant_services_delete"
}
//TenantServicesPort 应用端口信息
// TenantServicesPort 应用端口信息
type TenantServicesPort struct {
Model
TenantID string `gorm:"column:tenant_id;size:32" validate:"tenant_id|between:30,33" json:"tenant_id"`
@ -393,7 +414,7 @@ func (t *TenantServicesPort) Key() string {
return fmt.Sprintf("%s/%s/%d", t.TenantID, t.ServiceID, t.ContainerPort)
}
//TableName 表名
// TableName 表名
func (t *TenantServicesPort) TableName() string {
return "tenant_services_port"
}
@ -403,7 +424,7 @@ func (t *TenantServicesPort) IsOpen() bool {
return commonutil.BoolValue(t.IsOuterService) || commonutil.BoolValue(t.IsInnerService)
}
//TenantServiceLBMappingPort stream应用端口映射情况
// TenantServiceLBMappingPort stream应用端口映射情况
type TenantServiceLBMappingPort struct {
Model
ServiceID string `gorm:"column:service_id;size:32"`
@ -415,12 +436,12 @@ type TenantServiceLBMappingPort struct {
ContainerPort int `gorm:"column:container_port"`
}
//TableName 表名
// TableName 表名
func (t *TenantServiceLBMappingPort) TableName() string {
return "tenant_lb_mapping_port"
}
//TenantServiceRelation 应用依赖关系
// TenantServiceRelation 应用依赖关系
type TenantServiceRelation struct {
Model
TenantID string `gorm:"column:tenant_id;size:32" validate:"tenant_id" json:"tenant_id"`
@ -430,12 +451,12 @@ type TenantServiceRelation struct {
DependOrder int `gorm:"column:dep_order" validate:"dep_order" json:"dep_order"`
}
//TableName 表名
// TableName 表名
func (t *TenantServiceRelation) TableName() string {
return "tenant_services_relation"
}
//TenantServiceEnvVar 应用环境变量
// TenantServiceEnvVar 应用环境变量
type TenantServiceEnvVar struct {
Model
TenantID string `gorm:"column:tenant_id;size:32" validate:"tenant_id|between:30,33" json:"tenant_id"`
@ -448,13 +469,13 @@ type TenantServiceEnvVar struct {
Scope string `gorm:"column:scope;default:'outer'" validate:"scope|in:outer,inner,both" json:"scope"`
}
//TableName 表名
// TableName 表名
func (t *TenantServiceEnvVar) TableName() string {
//TODO:表名修改
return "tenant_services_envs"
}
//TenantServiceMountRelation 应用挂载依赖纪录
// TenantServiceMountRelation 应用挂载依赖纪录
type TenantServiceMountRelation struct {
Model
TenantID string `gorm:"column:tenant_id;size:32" json:"tenant_id" validate:"tenant_id|between:30,33"`
@ -469,29 +490,32 @@ type TenantServiceMountRelation struct {
VolumeType string `gorm:"column:volume_type" json:"volume_type" validate:"volume_type|required"`
}
//TableName 表名
// TableName 表名
func (t *TenantServiceMountRelation) TableName() string {
return "tenant_services_mnt_relation"
}
//VolumeType 存储类型
// VolumeType 存储类型
type VolumeType string
//ShareFileVolumeType 共享文件存储
// ShareFileVolumeType 共享文件存储
var ShareFileVolumeType VolumeType = "share-file"
//LocalVolumeType 本地文件存储
// LocalVolumeType 本地文件存储
var LocalVolumeType VolumeType = "local"
//PluginStorageType 插件存储
// PluginStorageType 插件存储
var PluginStorageType VolumeType = "plugin-storage"
//MemoryFSVolumeType 内存文件存储
// MemoryFSVolumeType 内存文件存储
var MemoryFSVolumeType VolumeType = "memoryfs"
//ConfigFileVolumeType configuration file volume type
// ConfigFileVolumeType configuration file volume type
var ConfigFileVolumeType VolumeType = "config-file"
// VMVolumeType vm file volume type
var VMVolumeType VolumeType = "vm-file"
// CephRBDVolumeType ceph rbd volume type
var CephRBDVolumeType VolumeType = "ceph-rbd"
@ -507,7 +531,7 @@ func (vt VolumeType) String() string {
return string(vt)
}
//TenantServiceVolume 应用持久化纪录
// TenantServiceVolume 应用持久化纪录
type TenantServiceVolume struct {
Model
ServiceID string `gorm:"column:service_id;size:32" json:"service_id"`
@ -540,7 +564,7 @@ type TenantServiceVolume struct {
Mode *int32 `gorm:"column:mode" json:"mode"`
}
//TableName 表名
// TableName 表名
func (t *TenantServiceVolume) TableName() string {
return "tenant_services_volume"
}
@ -563,7 +587,7 @@ func (t *TenantServiceConfigFile) TableName() string {
return "tenant_service_config_file"
}
//TenantServiceLable 应用高级标签
// TenantServiceLable 应用高级标签
type TenantServiceLable struct {
Model
ServiceID string `gorm:"column:service_id;size:32"`
@ -571,31 +595,31 @@ type TenantServiceLable struct {
LabelValue string `gorm:"column:label_value;size:50"`
}
//TableName 表名
// TableName 表名
func (t *TenantServiceLable) TableName() string {
return "tenant_services_label"
}
//LabelKeyNodeSelector 节点选择标签
// LabelKeyNodeSelector 节点选择标签
var LabelKeyNodeSelector = "node-selector"
//LabelKeyNodeAffinity 节点亲和标签
// LabelKeyNodeAffinity 节点亲和标签
var LabelKeyNodeAffinity = "node-affinity"
//LabelKeyServiceType 应用部署类型标签
// LabelKeyServiceType 应用部署类型标签
// TODO fanyangyang 待删除组件类型记录在tenant_service表中
var LabelKeyServiceType = "service-type"
//LabelKeyServiceAffinity 应用亲和标签
// LabelKeyServiceAffinity 应用亲和标签
var LabelKeyServiceAffinity = "service-affinity"
//LabelKeyServiceAntyAffinity 应用反亲和标签
// LabelKeyServiceAntyAffinity 应用反亲和标签
var LabelKeyServiceAntyAffinity = "service-anti-affinity"
// LabelKeyServicePrivileged -
var LabelKeyServicePrivileged = "privileged"
//TenantServiceProbe 应用探针信息
// TenantServiceProbe 应用探针信息
type TenantServiceProbe struct {
Model
ServiceID string `gorm:"column:service_id;size:32" json:"service_id" validate:"service_id|between:30,33"`
@ -638,7 +662,7 @@ const (
RestartFailureAction FailureActionType = "liveness"
)
//TableName 表名
// TableName 表名
func (t *TenantServiceProbe) TableName() string {
return "tenant_services_probe"
}

View File

@ -36,12 +36,12 @@ import (
"github.com/sirupsen/logrus"
)
//TenantDaoImpl 租户信息管理
// TenantDaoImpl 租户信息管理
type TenantDaoImpl struct {
DB *gorm.DB
}
//AddModel 添加租户
// AddModel 添加租户
func (t *TenantDaoImpl) AddModel(mo model.Interface) error {
tenant := mo.(*model.Tenants)
var oldTenant model.Tenants
@ -55,7 +55,7 @@ func (t *TenantDaoImpl) AddModel(mo model.Interface) error {
return nil
}
//UpdateModel 更新租户
// UpdateModel 更新租户
func (t *TenantDaoImpl) UpdateModel(mo model.Interface) error {
tenant := mo.(*model.Tenants)
if err := t.DB.Save(tenant).Error; err != nil {
@ -64,7 +64,7 @@ func (t *TenantDaoImpl) UpdateModel(mo model.Interface) error {
return nil
}
//GetTenantByUUID 获取租户
// GetTenantByUUID 获取租户
func (t *TenantDaoImpl) GetTenantByUUID(uuid string) (*model.Tenants, error) {
var tenant model.Tenants
if err := t.DB.Where("uuid = ?", uuid).Find(&tenant).Error; err != nil {
@ -73,7 +73,7 @@ func (t *TenantDaoImpl) GetTenantByUUID(uuid string) (*model.Tenants, error) {
return &tenant, nil
}
//GetTenantByUUIDIsExist 获取租户
// GetTenantByUUIDIsExist 获取租户
func (t *TenantDaoImpl) GetTenantByUUIDIsExist(uuid string) bool {
var tenant model.Tenants
isExist := t.DB.Where("uuid = ?", uuid).First(&tenant).RecordNotFound()
@ -81,7 +81,7 @@ func (t *TenantDaoImpl) GetTenantByUUIDIsExist(uuid string) bool {
}
//GetTenantIDByName 获取租户
// GetTenantIDByName 获取租户
func (t *TenantDaoImpl) GetTenantIDByName(name string) (*model.Tenants, error) {
var tenant model.Tenants
if err := t.DB.Where("name = ?", name).Find(&tenant).Error; err != nil {
@ -90,7 +90,7 @@ func (t *TenantDaoImpl) GetTenantIDByName(name string) (*model.Tenants, error) {
return &tenant, nil
}
//GetALLTenants GetALLTenants
// GetALLTenants GetALLTenants
func (t *TenantDaoImpl) GetALLTenants(query string) ([]*model.Tenants, error) {
var tenants []*model.Tenants
if query != "" {
@ -105,7 +105,7 @@ func (t *TenantDaoImpl) GetALLTenants(query string) ([]*model.Tenants, error) {
return tenants, nil
}
//GetTenantByEid get tenants by eid
// GetTenantByEid get tenants by eid
func (t *TenantDaoImpl) GetTenantByEid(eid, query string) ([]*model.Tenants, error) {
var tenants []*model.Tenants
if query != "" {
@ -120,7 +120,7 @@ func (t *TenantDaoImpl) GetTenantByEid(eid, query string) ([]*model.Tenants, err
return tenants, nil
}
//GetTenantIDsByNames get tenant ids by names
// GetTenantIDsByNames get tenant ids by names
func (t *TenantDaoImpl) GetTenantIDsByNames(names []string) (re []string, err error) {
rows, err := t.DB.Raw("select uuid from tenants where name in (?)", names).Rows()
if err != nil {
@ -135,7 +135,7 @@ func (t *TenantDaoImpl) GetTenantIDsByNames(names []string) (re []string, err er
return
}
//GetTenantLimitsByNames get tenants memory limit
// GetTenantLimitsByNames get tenants memory limit
func (t *TenantDaoImpl) GetTenantLimitsByNames(names []string) (limit map[string]int, err error) {
limit = make(map[string]int)
rows, err := t.DB.Raw("select uuid,limit_memory from tenants where name in (?)", names).Rows()
@ -170,7 +170,7 @@ func (t *TenantDaoImpl) DelByTenantID(tenantID string) error {
return nil
}
//TenantServicesDaoImpl 租户应用dao
// TenantServicesDaoImpl 租户应用dao
type TenantServicesDaoImpl struct {
DB *gorm.DB
}
@ -196,7 +196,7 @@ func (t *TenantServicesDaoImpl) GetServiceTypeByID(serviceID string) (*model.Ten
return &service, nil
}
//GetAllServicesID get all service sample info
// GetAllServicesID get all service sample info
func (t *TenantServicesDaoImpl) GetAllServicesID() ([]*model.TenantServices, error) {
var services []*model.TenantServices
if err := t.DB.Select("service_id,service_alias,tenant_id,app_id").Find(&services).Error; err != nil {
@ -218,7 +218,7 @@ func (t *TenantServicesDaoImpl) ListServicesByTenantID(tenantID string) ([]*mode
return services, nil
}
//UpdateDeployVersion update service current deploy version
// UpdateDeployVersion update service current deploy version
func (t *TenantServicesDaoImpl) UpdateDeployVersion(serviceID, deployversion string) error {
if err := t.DB.Exec("update tenant_services set deploy_version=? where service_id=?", deployversion, serviceID).Error; err != nil {
return err
@ -226,7 +226,7 @@ func (t *TenantServicesDaoImpl) UpdateDeployVersion(serviceID, deployversion str
return nil
}
//AddModel 添加租户应用
// AddModel 添加租户应用
func (t *TenantServicesDaoImpl) AddModel(mo model.Interface) error {
service := mo.(*model.TenantServices)
var oldService model.TenantServices
@ -240,7 +240,7 @@ func (t *TenantServicesDaoImpl) AddModel(mo model.Interface) error {
return nil
}
//UpdateModel 更新租户应用
// UpdateModel 更新租户应用
func (t *TenantServicesDaoImpl) UpdateModel(mo model.Interface) error {
service := mo.(*model.TenantServices)
if err := t.DB.Save(service).Error; err != nil {
@ -249,7 +249,7 @@ func (t *TenantServicesDaoImpl) UpdateModel(mo model.Interface) error {
return nil
}
//GetServiceByID 获取服务通过服务id
// GetServiceByID 获取服务通过服务id
func (t *TenantServicesDaoImpl) GetServiceByID(serviceID string) (*model.TenantServices, error) {
var service model.TenantServices
if err := t.DB.Where("service_id=?", serviceID).Find(&service).Error; err != nil {
@ -258,7 +258,7 @@ func (t *TenantServicesDaoImpl) GetServiceByID(serviceID string) (*model.TenantS
return &service, nil
}
//GetServiceByServiceAlias 获取服务通过服务别名
// GetServiceByServiceAlias 获取服务通过服务别名
func (t *TenantServicesDaoImpl) GetServiceByServiceAlias(serviceAlias string) (*model.TenantServices, error) {
var service model.TenantServices
if err := t.DB.Where("service_alias=?", serviceAlias).Find(&service).Error; err != nil {
@ -267,7 +267,7 @@ func (t *TenantServicesDaoImpl) GetServiceByServiceAlias(serviceAlias string) (*
return &service, nil
}
//GetServiceMemoryByTenantIDs get service memory by tenant ids
// GetServiceMemoryByTenantIDs get service memory by tenant ids
func (t *TenantServicesDaoImpl) GetServiceMemoryByTenantIDs(tenantIDs []string, runningServiceIDs []string) (map[string]map[string]interface{}, error) {
rows, err := t.DB.Raw("select tenant_id, sum(container_cpu) as cpu,sum(container_memory * replicas) as memory from tenant_services where tenant_id in (?) and service_id in (?) group by tenant_id", tenantIDs, runningServiceIDs).Rows()
if err != nil {
@ -294,7 +294,7 @@ func (t *TenantServicesDaoImpl) GetServiceMemoryByTenantIDs(tenantIDs []string,
return rc, nil
}
//GetServiceMemoryByServiceIDs get service memory by service ids
// GetServiceMemoryByServiceIDs get service memory by service ids
func (t *TenantServicesDaoImpl) GetServiceMemoryByServiceIDs(serviceIDs []string) (map[string]map[string]interface{}, error) {
rows, err := t.DB.Raw("select service_id, container_cpu as cpu, container_memory as memory from tenant_services where service_id in (?)", serviceIDs).Rows()
if err != nil {
@ -321,7 +321,7 @@ func (t *TenantServicesDaoImpl) GetServiceMemoryByServiceIDs(serviceIDs []string
return rc, nil
}
//GetPagedTenantService GetPagedTenantResource
// GetPagedTenantService GetPagedTenantResource
func (t *TenantServicesDaoImpl) GetPagedTenantService(offset, length int, serviceIDs []string) ([]map[string]interface{}, int, error) {
var count int
var service model.TenantServices
@ -391,7 +391,7 @@ func (t *TenantServicesDaoImpl) GetPagedTenantService(offset, length int, servic
return result, count, nil
}
//GetServiceAliasByIDs 获取应用别名
// GetServiceAliasByIDs 获取应用别名
func (t *TenantServicesDaoImpl) GetServiceAliasByIDs(uids []string) ([]*model.TenantServices, error) {
var services []*model.TenantServices
if err := t.DB.Where("service_id in (?)", uids).Select("service_alias,service_id").Find(&services).Error; err != nil {
@ -416,7 +416,7 @@ func (t *TenantServicesDaoImpl) GetWorkloadNameByIDs(uids []string) ([]*model.Co
return componentWorkload, nil
}
//GetServiceByIDs get some service by service ids
// GetServiceByIDs get some service by service ids
func (t *TenantServicesDaoImpl) GetServiceByIDs(uids []string) ([]*model.TenantServices, error) {
var services []*model.TenantServices
if err := t.DB.Where("service_id in (?)", uids).Find(&services).Error; err != nil {
@ -428,7 +428,7 @@ func (t *TenantServicesDaoImpl) GetServiceByIDs(uids []string) ([]*model.TenantS
return services, nil
}
//GetServiceByTenantIDAndServiceAlias 根据租户名和服务名
// GetServiceByTenantIDAndServiceAlias 根据租户名和服务名
func (t *TenantServicesDaoImpl) GetServiceByTenantIDAndServiceAlias(tenantID, serviceName string) (*model.TenantServices, error) {
var service model.TenantServices
if err := t.DB.Where("service_alias = ? and tenant_id=?", serviceName, tenantID).Find(&service).Error; err != nil {
@ -437,7 +437,7 @@ func (t *TenantServicesDaoImpl) GetServiceByTenantIDAndServiceAlias(tenantID, se
return &service, nil
}
//GetServicesByTenantID GetServicesByTenantID
// GetServicesByTenantID GetServicesByTenantID
func (t *TenantServicesDaoImpl) GetServicesByTenantID(tenantID string) ([]*model.TenantServices, error) {
var services []*model.TenantServices
if err := t.DB.Where("tenant_id=?", tenantID).Find(&services).Error; err != nil {
@ -449,7 +449,7 @@ func (t *TenantServicesDaoImpl) GetServicesByTenantID(tenantID string) ([]*model
return services, nil
}
//GetServicesByTenantIDs GetServicesByTenantIDs
// GetServicesByTenantIDs GetServicesByTenantIDs
func (t *TenantServicesDaoImpl) GetServicesByTenantIDs(tenantIDs []string) ([]*model.TenantServices, error) {
var services []*model.TenantServices
if err := t.DB.Where("tenant_id in (?)", tenantIDs).Find(&services).Error; err != nil {
@ -461,7 +461,7 @@ func (t *TenantServicesDaoImpl) GetServicesByTenantIDs(tenantIDs []string) ([]*m
return services, nil
}
//GetServicesAllInfoByTenantID GetServicesAllInfoByTenantID
// GetServicesAllInfoByTenantID GetServicesAllInfoByTenantID
func (t *TenantServicesDaoImpl) GetServicesAllInfoByTenantID(tenantID string) ([]*model.TenantServices, error) {
var services []*model.TenantServices
if err := t.DB.Where("tenant_id= ?", tenantID).Find(&services).Error; err != nil {
@ -511,7 +511,7 @@ func (t *TenantServicesDaoImpl) GetServiceIDsByAppID(appID string) (re []model.S
return
}
//GetServicesByServiceIDs Get Services By ServiceIDs
// GetServicesByServiceIDs Get Services By ServiceIDs
func (t *TenantServicesDaoImpl) GetServicesByServiceIDs(serviceIDs []string) ([]*model.TenantServices, error) {
var services []*model.TenantServices
if err := t.DB.Where("service_id in (?)", serviceIDs).Find(&services).Error; err != nil {
@ -523,7 +523,7 @@ func (t *TenantServicesDaoImpl) GetServicesByServiceIDs(serviceIDs []string) ([]
return services, nil
}
//SetTenantServiceStatus SetTenantServiceStatus
// SetTenantServiceStatus SetTenantServiceStatus
func (t *TenantServicesDaoImpl) SetTenantServiceStatus(serviceID, status string) error {
var service model.TenantServices
if status == "closed" || status == "undeploy" {
@ -538,7 +538,7 @@ func (t *TenantServicesDaoImpl) SetTenantServiceStatus(serviceID, status string)
return nil
}
//DeleteServiceByServiceID DeleteServiceByServiceID
// DeleteServiceByServiceID DeleteServiceByServiceID
func (t *TenantServicesDaoImpl) DeleteServiceByServiceID(serviceID string) error {
ts := &model.TenantServices{
ServiceID: serviceID,
@ -604,7 +604,7 @@ func (t *TenantServicesDaoImpl) DeleteByComponentIDs(tenantID, appID string, com
return nil
}
//IsK8sComponentNameDuplicate -
// IsK8sComponentNameDuplicate -
func (t *TenantServicesDaoImpl) IsK8sComponentNameDuplicate(appID, serviceID, k8sComponentName string) bool {
var count int64
if err := t.DB.Model(&model.TenantServices{}).Where("app_id=? and service_id<>? and k8s_component_name=?", appID, serviceID, k8sComponentName).Count(&count).Error; err != nil {
@ -614,12 +614,12 @@ func (t *TenantServicesDaoImpl) IsK8sComponentNameDuplicate(appID, serviceID, k8
return count > 0
}
//TenantServicesDeleteImpl TenantServiceDeleteImpl
// TenantServicesDeleteImpl TenantServiceDeleteImpl
type TenantServicesDeleteImpl struct {
DB *gorm.DB
}
//AddModel 添加已删除的应用
// AddModel 添加已删除的应用
func (t *TenantServicesDeleteImpl) AddModel(mo model.Interface) error {
service := mo.(*model.TenantServicesDelete)
var oldService model.TenantServicesDelete
@ -631,7 +631,7 @@ func (t *TenantServicesDeleteImpl) AddModel(mo model.Interface) error {
return nil
}
//UpdateModel 更新租户应用
// UpdateModel 更新租户应用
func (t *TenantServicesDeleteImpl) UpdateModel(mo model.Interface) error {
service := mo.(*model.TenantServicesDelete)
if err := t.DB.Save(service).Error; err != nil {
@ -669,12 +669,12 @@ func (t *TenantServicesDeleteImpl) List() ([]*model.TenantServicesDelete, error)
return components, nil
}
//TenantServicesPortDaoImpl 租户应用端口操作
// TenantServicesPortDaoImpl 租户应用端口操作
type TenantServicesPortDaoImpl struct {
DB *gorm.DB
}
//AddModel 添加应用端口
// AddModel 添加应用端口
func (t *TenantServicesPortDaoImpl) AddModel(mo model.Interface) error {
port := mo.(*model.TenantServicesPort)
var oldPort model.TenantServicesPort
@ -688,7 +688,7 @@ func (t *TenantServicesPortDaoImpl) AddModel(mo model.Interface) error {
return nil
}
//UpdateModel 更新租户
// UpdateModel 更新租户
func (t *TenantServicesPortDaoImpl) UpdateModel(mo model.Interface) error {
port := mo.(*model.TenantServicesPort)
if port.ID == 0 {
@ -736,7 +736,7 @@ func (t *TenantServicesPortDaoImpl) CreateOrUpdatePortsInBatch(ports []*model.Te
return nil
}
//DeleteModel 删除端口
// DeleteModel 删除端口
func (t *TenantServicesPortDaoImpl) DeleteModel(serviceID string, args ...interface{}) error {
if len(args) < 1 {
return fmt.Errorf("can not provide containerPort")
@ -765,7 +765,7 @@ func (t *TenantServicesPortDaoImpl) GetByTenantAndName(tenantID, name string) (*
return &port, nil
}
//GetPortsByServiceID 通过服务获取port
// GetPortsByServiceID 通过服务获取port
func (t *TenantServicesPortDaoImpl) GetPortsByServiceID(serviceID string) ([]*model.TenantServicesPort, error) {
var oldPort []*model.TenantServicesPort
if err := t.DB.Where("service_id = ?", serviceID).Find(&oldPort).Error; err != nil {
@ -777,7 +777,7 @@ func (t *TenantServicesPortDaoImpl) GetPortsByServiceID(serviceID string) ([]*mo
return oldPort, nil
}
//GetOuterPorts 获取对外端口
// GetOuterPorts 获取对外端口
func (t *TenantServicesPortDaoImpl) GetOuterPorts(serviceID string) ([]*model.TenantServicesPort, error) {
var oldPort []*model.TenantServicesPort
if err := t.DB.Where("service_id = ? and is_outer_service=?", serviceID, true).Find(&oldPort).Error; err != nil {
@ -789,7 +789,7 @@ func (t *TenantServicesPortDaoImpl) GetOuterPorts(serviceID string) ([]*model.Te
return oldPort, nil
}
//GetInnerPorts 获取对内端口
// GetInnerPorts 获取对内端口
func (t *TenantServicesPortDaoImpl) GetInnerPorts(serviceID string) ([]*model.TenantServicesPort, error) {
var oldPort []*model.TenantServicesPort
if err := t.DB.Where("service_id = ? and is_inner_service=?", serviceID, true).Find(&oldPort).Error; err != nil {
@ -798,7 +798,7 @@ func (t *TenantServicesPortDaoImpl) GetInnerPorts(serviceID string) ([]*model.Te
return oldPort, nil
}
//GetPort get port
// GetPort get port
func (t *TenantServicesPortDaoImpl) GetPort(serviceID string, port int) (*model.TenantServicesPort, error) {
var oldPort model.TenantServicesPort
if err := t.DB.Where("service_id = ? and container_port=?", serviceID, port).Find(&oldPort).Error; err != nil {
@ -820,7 +820,7 @@ func (t *TenantServicesPortDaoImpl) GetOpenedPorts(serviceID string) ([]*model.T
return ports, nil
}
//DELPortsByServiceID DELPortsByServiceID
// DELPortsByServiceID DELPortsByServiceID
func (t *TenantServicesPortDaoImpl) DELPortsByServiceID(serviceID string) error {
var port model.TenantServicesPort
if err := t.DB.Where("service_id=?", serviceID).Delete(&port).Error; err != nil {
@ -842,7 +842,7 @@ func (t *TenantServicesPortDaoImpl) HasOpenPort(sid string) bool {
return true
}
//GetDepUDPPort get all depend service udp port
// GetDepUDPPort get all depend service udp port
func (t *TenantServicesPortDaoImpl) GetDepUDPPort(serviceID string) ([]*model.TenantServicesPort, error) {
var portInfos []*model.TenantServicesPort
var port model.TenantServicesPort
@ -882,12 +882,12 @@ func (t *TenantServicesPortDaoImpl) ListByK8sServiceNames(k8sServiceNames []stri
return ports, nil
}
//TenantServiceRelationDaoImpl TenantServiceRelationDaoImpl
// TenantServiceRelationDaoImpl TenantServiceRelationDaoImpl
type TenantServiceRelationDaoImpl struct {
DB *gorm.DB
}
//AddModel 添加应用依赖关系
// AddModel 添加应用依赖关系
func (t *TenantServiceRelationDaoImpl) AddModel(mo model.Interface) error {
relation := mo.(*model.TenantServiceRelation)
var oldRelation model.TenantServiceRelation
@ -901,7 +901,7 @@ func (t *TenantServiceRelationDaoImpl) AddModel(mo model.Interface) error {
return nil
}
//UpdateModel 更新应用依赖关系
// UpdateModel 更新应用依赖关系
func (t *TenantServiceRelationDaoImpl) UpdateModel(mo model.Interface) error {
relation := mo.(*model.TenantServiceRelation)
if relation.ID == 0 {
@ -913,7 +913,7 @@ func (t *TenantServiceRelationDaoImpl) UpdateModel(mo model.Interface) error {
return nil
}
//DeleteModel 删除依赖
// DeleteModel 删除依赖
func (t *TenantServiceRelationDaoImpl) DeleteModel(serviceID string, args ...interface{}) error {
depServiceID := args[0].(string)
relation := &model.TenantServiceRelation{
@ -927,7 +927,7 @@ func (t *TenantServiceRelationDaoImpl) DeleteModel(serviceID string, args ...int
return nil
}
//DeleteRelationByDepID DeleteRelationByDepID
// DeleteRelationByDepID DeleteRelationByDepID
func (t *TenantServiceRelationDaoImpl) DeleteRelationByDepID(serviceID, depID string) error {
relation := &model.TenantServiceRelation{
ServiceID: serviceID,
@ -939,7 +939,7 @@ func (t *TenantServiceRelationDaoImpl) DeleteRelationByDepID(serviceID, depID st
return nil
}
//DeleteByComponentIDs -
// DeleteByComponentIDs -
func (t *TenantServiceRelationDaoImpl) DeleteByComponentIDs(componentIDs []string) error {
return t.DB.Where("service_id in (?)", componentIDs).Delete(&model.TenantServiceRelation{}).Error
}
@ -973,7 +973,7 @@ func (t *TenantServiceRelationDaoImpl) CreateOrUpdateRelationsInBatch(relations
return nil
}
//GetTenantServiceRelations 获取应用依赖关系
// GetTenantServiceRelations 获取应用依赖关系
func (t *TenantServiceRelationDaoImpl) GetTenantServiceRelations(serviceID string) ([]*model.TenantServiceRelation, error) {
var oldRelation []*model.TenantServiceRelation
if err := t.DB.Where("service_id = ?", serviceID).Find(&oldRelation).Error; err != nil {
@ -995,7 +995,7 @@ func (t *TenantServiceRelationDaoImpl) ListByServiceIDs(serviceIDs []string) ([]
return relations, nil
}
//HaveRelations 是否有依赖
// HaveRelations 是否有依赖
func (t *TenantServiceRelationDaoImpl) HaveRelations(serviceID string) bool {
var oldRelation []*model.TenantServiceRelation
if err := t.DB.Where("service_id = ?", serviceID).Find(&oldRelation).Error; err != nil {
@ -1007,7 +1007,7 @@ func (t *TenantServiceRelationDaoImpl) HaveRelations(serviceID string) bool {
return false
}
//DELRelationsByServiceID DELRelationsByServiceID
// DELRelationsByServiceID DELRelationsByServiceID
func (t *TenantServiceRelationDaoImpl) DELRelationsByServiceID(serviceID string) error {
relation := &model.TenantServiceRelation{
ServiceID: serviceID,
@ -1019,7 +1019,7 @@ func (t *TenantServiceRelationDaoImpl) DELRelationsByServiceID(serviceID string)
return nil
}
//GetTenantServiceRelationsByDependServiceID 获取全部依赖当前服务的应用
// GetTenantServiceRelationsByDependServiceID 获取全部依赖当前服务的应用
func (t *TenantServiceRelationDaoImpl) GetTenantServiceRelationsByDependServiceID(dependServiceID string) ([]*model.TenantServiceRelation, error) {
var oldRelation []*model.TenantServiceRelation
if err := t.DB.Where("dep_service_id = ?", dependServiceID).Find(&oldRelation).Error; err != nil {
@ -1028,12 +1028,12 @@ func (t *TenantServiceRelationDaoImpl) GetTenantServiceRelationsByDependServiceI
return oldRelation, nil
}
//TenantServiceEnvVarDaoImpl TenantServiceEnvVarDaoImpl
// TenantServiceEnvVarDaoImpl TenantServiceEnvVarDaoImpl
type TenantServiceEnvVarDaoImpl struct {
DB *gorm.DB
}
//AddModel 添加应用环境变量
// AddModel 添加应用环境变量
func (t *TenantServiceEnvVarDaoImpl) AddModel(mo model.Interface) error {
relation := mo.(*model.TenantServiceEnvVar)
var oldRelation model.TenantServiceEnvVar
@ -1050,7 +1050,7 @@ func (t *TenantServiceEnvVarDaoImpl) AddModel(mo model.Interface) error {
return nil
}
//UpdateModel update env support attr_value\is_change\scope
// UpdateModel update env support attr_value\is_change\scope
func (t *TenantServiceEnvVarDaoImpl) UpdateModel(mo model.Interface) error {
env := mo.(*model.TenantServiceEnvVar)
return t.DB.Table(env.TableName()).Where("service_id=? and attr_name = ?", env.ServiceID, env.AttrName).Update(map[string]interface{}{
@ -1060,7 +1060,7 @@ func (t *TenantServiceEnvVarDaoImpl) UpdateModel(mo model.Interface) error {
}).Error
}
//DeleteByComponentIDs -
// DeleteByComponentIDs -
func (t *TenantServiceEnvVarDaoImpl) DeleteByComponentIDs(componentIDs []string) error {
return t.DB.Where("service_id in (?)", componentIDs).Delete(&model.TenantServiceEnvVar{}).Error
}
@ -1101,7 +1101,7 @@ func (t *TenantServiceEnvVarDaoImpl) CreateOrUpdateEnvsInBatch(envs []*model.Ten
return nil
}
//DeleteModel 删除env
// DeleteModel 删除env
func (t *TenantServiceEnvVarDaoImpl) DeleteModel(serviceID string, args ...interface{}) error {
envName := args[0].(string)
relation := &model.TenantServiceEnvVar{
@ -1114,7 +1114,7 @@ func (t *TenantServiceEnvVarDaoImpl) DeleteModel(serviceID string, args ...inter
return nil
}
//GetDependServiceEnvs 获取依赖服务的环境变量
// GetDependServiceEnvs 获取依赖服务的环境变量
func (t *TenantServiceEnvVarDaoImpl) GetDependServiceEnvs(serviceIDs []string, scopes []string) ([]*model.TenantServiceEnvVar, error) {
var envs []*model.TenantServiceEnvVar
if err := t.DB.Where("service_id in (?) and scope in (?)", serviceIDs, scopes).Find(&envs).Error; err != nil {
@ -1126,7 +1126,7 @@ func (t *TenantServiceEnvVarDaoImpl) GetDependServiceEnvs(serviceIDs []string, s
return envs, nil
}
//GetServiceEnvs 获取服务环境变量
// GetServiceEnvs 获取服务环境变量
func (t *TenantServiceEnvVarDaoImpl) GetServiceEnvs(serviceID string, scopes []string) ([]*model.TenantServiceEnvVar, error) {
var envs []*model.TenantServiceEnvVar
if scopes == nil {
@ -1147,7 +1147,7 @@ func (t *TenantServiceEnvVarDaoImpl) GetServiceEnvs(serviceID string, scopes []s
return envs, nil
}
//GetEnv 获取某个环境变量
// GetEnv 获取某个环境变量
func (t *TenantServiceEnvVarDaoImpl) GetEnv(serviceID, envName string) (*model.TenantServiceEnvVar, error) {
var env model.TenantServiceEnvVar
if err := t.DB.Where("service_id=? and attr_name=? ", serviceID, envName).Find(&env).Error; err != nil {
@ -1156,7 +1156,7 @@ func (t *TenantServiceEnvVarDaoImpl) GetEnv(serviceID, envName string) (*model.T
return &env, nil
}
//DELServiceEnvsByServiceID 通过serviceID 删除envs
// DELServiceEnvsByServiceID 通过serviceID 删除envs
func (t *TenantServiceEnvVarDaoImpl) DELServiceEnvsByServiceID(serviceID string) error {
var env model.TenantServiceEnvVar
if err := t.DB.Where("service_id=?", serviceID).Find(&env).Error; err != nil {
@ -1177,12 +1177,12 @@ func (t *TenantServiceEnvVarDaoImpl) DelByServiceIDAndScope(sid, scope string) e
return nil
}
//TenantServiceMountRelationDaoImpl 依赖存储
// TenantServiceMountRelationDaoImpl 依赖存储
type TenantServiceMountRelationDaoImpl struct {
DB *gorm.DB
}
//AddModel 添加应用依赖挂载
// AddModel 添加应用依赖挂载
func (t *TenantServiceMountRelationDaoImpl) AddModel(mo model.Interface) error {
relation := mo.(*model.TenantServiceMountRelation)
var oldRelation model.TenantServiceMountRelation
@ -1196,7 +1196,7 @@ func (t *TenantServiceMountRelationDaoImpl) AddModel(mo model.Interface) error {
return nil
}
//UpdateModel 更新应用依赖挂载
// UpdateModel 更新应用依赖挂载
func (t *TenantServiceMountRelationDaoImpl) UpdateModel(mo model.Interface) error {
relation := mo.(*model.TenantServiceMountRelation)
if relation.ID == 0 {
@ -1208,7 +1208,7 @@ func (t *TenantServiceMountRelationDaoImpl) UpdateModel(mo model.Interface) erro
return nil
}
//DElTenantServiceMountRelationByServiceAndName DElTenantServiceMountRelationByServiceAndName
// DElTenantServiceMountRelationByServiceAndName DElTenantServiceMountRelationByServiceAndName
func (t *TenantServiceMountRelationDaoImpl) DElTenantServiceMountRelationByServiceAndName(serviceID, name string) error {
var relation model.TenantServiceMountRelation
if err := t.DB.Where("service_id=? and volume_name=? ", serviceID, name).Find(&relation).Error; err != nil {
@ -1220,7 +1220,7 @@ func (t *TenantServiceMountRelationDaoImpl) DElTenantServiceMountRelationByServi
return nil
}
//DElTenantServiceMountRelationByDepService del mount relation
// DElTenantServiceMountRelationByDepService del mount relation
func (t *TenantServiceMountRelationDaoImpl) DElTenantServiceMountRelationByDepService(serviceID, depServiceID string) error {
var relation model.TenantServiceMountRelation
if err := t.DB.Where("service_id=? and dep_service_id=?", serviceID, depServiceID).Find(&relation).Error; err != nil {
@ -1232,7 +1232,7 @@ func (t *TenantServiceMountRelationDaoImpl) DElTenantServiceMountRelationByDepSe
return nil
}
//DELTenantServiceMountRelationByServiceID DELTenantServiceMountRelationByServiceID
// DELTenantServiceMountRelationByServiceID DELTenantServiceMountRelationByServiceID
func (t *TenantServiceMountRelationDaoImpl) DELTenantServiceMountRelationByServiceID(serviceID string) error {
var relation model.TenantServiceMountRelation
if err := t.DB.Where("service_id=?", serviceID).Delete(&relation).Error; err != nil {
@ -1241,7 +1241,7 @@ func (t *TenantServiceMountRelationDaoImpl) DELTenantServiceMountRelationByServi
return nil
}
//GetTenantServiceMountRelationsByService 获取应用的所有挂载依赖
// GetTenantServiceMountRelationsByService 获取应用的所有挂载依赖
func (t *TenantServiceMountRelationDaoImpl) GetTenantServiceMountRelationsByService(serviceID string) ([]*model.TenantServiceMountRelation, error) {
var relations []*model.TenantServiceMountRelation
if err := t.DB.Where("service_id=? ", serviceID).Find(&relations).Error; err != nil {
@ -1287,12 +1287,12 @@ func (t *TenantServiceMountRelationDaoImpl) CreateOrUpdateVolumeRelsInBatch(volR
return nil
}
//TenantServiceVolumeDaoImpl 应用存储
// TenantServiceVolumeDaoImpl 应用存储
type TenantServiceVolumeDaoImpl struct {
DB *gorm.DB
}
//GetAllVolumes 获取全部存储信息
// GetAllVolumes 获取全部存储信息
func (t *TenantServiceVolumeDaoImpl) GetAllVolumes() ([]*model.TenantServiceVolume, error) {
var volumes []*model.TenantServiceVolume
if err := t.DB.Find(&volumes).Error; err != nil {
@ -1304,21 +1304,27 @@ func (t *TenantServiceVolumeDaoImpl) GetAllVolumes() ([]*model.TenantServiceVolu
return volumes, nil
}
//AddModel 添加应用挂载
// AddModel 添加应用挂载
func (t *TenantServiceVolumeDaoImpl) AddModel(mo model.Interface) error {
volume := mo.(*model.TenantServiceVolume)
var oldvolume model.TenantServiceVolume
if ok := t.DB.Where("(volume_name=? or volume_path = ?) and service_id=?", volume.VolumeName, volume.VolumePath, volume.ServiceID).Find(&oldvolume).RecordNotFound(); ok {
if volume.VolumeType == model.VMVolumeType.String() {
if err := t.DB.Create(volume).Error; err != nil {
return err
}
} else {
return fmt.Errorf("service %s volume name %s path %s is exist ", volume.ServiceID, volume.VolumeName, volume.VolumePath)
if ok := t.DB.Where("(volume_name=? or volume_path = ?) and service_id=?", volume.VolumeName, volume.VolumePath, volume.ServiceID).Find(&oldvolume).RecordNotFound(); ok {
if err := t.DB.Create(volume).Error; err != nil {
return err
}
} else {
return fmt.Errorf("service %s volume name %s path %s is exist ", volume.ServiceID, volume.VolumeName, volume.VolumePath)
}
}
return nil
}
//UpdateModel 更<><E69BB4>应用挂载
// UpdateModel 更<><E69BB4>应用挂载
func (t *TenantServiceVolumeDaoImpl) UpdateModel(mo model.Interface) error {
volume := mo.(*model.TenantServiceVolume)
if volume.ID == 0 {
@ -1330,7 +1336,7 @@ func (t *TenantServiceVolumeDaoImpl) UpdateModel(mo model.Interface) error {
return nil
}
//GetTenantServiceVolumesByServiceID 获取应用挂载
// GetTenantServiceVolumesByServiceID 获取应用挂载
func (t *TenantServiceVolumeDaoImpl) GetTenantServiceVolumesByServiceID(serviceID string) ([]*model.TenantServiceVolume, error) {
var volumes []*model.TenantServiceVolume
if err := t.DB.Where("service_id=? ", serviceID).Find(&volumes).Error; err != nil {
@ -1351,12 +1357,12 @@ func (t *TenantServiceVolumeDaoImpl) ListVolumesByComponentIDs(componentIDs []st
return volumes, nil
}
//DeleteByVolumeIDs -
// DeleteByVolumeIDs -
func (t *TenantServiceVolumeDaoImpl) DeleteByVolumeIDs(volumeIDs []uint) error {
return t.DB.Where("ID in (?)", volumeIDs).Delete(&model.TenantServiceVolume{}).Error
}
//DeleteByComponentIDs -
// DeleteByComponentIDs -
func (t *TenantServiceVolumeDaoImpl) DeleteByComponentIDs(componentIDs []string) error {
return t.DB.Where("service_id in (?)", componentIDs).Delete(&model.TenantServiceVolume{}).Error
}
@ -1390,7 +1396,7 @@ func (t *TenantServiceVolumeDaoImpl) CreateOrUpdateVolumesInBatch(volumes []*mod
return nil
}
//DeleteModel 删除挂载
// DeleteModel 删除挂载
func (t *TenantServiceVolumeDaoImpl) DeleteModel(serviceID string, args ...interface{}) error {
var volume model.TenantServiceVolume
volumeName := args[0].(string)
@ -1403,7 +1409,7 @@ func (t *TenantServiceVolumeDaoImpl) DeleteModel(serviceID string, args ...inter
return nil
}
//DeleteByServiceIDAndVolumePath 删除挂载通过挂载的目录
// DeleteByServiceIDAndVolumePath 删除挂载通过挂载的目录
func (t *TenantServiceVolumeDaoImpl) DeleteByServiceIDAndVolumePath(serviceID string, volumePath string) error {
var volume model.TenantServiceVolume
if err := t.DB.Where("volume_path = ? and service_id=?", volumePath, serviceID).Find(&volume).Error; err != nil {
@ -1415,7 +1421,7 @@ func (t *TenantServiceVolumeDaoImpl) DeleteByServiceIDAndVolumePath(serviceID st
return nil
}
//GetVolumeByServiceIDAndName 获取存储信息
// GetVolumeByServiceIDAndName 获取存储信息
func (t *TenantServiceVolumeDaoImpl) GetVolumeByServiceIDAndName(serviceID, name string) (*model.TenantServiceVolume, error) {
var volume model.TenantServiceVolume
if err := t.DB.Where("service_id=? and volume_name=? ", serviceID, name).Find(&volume).Error; err != nil {
@ -1424,7 +1430,7 @@ func (t *TenantServiceVolumeDaoImpl) GetVolumeByServiceIDAndName(serviceID, name
return &volume, nil
}
//GetVolumeByID get volume by id
// GetVolumeByID get volume by id
func (t *TenantServiceVolumeDaoImpl) GetVolumeByID(id int) (*model.TenantServiceVolume, error) {
var volume model.TenantServiceVolume
if err := t.DB.Where("ID=?", id).Find(&volume).Error; err != nil {
@ -1436,7 +1442,7 @@ func (t *TenantServiceVolumeDaoImpl) GetVolumeByID(id int) (*model.TenantService
return &volume, nil
}
//DeleteTenantServiceVolumesByServiceID 删除挂载
// DeleteTenantServiceVolumesByServiceID 删除挂载
func (t *TenantServiceVolumeDaoImpl) DeleteTenantServiceVolumesByServiceID(serviceID string) error {
var volume model.TenantServiceVolume
if err := t.DB.Where("service_id=? ", serviceID).Delete(&volume).Error; err != nil {
@ -1451,7 +1457,7 @@ func (t *TenantServiceVolumeDaoImpl) DelShareableBySID(sid string) error {
return t.DB.Where(query, sid).Delete(&model.TenantServiceVolume{}).Error
}
//TenantServiceConfigFileDaoImpl is a implementation of TenantServiceConfigFileDao
// TenantServiceConfigFileDaoImpl is a implementation of TenantServiceConfigFileDao
type TenantServiceConfigFileDaoImpl struct {
DB *gorm.DB
}
@ -1552,12 +1558,12 @@ func (t *TenantServiceConfigFileDaoImpl) CreateOrUpdateConfigFilesInBatch(config
return nil
}
//TenantServiceLBMappingPortDaoImpl stream服务映射
// TenantServiceLBMappingPortDaoImpl stream服务映射
type TenantServiceLBMappingPortDaoImpl struct {
DB *gorm.DB
}
//AddModel 添加应用端口映射
// AddModel 添加应用端口映射
func (t *TenantServiceLBMappingPortDaoImpl) AddModel(mo model.Interface) error {
mapPort := mo.(*model.TenantServiceLBMappingPort)
var oldMapPort model.TenantServiceLBMappingPort
@ -1571,7 +1577,7 @@ func (t *TenantServiceLBMappingPortDaoImpl) AddModel(mo model.Interface) error {
return nil
}
//UpdateModel 更新应用端口映射
// UpdateModel 更新应用端口映射
func (t *TenantServiceLBMappingPortDaoImpl) UpdateModel(mo model.Interface) error {
mapPort := mo.(*model.TenantServiceLBMappingPort)
if mapPort.ID == 0 {
@ -1583,7 +1589,7 @@ func (t *TenantServiceLBMappingPortDaoImpl) UpdateModel(mo model.Interface) erro
return nil
}
//GetTenantServiceLBMappingPort 获取端口映射
// GetTenantServiceLBMappingPort 获取端口映射
func (t *TenantServiceLBMappingPortDaoImpl) GetTenantServiceLBMappingPort(serviceID string, containerPort int) (*model.TenantServiceLBMappingPort, error) {
var mapPort model.TenantServiceLBMappingPort
if err := t.DB.Where("service_id=? and container_port=?", serviceID, containerPort).Find(&mapPort).Error; err != nil {
@ -1610,7 +1616,7 @@ func (t *TenantServiceLBMappingPortDaoImpl) GetLBPortsASC() ([]*model.TenantServ
return ports, nil
}
//CreateTenantServiceLBMappingPort 创建负载均衡VS端口,如果端口分配已存在,直接返回
// CreateTenantServiceLBMappingPort 创建负载均衡VS端口,如果端口分配已存在,直接返回
func (t *TenantServiceLBMappingPortDaoImpl) CreateTenantServiceLBMappingPort(serviceID string, containerPort int) (*model.TenantServiceLBMappingPort, error) {
var mapPorts []*model.TenantServiceLBMappingPort
var mapPort model.TenantServiceLBMappingPort
@ -1695,7 +1701,7 @@ func (t *TenantServiceLBMappingPortDaoImpl) CreateTenantServiceLBMappingPort(ser
return nil, fmt.Errorf("no more lb port can be use,max port is %d", maxPort)
}
//GetTenantServiceLBMappingPortByService 获取端口映射
// GetTenantServiceLBMappingPortByService 获取端口映射
func (t *TenantServiceLBMappingPortDaoImpl) GetTenantServiceLBMappingPortByService(serviceID string) ([]*model.TenantServiceLBMappingPort, error) {
var mapPort []*model.TenantServiceLBMappingPort
if err := t.DB.Where("service_id=?", serviceID).Find(&mapPort).Error; err != nil {
@ -1704,7 +1710,7 @@ func (t *TenantServiceLBMappingPortDaoImpl) GetTenantServiceLBMappingPortByServi
return mapPort, nil
}
//DELServiceLBMappingPortByServiceID DELServiceLBMappingPortByServiceID
// DELServiceLBMappingPortByServiceID DELServiceLBMappingPortByServiceID
func (t *TenantServiceLBMappingPortDaoImpl) DELServiceLBMappingPortByServiceID(serviceID string) error {
mapPorts := &model.TenantServiceLBMappingPort{
ServiceID: serviceID,
@ -1715,7 +1721,7 @@ func (t *TenantServiceLBMappingPortDaoImpl) DELServiceLBMappingPortByServiceID(s
return nil
}
//DELServiceLBMappingPortByServiceIDAndPort DELServiceLBMappingPortByServiceIDAndPort
// DELServiceLBMappingPortByServiceIDAndPort DELServiceLBMappingPortByServiceIDAndPort
func (t *TenantServiceLBMappingPortDaoImpl) DELServiceLBMappingPortByServiceIDAndPort(serviceID string, lbport int) error {
var mapPorts model.TenantServiceLBMappingPort
if err := t.DB.Where("service_id=? and port=?", serviceID, lbport).Delete(&mapPorts).Error; err != nil {
@ -1739,12 +1745,12 @@ func (t *TenantServiceLBMappingPortDaoImpl) PortExists(port int) bool {
return !t.DB.Where("port=?", port).Find(&mapPorts).RecordNotFound()
}
//ServiceLabelDaoImpl ServiceLabelDaoImpl
// ServiceLabelDaoImpl ServiceLabelDaoImpl
type ServiceLabelDaoImpl struct {
DB *gorm.DB
}
//AddModel 添加应用Label
// AddModel 添加应用Label
func (t *ServiceLabelDaoImpl) AddModel(mo model.Interface) error {
label := mo.(*model.TenantServiceLable)
var oldLabel model.TenantServiceLable
@ -1758,7 +1764,7 @@ func (t *ServiceLabelDaoImpl) AddModel(mo model.Interface) error {
return nil
}
//UpdateModel 更新应用Label
// UpdateModel 更新应用Label
func (t *ServiceLabelDaoImpl) UpdateModel(mo model.Interface) error {
label := mo.(*model.TenantServiceLable)
if label.ID == 0 {
@ -1770,7 +1776,7 @@ func (t *ServiceLabelDaoImpl) UpdateModel(mo model.Interface) error {
return nil
}
//DeleteModel 删除应用label
// DeleteModel 删除应用label
func (t *ServiceLabelDaoImpl) DeleteModel(serviceID string, args ...interface{}) error {
label := &model.TenantServiceLable{
ServiceID: serviceID,
@ -1784,7 +1790,7 @@ func (t *ServiceLabelDaoImpl) DeleteModel(serviceID string, args ...interface{})
return nil
}
//DeleteLabelByServiceID 删除应用全部label
// DeleteLabelByServiceID 删除应用全部label
func (t *ServiceLabelDaoImpl) DeleteLabelByServiceID(serviceID string) error {
label := &model.TenantServiceLable{
ServiceID: serviceID,
@ -1795,7 +1801,7 @@ func (t *ServiceLabelDaoImpl) DeleteLabelByServiceID(serviceID string) error {
return nil
}
//GetTenantServiceLabel GetTenantServiceLabel
// GetTenantServiceLabel GetTenantServiceLabel
func (t *ServiceLabelDaoImpl) GetTenantServiceLabel(serviceID string) ([]*model.TenantServiceLable, error) {
var labels []*model.TenantServiceLable
if err := t.DB.Where("service_id=?", serviceID).Find(&labels).Error; err != nil {
@ -1807,7 +1813,7 @@ func (t *ServiceLabelDaoImpl) GetTenantServiceLabel(serviceID string) ([]*model.
return labels, nil
}
//GetTenantServiceNodeSelectorLabel GetTenantServiceNodeSelectorLabel
// GetTenantServiceNodeSelectorLabel GetTenantServiceNodeSelectorLabel
func (t *ServiceLabelDaoImpl) GetTenantServiceNodeSelectorLabel(serviceID string) ([]*model.TenantServiceLable, error) {
var labels []*model.TenantServiceLable
if err := t.DB.Where("service_id=? and label_key=?", serviceID, model.LabelKeyNodeSelector).Find(&labels).Error; err != nil {
@ -1829,7 +1835,7 @@ func (t *ServiceLabelDaoImpl) GetLabelByNodeSelectorKey(serviceID string, labelV
return &label, nil
}
//GetTenantNodeAffinityLabel returns TenantServiceLable matching serviceID and LabelKeyNodeAffinity
// GetTenantNodeAffinityLabel returns TenantServiceLable matching serviceID and LabelKeyNodeAffinity
func (t *ServiceLabelDaoImpl) GetTenantNodeAffinityLabel(serviceID string) (*model.TenantServiceLable, error) {
var label model.TenantServiceLable
if err := t.DB.Where("service_id=? and label_key = ?", serviceID, model.LabelKeyNodeAffinity).
@ -1842,7 +1848,7 @@ func (t *ServiceLabelDaoImpl) GetTenantNodeAffinityLabel(serviceID string) (*mod
return &label, nil
}
//GetTenantServiceAffinityLabel GetTenantServiceAffinityLabel
// GetTenantServiceAffinityLabel GetTenantServiceAffinityLabel
func (t *ServiceLabelDaoImpl) GetTenantServiceAffinityLabel(serviceID string) ([]*model.TenantServiceLable, error) {
var labels []*model.TenantServiceLable
if err := t.DB.Where("service_id=? and label_key in (?)", serviceID, []string{model.LabelKeyNodeSelector, model.LabelKeyNodeAffinity,
@ -1855,7 +1861,7 @@ func (t *ServiceLabelDaoImpl) GetTenantServiceAffinityLabel(serviceID string) ([
return labels, nil
}
//GetTenantServiceTypeLabel GetTenantServiceTypeLabel
// GetTenantServiceTypeLabel GetTenantServiceTypeLabel
// no usages func. get tenant service type use TenantServiceDao.GetServiceTypeByID(serviceID string)
func (t *ServiceLabelDaoImpl) GetTenantServiceTypeLabel(serviceID string) (*model.TenantServiceLable, error) {
var label model.TenantServiceLable
@ -1871,7 +1877,7 @@ func (t *ServiceLabelDaoImpl) GetPrivilegedLabel(serviceID string) (*model.Tenan
return &label, nil
}
//DelTenantServiceLabelsByLabelValuesAndServiceID DELTenantServiceLabelsByLabelvaluesAndServiceID
// DelTenantServiceLabelsByLabelValuesAndServiceID DELTenantServiceLabelsByLabelvaluesAndServiceID
func (t *ServiceLabelDaoImpl) DelTenantServiceLabelsByLabelValuesAndServiceID(serviceID string) error {
var label model.TenantServiceLable
if err := t.DB.Where("service_id=? and label_value=?", serviceID, model.LabelKeyNodeSelector).Delete(&label).Error; err != nil {
@ -1880,7 +1886,7 @@ func (t *ServiceLabelDaoImpl) DelTenantServiceLabelsByLabelValuesAndServiceID(se
return nil
}
//DelTenantServiceLabelsByServiceIDKeyValue deletes labels
// DelTenantServiceLabelsByServiceIDKeyValue deletes labels
func (t *ServiceLabelDaoImpl) DelTenantServiceLabelsByServiceIDKeyValue(serviceID string, labelKey string,
labelValue string) error {
var label model.TenantServiceLable
@ -1891,7 +1897,7 @@ func (t *ServiceLabelDaoImpl) DelTenantServiceLabelsByServiceIDKeyValue(serviceI
return nil
}
//DelTenantServiceLabelsByServiceIDKey deletes labels by serviceID and labelKey
// DelTenantServiceLabelsByServiceIDKey deletes labels by serviceID and labelKey
func (t *ServiceLabelDaoImpl) DelTenantServiceLabelsByServiceIDKey(serviceID string, labelKey string) error {
var label model.TenantServiceLable
if err := t.DB.Where("service_id=? and label_key=?", serviceID, labelKey).Delete(&label).Error; err != nil {

View File

@ -36,7 +36,7 @@ import (
"github.com/sirupsen/logrus"
)
//CallbackUpdate 每次返还变化
// CallbackUpdate 每次返还变化
type CallbackUpdate interface {
//TODO:
//weight自动发现更改实现暂时不 Ready
@ -45,21 +45,21 @@ type CallbackUpdate interface {
Error(error)
}
//Callback 每次返回全部节点
// Callback 每次返回全部节点
type Callback interface {
UpdateEndpoints(endpoints ...*config.Endpoint)
//when watch occurred error,will exec this method
Error(error)
}
//Discover 后端服务自动发现
// Discover 后端服务自动发现
type Discover interface {
AddProject(name string, callback Callback)
AddUpdateProject(name string, callback CallbackUpdate)
Stop()
}
//GetDiscover 获取服务发现管理器
// GetDiscover 获取服务发现管理器
func GetDiscover(opt config.DiscoverConfig) (Discover, error) {
if opt.Ctx == nil {
opt.Ctx = context.Background()

View File

@ -31,7 +31,7 @@ import (
"github.com/sirupsen/logrus"
)
//KeepAlive 服务注册
// KeepAlive 服务注册
type KeepAlive struct {
cancel context.CancelFunc
EtcdClentArgs *etcdutil.ClientArgs
@ -44,7 +44,7 @@ type KeepAlive struct {
etcdClient *client.Client
}
//CreateKeepAlive create keepalive for server
// CreateKeepAlive create keepalive for server
func CreateKeepAlive(etcdClientArgs *etcdutil.ClientArgs, serverName string, hostName string, HostIP string, Port int) (*KeepAlive, error) {
if serverName == "" || Port == 0 {
return nil, fmt.Errorf("servername or serverport can not be empty")
@ -74,7 +74,7 @@ func CreateKeepAlive(etcdClientArgs *etcdutil.ClientArgs, serverName string, hos
}, nil
}
//Start 开始
// Start 开始
func (k *KeepAlive) Start() error {
duration := time.Duration(k.TTL) * time.Second
timer := time.NewTimer(duration)
@ -140,7 +140,7 @@ func (k *KeepAlive) reg() error {
return nil
}
//Stop 结束
// Stop 结束
func (k *KeepAlive) Stop() error {
close(k.Done)
defer k.cancel()

View File

@ -38,7 +38,7 @@ import (
"github.com/sirupsen/logrus"
)
//Cluster 集群模块对外服务
// Cluster 集群模块对外服务
type Cluster interface {
//获取一个承接日志的节点
GetSuitableInstance(serviceID string) *discover.Instance
@ -51,7 +51,7 @@ type Cluster interface {
Scrape(ch chan<- prometheus.Metric, namespace, exporter string) error
}
//ClusterManager 控制器
// ClusterManager 控制器
type ClusterManager struct {
discover discover.Manager
zmqPub *connect.Pub
@ -65,7 +65,7 @@ type ClusterManager struct {
etcdClient *clientv3.Client
}
//NewCluster 创建集群控制器
// NewCluster 创建集群控制器
func NewCluster(etcdClient *clientv3.Client, conf conf.ClusterConf, log *logrus.Entry, storeManager store.Manager) Cluster {
ctx, cancel := context.WithCancel(context.Background())
discover := discover.New(etcdClient, conf.Discover, log.WithField("module", "Discover"))
@ -87,7 +87,7 @@ func NewCluster(etcdClient *clientv3.Client, conf conf.ClusterConf, log *logrus.
}
}
//Start 启动
// Start 启动
func (s *ClusterManager) Start() error {
if err := s.discover.Run(); err != nil {
return err
@ -105,7 +105,7 @@ func (s *ClusterManager) Start() error {
return nil
}
//Stop 停止
// Stop 停止
func (s *ClusterManager) Stop() {
s.cancel()
s.distribution.Stop()
@ -114,12 +114,12 @@ func (s *ClusterManager) Stop() {
s.discover.Stop()
}
//GetSuitableInstance 获取适合的日志接收节点
// GetSuitableInstance 获取适合的日志接收节点
func (s *ClusterManager) GetSuitableInstance(serviceID string) *discover.Instance {
return s.distribution.GetSuitableInstance(serviceID)
}
//MessageRadio 消息广播
// MessageRadio 消息广播
func (s *ClusterManager) MessageRadio(mes ...db.ClusterMessage) {
for _, m := range mes {
s.zmqPub.RadioChan <- m
@ -153,7 +153,7 @@ func (s *ClusterManager) monitor() {
}
}
//Scrape prometheus monitor metrics
// Scrape prometheus monitor metrics
func (s *ClusterManager) Scrape(ch chan<- prometheus.Metric, namespace, exporter string) error {
s.discover.Scrape(ch, namespace, exporter)
return nil

View File

@ -28,7 +28,7 @@ import (
"golang.org/x/net/context"
)
//SaveDockerLogInInstance 存储service和node 的对应关系
// SaveDockerLogInInstance 存储service和node 的对应关系
func SaveDockerLogInInstance(etcdClient *clientv3.Client, conf conf.DiscoverConf, serviceID, instanceID string) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
@ -40,7 +40,7 @@ func SaveDockerLogInInstance(etcdClient *clientv3.Client, conf conf.DiscoverConf
return nil
}
//GetDokerLogInInstance 获取应用日志接收节点
// GetDokerLogInInstance 获取应用日志接收节点
func GetDokerLogInInstance(etcdClient *clientv3.Client, conf conf.DiscoverConf, serviceID string) (string, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

View File

@ -21,13 +21,13 @@ package discover
import (
"encoding/json"
"fmt"
"github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/mvcc/mvccpb"
"net"
"os"
"strings"
"time"
"github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/mvcc/mvccpb"
"github.com/goodrain/rainbond/eventlog/conf"
"github.com/goodrain/rainbond/eventlog/util"
etcdutil "github.com/goodrain/rainbond/util/etcd"
@ -36,7 +36,7 @@ import (
"golang.org/x/net/context"
)
//Manager 节点动态发现管理器
// Manager 节点动态发现管理器
type Manager interface {
RegisteredInstance(host string, port int, stopRegister *bool) *Instance
CancellationInstance(instance *Instance)
@ -51,7 +51,7 @@ type Manager interface {
Scrape(ch chan<- prometheus.Metric, namespace, exporter string) error
}
//EtcdDiscoverManager 基于ETCD自动发现
// EtcdDiscoverManager 基于ETCD自动发现
type EtcdDiscoverManager struct {
cancel func()
context context.Context
@ -66,7 +66,7 @@ type EtcdDiscoverManager struct {
stopDiscover bool
}
//New 创建
// New 创建
func New(etcdClient *clientv3.Client, conf conf.DiscoverConf, log *logrus.Entry) Manager {
ctx, cancel := context.WithCancel(context.Background())
return &EtcdDiscoverManager{
@ -82,12 +82,12 @@ func New(etcdClient *clientv3.Client, conf conf.DiscoverConf, log *logrus.Entry)
}
}
//GetCurrentInstance 获取当前节点
// GetCurrentInstance 获取当前节点
func (d *EtcdDiscoverManager) GetCurrentInstance() Instance {
return *d.selfInstance
}
//RegisteredInstance 注册实例
// RegisteredInstance 注册实例
func (d *EtcdDiscoverManager) RegisteredInstance(host string, port int, stopRegister *bool) *Instance {
instance := &Instance{}
for !*stopRegister {
@ -143,22 +143,22 @@ func (d *EtcdDiscoverManager) RegisteredInstance(host string, port int, stopRegi
return nil
}
//MonitorAddInstances 实例通知
// MonitorAddInstances 实例通知
func (d *EtcdDiscoverManager) MonitorAddInstances() chan *Instance {
return d.addChan
}
//MonitorDelInstances 实例通知
// MonitorDelInstances 实例通知
func (d *EtcdDiscoverManager) MonitorDelInstances() chan *Instance {
return d.delChan
}
//MonitorUpdateInstances 实例通知
// MonitorUpdateInstances 实例通知
func (d *EtcdDiscoverManager) MonitorUpdateInstances() chan *Instance {
return d.updateChan
}
//Run 启动
// Run 启动
func (d *EtcdDiscoverManager) Run() error {
d.log.Info("Discover manager start ")
etcdClientArgs := &etcdutil.ClientArgs{
@ -176,7 +176,7 @@ func (d *EtcdDiscoverManager) Run() error {
return nil
}
//Discover 发现
// Discover 发现
func (d *EtcdDiscoverManager) discover() {
tike := time.NewTicker(time.Second * 5)
defer tike.Stop()
@ -307,7 +307,7 @@ func (d *EtcdDiscoverManager) update(node *Node) {
}
//DeleteSlice 从数组中删除某元素
// DeleteSlice 从数组中删除某元素
func DeleteSlice(source []*Instance, index int) []*Instance {
if len(source) == 1 {
return make([]*Instance, 0)
@ -321,14 +321,14 @@ func DeleteSlice(source []*Instance, index int) []*Instance {
return append(source[0:index-1], source[index+1:]...)
}
//Stop 停止
// Stop 停止
func (d *EtcdDiscoverManager) Stop() {
d.stopDiscover = true
d.cancel()
d.log.Info("Stop the discover manager.")
}
//CancellationInstance 注销实例
// CancellationInstance 注销实例
func (d *EtcdDiscoverManager) CancellationInstance(instance *Instance) {
ctx, cancel := context.WithTimeout(d.context, time.Second*5)
defer cancel()
@ -340,7 +340,7 @@ func (d *EtcdDiscoverManager) CancellationInstance(instance *Instance) {
}
}
//UpdateInstance 更新实例
// UpdateInstance 更新实例
func (d *EtcdDiscoverManager) UpdateInstance(instance *Instance) {
instance.Status = "update"
data, err := json.Marshal(instance)
@ -356,10 +356,10 @@ func (d *EtcdDiscoverManager) UpdateInstance(instance *Instance) {
}
}
//InstanceCheckHealth 将由distribution调用当发现节点不正常时
//此处检查,如果节点已经下线,返回 delete
//如果节点未下线标记为异常,返回 abnormal
//如果节点被集群判断为故障,返回 delete
// InstanceCheckHealth 将由distribution调用当发现节点不正常时
// 此处检查,如果节点已经下线,返回 delete
// 如果节点未下线标记为异常,返回 abnormal
// 如果节点被集群判断为故障,返回 delete
func (d *EtcdDiscoverManager) InstanceCheckHealth(instanceID string) string {
d.log.Info("Start check instance health.")
if d.selfInstance.HostID == instanceID {
@ -383,7 +383,7 @@ func (d *EtcdDiscoverManager) InstanceCheckHealth(instanceID string) string {
return "delete"
}
//GetInstance 获取实例
// GetInstance 获取实例
func (d *EtcdDiscoverManager) GetInstance(id string) *Instance {
if id == d.selfInstance.HostID {
return d.selfInstance
@ -396,7 +396,7 @@ func (d *EtcdDiscoverManager) GetInstance(id string) *Instance {
return nil
}
//Scrape prometheus monitor metrics
// Scrape prometheus monitor metrics
func (d *EtcdDiscoverManager) Scrape(ch chan<- prometheus.Metric, namespace, exporter string) error {
instanceDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, exporter, "instance_up"),

View File

@ -33,7 +33,7 @@ import (
"github.com/sirupsen/logrus"
)
//Distribution 数据分区
// Distribution 数据分区
type Distribution struct {
monitorDatas map[string]*db.MonitorData
updateTime map[string]time.Time
@ -63,18 +63,18 @@ func NewDistribution(etcdClient *clientv3.Client, conf conf.DiscoverConf, dis di
return d
}
//Start 开始健康监测
// Start 开始健康监测
func (d *Distribution) Start() error {
go d.checkHealth()
return nil
}
//Stop 停止
// Stop 停止
func (d *Distribution) Stop() {
d.cancel()
}
//Update 更新监控数据
// Update 更新监控数据
func (d *Distribution) Update(m db.MonitorData) {
d.lock.Lock()
defer d.lock.Unlock()
@ -121,7 +121,7 @@ func (d *Distribution) checkHealth() {
}
}
//GetSuitableInstance 获取推荐节点
// GetSuitableInstance 获取推荐节点
func (d *Distribution) GetSuitableInstance(serviceID string) *discover.Instance {
d.lock.Lock()
defer d.lock.Unlock()

View File

@ -21,6 +21,7 @@ package web
import (
"encoding/json"
"fmt"
"github.com/coreos/etcd/clientv3"
"io/ioutil"
"net/http"
"strings"
@ -34,7 +35,6 @@ import (
"github.com/goodrain/rainbond/util"
httputil "github.com/goodrain/rainbond/util/http"
"github.com/coreos/etcd/clientv3"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/gorilla/websocket"
@ -46,7 +46,7 @@ import (
"golang.org/x/net/context"
)
//SocketServer socket 服务
// SocketServer socket 服务
type SocketServer struct {
conf conf.WebSocketConf
discoverConf conf.DiscoverConf
@ -63,7 +63,7 @@ type SocketServer struct {
pubsubCtx map[string]*PubContext
}
//NewSocket 创建zmq sub客户端
// NewSocket 创建zmq sub客户端
func NewSocket(conf conf.WebSocketConf, discoverConf conf.DiscoverConf, etcdClient *clientv3.Client, log *logrus.Entry, storeManager store.Manager, c cluster.Cluster, healthInfo map[string]string) *SocketServer {
ctx, cancel := context.WithCancel(context.Background())
d, err := time.ParseDuration(conf.TimeOut)
@ -435,7 +435,7 @@ func (s *SocketServer) reader(ws *websocket.Conn, ch chan struct{}) {
close(ch)
}
//Run 执行
// Run 执行
func (s *SocketServer) Run() error {
s.log.Info("WebSocker Server start")
go s.listen()
@ -533,18 +533,18 @@ func (s *SocketServer) checkHealth() {
}
}
//ListenError 返回错误通道
// ListenError 返回错误通道
func (s *SocketServer) ListenError() chan error {
return s.errorStop
}
//Stop 停止
// Stop 停止
func (s *SocketServer) Stop() {
s.log.Info("WebSocker Server stop")
s.cancel()
}
//receiveEventMessage 接收操作日志API
// receiveEventMessage 接收操作日志API
func (s *SocketServer) receiveEventMessage(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
w.WriteHeader(http.StatusMethodNotAllowed)
@ -579,7 +579,7 @@ func (s *SocketServer) prometheus(r *chi.Mux) {
r.Handle(s.conf.PrometheusMetricPath, promhttp.Handler())
}
//ResponseType 返回内容
// ResponseType 返回内容
type ResponseType struct {
Code int `json:"code"`
Message string `json:"msg"`
@ -587,7 +587,7 @@ type ResponseType struct {
Body ResponseBody `json:"body,omitempty"`
}
//ResponseBody 返回主体
// ResponseBody 返回主体
type ResponseBody struct {
Bean interface{} `json:"bean,omitempty"`
List []interface{} `json:"list,omitempty"`
@ -596,7 +596,7 @@ type ResponseBody struct {
Total int `json:"total,omitempty"`
}
//NewResponseType 构建返回结构
// NewResponseType 构建返回结构
func NewResponseType(code int, message string, messageCN string, bean interface{}, list []interface{}) ResponseType {
return ResponseType{
Code: code,
@ -609,7 +609,7 @@ func NewResponseType(code int, message string, messageCN string, bean interface{
}
}
//NewSuccessResponse 创建成功返回结构
// NewSuccessResponse 创建成功返回结构
func NewSuccessResponse(bean interface{}, list []interface{}) ResponseType {
return NewResponseType(200, "", "", bean, list)
}

View File

@ -33,8 +33,8 @@ import (
"github.com/goodrain/rainbond/util"
)
//IPManager ip manager
//Gets all available IP addresses for synchronizing the current node
// IPManager ip manager
// Gets all available IP addresses for synchronizing the current node
type IPManager interface {
//Whether the IP address belongs to the current node
IPInCurrentHost(net.IP) bool
@ -56,7 +56,7 @@ type ipManager struct {
needUpdate chan util.IPEVENT
}
//CreateIPManager create ip manage
// CreateIPManager create ip manage
func CreateIPManager(ctx context.Context, config option.Config, etcdcli *clientv3.Client) (IPManager, error) {
newCtx, cancel := context.WithCancel(ctx)
IPPool := util.NewIPPool(config.IgnoreInterface)
@ -75,7 +75,7 @@ func (i *ipManager) NeedUpdateGatewayPolicy() <-chan util.IPEVENT {
return i.needUpdate
}
//IPInCurrentHost Whether the IP address belongs to the current node
// IPInCurrentHost Whether the IP address belongs to the current node
func (i *ipManager) IPInCurrentHost(in net.IP) bool {
for _, exit := range i.IPPool.GetHostIPs() {
if exit.Equal(in) {

View File

@ -21,21 +21,21 @@ package cluster
import (
"context"
"fmt"
"github.com/coreos/etcd/clientv3"
"net"
"time"
"github.com/coreos/etcd/clientv3"
"github.com/goodrain/rainbond/cmd/gateway/option"
"github.com/sirupsen/logrus"
)
//NodeManager node manager
// NodeManager node manager
type NodeManager struct {
config option.Config
ipManager IPManager
}
//CreateNodeManager create node manager
// CreateNodeManager create node manager
func CreateNodeManager(ctx context.Context, config option.Config, etcdcli *clientv3.Client) (*NodeManager, error) {
nm := &NodeManager{
config: config,
@ -75,7 +75,7 @@ func (n *NodeManager) checkGatewayPort() bool {
return n.CheckPortAvailable("tcp", ports...)
}
//CheckPortAvailable checks whether the specified port is available
// CheckPortAvailable checks whether the specified port is available
func (n *NodeManager) CheckPortAvailable(protocol string, ports ...uint32) bool {
if protocol == "" {
protocol = "tcp"
@ -91,7 +91,7 @@ func (n *NodeManager) CheckPortAvailable(protocol string, ports ...uint32) bool
return true
}
//IPManager ip manager
// IPManager ip manager
func (n *NodeManager) IPManager() IPManager {
return n.ipManager
}

View File

@ -21,12 +21,12 @@ package controller
import (
"context"
"fmt"
client "github.com/coreos/etcd/clientv3"
"sync"
"time"
"github.com/goodrain/rainbond/gateway/cluster"
client "github.com/coreos/etcd/clientv3"
"github.com/eapache/channels"
"github.com/goodrain/rainbond/cmd/gateway/option"
"github.com/goodrain/rainbond/gateway/controller/openresty"
@ -177,7 +177,7 @@ func (gwc *GWController) syncGateway(key interface{}) error {
return nil
}
//NewGWController new Gateway controller
// NewGWController new Gateway controller
func NewGWController(ctx context.Context, clientset kubernetes.Interface, cfg *option.Config, mc metric.Collector, node *cluster.NodeManager) (*GWController, error) {
gwc := &GWController{
updateCh: channels.NewRingChannel(1024),

219
go.mod
View File

@ -1,13 +1,13 @@
module github.com/goodrain/rainbond
go 1.18
go 1.19
require (
cuelang.org/go v0.2.2
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/aliyun/aliyun-oss-go-sdk v2.1.5+incompatible
github.com/atcdot/gorm-bulk-upsert v1.0.0
github.com/aws/aws-sdk-go v1.38.49
github.com/aws/aws-sdk-go v1.44.116
github.com/barnettZQG/gotty v1.0.1-0.20200904091006-a0a1f7d747dc
github.com/beorn7/perks v1.0.1
github.com/bitly/go-simplejson v0.5.0
@ -22,12 +22,12 @@ require (
github.com/docker/go-units v0.4.0
github.com/docker/libcompose v0.4.1-0.20190808084053-143e0f3f1ab9
github.com/eapache/channels v1.1.0
github.com/emicklei/go-restful v2.14.2+incompatible
github.com/emicklei/go-restful v2.15.0+incompatible
github.com/emicklei/go-restful-swagger12 v0.0.0-20170926063155-7524189396c6
github.com/envoyproxy/go-control-plane v0.10.1
github.com/envoyproxy/go-control-plane v0.10.3
github.com/fatih/color v1.13.0
github.com/fatih/structs v1.1.0
github.com/fsnotify/fsnotify v1.5.1
github.com/fsnotify/fsnotify v1.6.0
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/go-chi/chi v4.1.2+incompatible
github.com/go-chi/render v1.0.1
@ -39,13 +39,13 @@ require (
github.com/gogo/protobuf v1.3.2
github.com/golang/glog v1.0.0
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.2
github.com/golang/protobuf v1.5.3
github.com/goodrain/rainbond-oam v0.0.0-20221115150510-dd668a6d6765
github.com/goodrain/rainbond-operator v1.3.1-0.20210401055914-f8fe4bf89a21
github.com/gorilla/websocket v1.4.2
github.com/gorilla/websocket v1.5.0
github.com/gosuri/uitable v0.0.4
github.com/howeyc/fsnotify v0.9.0
github.com/imdario/mergo v0.3.12
github.com/imdario/mergo v0.3.15
github.com/jinzhu/gorm v1.9.16
github.com/json-iterator/go v1.1.12
github.com/kr/pty v1.1.8
@ -58,50 +58,49 @@ require (
github.com/ncabatoff/process-exporter v0.7.1
github.com/oam-dev/kubevela v1.1.0-alpha.4.0.20210625105426-e176fcfc56f0
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.19.0
github.com/onsi/gomega v1.27.10
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.0.3-0.20220114050600-8b9d41f48198
github.com/pborman/uuid v1.2.1
github.com/pebbe/zmq4 v1.2.1
github.com/pkg/errors v0.9.1
github.com/pkg/sftp v1.12.0
github.com/pkg/sftp v1.13.1
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.45.0
github.com/prometheus-operator/prometheus-operator/pkg/client v0.45.0
github.com/prometheus/client_golang v1.12.1
github.com/prometheus/client_model v0.2.0
github.com/prometheus/common v0.32.1
github.com/prometheus/client_golang v1.16.0
github.com/prometheus/client_model v0.4.0
github.com/prometheus/common v0.44.0
github.com/prometheus/node_exporter v1.0.1
github.com/prometheus/procfs v0.7.3
github.com/prometheus/procfs v0.10.1
github.com/shirou/gopsutil v3.21.3+incompatible
github.com/sirupsen/logrus v1.8.1
github.com/smartystreets/goconvey v1.6.4
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.1
github.com/stretchr/testify v1.8.2
github.com/testcontainers/testcontainers-go v0.8.0
github.com/thejerf/suture v3.0.3+incompatible
github.com/tidwall/gjson v1.9.3
github.com/twinj/uuid v1.0.0
github.com/urfave/cli v1.22.4
github.com/yudai/umutex v0.0.0-20150817080136-18216d265c6b
golang.org/x/crypto v0.1.0
golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10
golang.org/x/sys v0.3.0
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65
google.golang.org/grpc v1.45.0
google.golang.org/protobuf v1.28.1
golang.org/x/crypto v0.14.0
golang.org/x/net v0.17.0
golang.org/x/sys v0.13.0
golang.org/x/time v0.3.0
google.golang.org/grpc v1.54.0
google.golang.org/protobuf v1.30.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
helm.sh/helm/v3 v3.8.2
k8s.io/api v0.26.0
k8s.io/apiextensions-apiserver v0.26.0
k8s.io/apimachinery v0.26.0
k8s.io/apiserver v0.24.1
k8s.io/cli-runtime v0.24.1
k8s.io/api v0.28.3
k8s.io/apiextensions-apiserver v0.28.3
k8s.io/apiserver v0.28.3
k8s.io/cli-runtime v0.26.4
k8s.io/client-go v12.0.0+incompatible
k8s.io/code-generator v0.26.0
k8s.io/component-base v0.24.1
k8s.io/code-generator v0.26.4
k8s.io/component-base v0.28.3
k8s.io/cri-api v0.23.1
k8s.io/kubernetes v1.23.12
sigs.k8s.io/controller-runtime v0.12.1
@ -110,17 +109,21 @@ require (
require (
github.com/coreos/etcd v3.3.13+incompatible
github.com/dustin/go-humanize v1.0.0
github.com/go-playground/assert/v2 v2.0.1
github.com/helm/helm v2.17.0+incompatible
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29
k8s.io/klog/v2 v2.80.1
golang.org/x/sync v0.2.0
k8s.io/apimachinery v0.28.3
k8s.io/klog/v2 v2.100.1
kubevirt.io/api v1.1.0
kubevirt.io/client-go v1.1.0
sigs.k8s.io/gateway-api v0.6.1
)
require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/BurntSushi/toml v1.0.0 // indirect
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
@ -131,15 +134,15 @@ require (
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/beevik/ntp v0.3.0 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/census-instrumentation/opencensus-proto v0.3.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5 // indirect
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4 // indirect
github.com/cncf/xds/go v0.0.0-20211130200136-a8f946100490 // indirect
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe // indirect
github.com/cncf/xds/go v0.0.0-20230105202645-06c439db220b // indirect
github.com/cockroachdb/apd/v2 v2.0.1 // indirect
github.com/containerd/cgroups v1.0.3 // indirect
github.com/containerd/console v1.0.3 // indirect
@ -147,6 +150,7 @@ require (
github.com/containerd/fifo v1.0.0 // indirect
github.com/containerd/ttrpc v1.1.0 // indirect
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/coreos/prometheus-operator v0.41.1 // indirect
github.com/creack/pty v1.1.11 // indirect
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
@ -157,20 +161,21 @@ require (
github.com/eapache/queue v1.1.0 // indirect
github.com/elazarl/go-bindata-assetfs v1.0.0 // indirect
github.com/ema/qdisc v0.0.0-20190904071900-b82c76788043 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/envoyproxy/protoc-gen-validate v0.6.2 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/envoyproxy/protoc-gen-validate v0.9.1 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-gorp/gorp/v3 v3.0.2 // indirect
github.com/go-logfmt/logfmt v0.5.0 // indirect
github.com/go-logr/zapr v1.2.0 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
@ -185,25 +190,27 @@ require (
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/hodgesds/perf-utils v0.0.8 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmoiron/sqlx v1.3.4 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/k8snetworkplumbingwg/network-attachment-definition-client v0.0.0-20191119172530-79f836b90111 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lib/pq v1.10.4 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/lufia/iostat v1.1.0 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-xmlrpc v0.0.3 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mdlayher/genetlink v1.0.0 // indirect
github.com/mdlayher/netlink v1.1.0 // indirect
github.com/mdlayher/wifi v0.0.0-20190303161829-b1436901ddee // indirect
@ -213,7 +220,7 @@ require (
github.com/moby/locker v1.0.1 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/moby/sys/mountinfo v0.6.2 // indirect
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
@ -226,11 +233,13 @@ require (
github.com/opencontainers/runc v1.1.4 // indirect
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 // indirect
github.com/opencontainers/selinux v1.10.1 // indirect
github.com/openshift/api v0.0.0-20230503133300-8bbcb7ca7183 // indirect
github.com/openshift/client-go v0.0.0-20210112165513-ebc401615f47 // indirect
github.com/openshift/custom-resource-status v1.1.2 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rubenv/sql-migrate v1.1.1 // indirect
github.com/russross/blackfriday v1.6.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
@ -244,50 +253,53 @@ require (
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
go.opencensus.io v0.23.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.19.1 // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/term v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.25.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230525234035-dd9d682886f9 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/src-d/go-billy.v4 v4.3.2 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/gengo v0.0.0-20220902162205-c0856e24416d // indirect
k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01 // indirect
k8s.io/helm v2.17.0+incompatible // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230505201702-9f6742963106 // indirect
kubevirt.io/containerized-data-importer-api v1.57.0-alpha1 // indirect
kubevirt.io/controller-lifecycle-operator-sdk/api v0.0.0-20220329064328-f3cc58c6ed90 // indirect
oras.land/oras-go v1.1.1 // indirect
sigs.k8s.io/kustomize/api v0.11.4 // indirect
sigs.k8s.io/kustomize/kyaml v0.13.6 // indirect
sigs.k8s.io/kustomize/api v0.12.1 // indirect
sigs.k8s.io/kustomize/kyaml v0.13.9 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)
require (
github.com/alecthomas/units v0.0.0-20201120081800-1786d5ef83d4 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
github.com/klauspost/compress v1.15.4 // indirect
github.com/mattn/go-sqlite3 v1.14.8 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/mattn/go-sqlite3 v1.14.14 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.1
github.com/spf13/cobra v1.6.0 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/xanzy/ssh-agent v0.3.0 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/tools v0.2.0 // indirect
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
google.golang.org/genproto v0.0.0-20220421151946-72621c1f0bd3 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/tools v0.9.3 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/genproto v0.0.0-20230526161137-0005af68ea54 // indirect
k8s.io/kubectl v0.24.0 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
)
// Pinned to kubernetes-1.23.12
@ -300,35 +312,36 @@ replace (
github.com/envoyproxy/go-control-plane => github.com/envoyproxy/go-control-plane v0.9.5
github.com/godbus/dbus => github.com/godbus/dbus/v5 v5.0.4
github.com/goodrain/rainbond-oam => github.com/goodrain/rainbond-oam v0.0.0-20230823084937-0067a4cf0912
github.com/prometheus/common => github.com/prometheus/common v0.15.0
github.com/prometheus/procfs => github.com/prometheus/procfs v0.7.3
google.golang.org/grpc => google.golang.org/grpc v1.27.1
helm.sh/helm/v3 => helm.sh/helm/v3 v3.9.0
k8s.io/api => k8s.io/api v0.24.1
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.24.1
k8s.io/apimachinery => k8s.io/apimachinery v0.24.1
k8s.io/apiserver => k8s.io/apiserver v0.24.1
k8s.io/cli-runtime => k8s.io/cli-runtime v0.24.1
k8s.io/client-go => k8s.io/client-go v0.24.1
k8s.io/cloud-provider => k8s.io/cloud-provider v0.24.1
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.24.1
k8s.io/code-generator => k8s.io/code-generator v0.24.1
k8s.io/component-base => k8s.io/component-base v0.24.1
k8s.io/component-helpers => k8s.io/component-helpers v0.24.1
k8s.io/controller-manager => k8s.io/controller-manager v0.24.1
k8s.io/cri-api => k8s.io/cri-api v0.24.1
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.24.1
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.24.1
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.24.1
k8s.io/kube-proxy => k8s.io/kube-proxy v0.24.1
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.24.1
k8s.io/kubectl => k8s.io/kubectl v0.24.1
k8s.io/kubelet => k8s.io/kubelet v0.24.1
k8s.io/api => k8s.io/api v0.26.4
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.26.4
k8s.io/apimachinery => k8s.io/apimachinery v0.26.4
k8s.io/apiserver => k8s.io/apiserver v0.26.4
k8s.io/cli-runtime => k8s.io/cli-runtime v0.26.4
k8s.io/client-go => k8s.io/client-go v0.26.4
k8s.io/cloud-provider => k8s.io/cloud-provider v0.26.4
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.26.4
k8s.io/code-generator => k8s.io/code-generator v0.26.4
k8s.io/component-base => k8s.io/component-base v0.26.4
k8s.io/component-helpers => k8s.io/component-helpers v0.26.4
k8s.io/controller-manager => k8s.io/controller-manager v0.26.4
k8s.io/cri-api => k8s.io/cri-api v0.26.4
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.26.4
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.26.4
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.26.4
k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280
k8s.io/kube-proxy => k8s.io/kube-proxy v0.26.4
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.26.4
k8s.io/kubectl => k8s.io/kubectl v0.26.4
k8s.io/kubelet => k8s.io/kubelet v0.26.4
k8s.io/kubernetes => k8s.io/kubernetes v1.24.1
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.24.1
k8s.io/metrics => k8s.io/metrics v0.24.1
k8s.io/mount-utils => k8s.io/mount-utils v0.24.1
k8s.io/pod-security-admission => k8s.io/pod-security-admission v0.24.1
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.24.1
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.26.4
k8s.io/metrics => k8s.io/metrics v0.26.4
k8s.io/mount-utils => k8s.io/mount-utils v0.26.4
k8s.io/pod-security-admission => k8s.io/pod-security-admission v0.26.4
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.26.4
sigs.k8s.io/apiserver-network-proxy/konnectivity-client => sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.24
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.11.0
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.14.7
)

579
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@ import (
"encoding/json"
"fmt"
"github.com/goodrain/rainbond/grctl/clients"
"github.com/prometheus/common/log"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -18,7 +18,7 @@ import (
"time"
)
//DeviceInfo -
// DeviceInfo -
type DeviceInfo struct {
idx int
pods []v1.Pod
@ -27,7 +27,7 @@ type DeviceInfo struct {
node v1.Node
}
//NodeInfo -
// NodeInfo -
type NodeInfo struct {
pods []v1.Pod
node v1.Node
@ -42,7 +42,7 @@ var (
memoryUnit = ""
)
//NewCmdGPUShare -
// NewCmdGPUShare -
func NewCmdGPUShare() cli.Command {
c := cli.Command{
Name: "gpushare",
@ -493,7 +493,7 @@ func (n *NodeInfo) hasPendingGPUMemory() bool {
return found
}
//GetAllocation -
// GetAllocation -
func GetAllocation(pod *v1.Pod) map[int]int {
podGPUMems := map[int]int{}
allocationString := ""
@ -514,7 +514,7 @@ func GetAllocation(pod *v1.Pod) map[int]int {
for id, gpuMem := range containerAllocation {
gpuIndex, err := strconv.Atoi(id)
if err != nil {
log.Errorf("failed to get gpu memory from pod annotation,reason: %v", err)
logrus.Errorf("failed to get gpu memory from pod annotation,reason: %v", err)
return map[int]int{}
}
podGPUMems[gpuIndex] += gpuMem

View File

@ -1,4 +1,4 @@
FROM golang:1.18-alpine
FROM golang:1.19-alpine
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk --no-cache add pkgconfig gcc musl-dev

View File

@ -1,4 +1,4 @@
FROM golang:1.18-alpine3.16
FROM golang:1.19-alpine3.16
#RUN apt update && apt-get install -y libzmq3-dev
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk --no-cache add zeromq-dev gcc libc-dev

View File

@ -20,9 +20,10 @@ package monitor
import (
"context"
v3 "github.com/coreos/etcd/clientv3"
"time"
v3 "github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/clientv3"
"github.com/goodrain/rainbond/cmd/monitor/option"
discoverv1 "github.com/goodrain/rainbond/discover"
discoverv2 "github.com/goodrain/rainbond/discover.v2"
@ -36,12 +37,12 @@ import (
"github.com/tidwall/gjson"
)
//Monitor monitor
// Monitor monitor
type Monitor struct {
config *option.Config
ctx context.Context
cancel context.CancelFunc
client *v3.Client
client *clientv3.Client
timeout time.Duration
manager *prometheus.Manager
discoverv1 discoverv1.Discover
@ -50,7 +51,7 @@ type Monitor struct {
stopCh chan struct{}
}
//Start start
// Start start
func (d *Monitor) Start() {
d.discoverv1.AddProject("prometheus", &callback.Prometheus{Prometheus: d.manager})
d.discoverv1.AddProject("event_log_event_http", &callback.EventLog{Prometheus: d.manager})

View File

@ -19,6 +19,7 @@
package mq
import (
"github.com/coreos/etcd/clientv3"
"os"
"strings"
"sync"
@ -31,11 +32,10 @@ import (
etcdutil "github.com/goodrain/rainbond/util/etcd"
"github.com/coreos/etcd/clientv3"
"github.com/sirupsen/logrus"
)
//ActionMQ 队列操作
// ActionMQ 队列操作
type ActionMQ interface {
Enqueue(context.Context, string, string) error
Dequeue(context.Context, string) (string, error)
@ -52,7 +52,7 @@ var EnqueueNumber float64 = 0
// DequeueNumber dequeue number
var DequeueNumber float64 = 0
//NewActionMQ new etcd mq
// NewActionMQ new etcd mq
func NewActionMQ(ctx context.Context, c option.Config) ActionMQ {
etcdQueue := etcdQueue{
config: c,
@ -99,7 +99,7 @@ func (e *etcdQueue) Start() error {
return nil
}
//registerTopic 注册消息队列主题
// registerTopic 注册消息队列主题
func (e *etcdQueue) registerTopic(topic string) {
e.queuesLock.Lock()
defer e.queuesLock.Unlock()

View File

@ -21,11 +21,11 @@ package api
import (
"context"
"fmt"
client "github.com/coreos/etcd/clientv3"
"net/http"
"strconv"
"strings"
client "github.com/coreos/etcd/clientv3"
"github.com/go-chi/chi"
"github.com/goodrain/rainbond/cmd/node/option"
"github.com/goodrain/rainbond/discover"
@ -44,7 +44,7 @@ import (
_ "net/http/pprof"
)
//Manager api manager
// Manager api manager
type Manager struct {
ctx context.Context
cancel context.CancelFunc
@ -58,7 +58,7 @@ type Manager struct {
etcdClientArgs *etcdutil.ClientArgs
}
//NewManager api manager
// NewManager api manager
func NewManager(c option.Conf, node *nodeclient.HostNode, ms *masterserver.MasterServer, kubecli kubecache.KubeClient) *Manager {
r := router.Routers(c.RunMode)
ctx, cancel := context.WithCancel(context.Background())
@ -84,7 +84,7 @@ func NewManager(c option.Conf, node *nodeclient.HostNode, ms *masterserver.Maste
return m
}
//Start 启动
// Start 启动
func (m *Manager) Start(errChan chan error) error {
logrus.Infof("api server start listening on %s", m.conf.APIAddr)
go func() {
@ -122,7 +122,7 @@ func (m *Manager) Start(errChan chan error) error {
return nil
}
//Stop 停止
// Stop 停止
func (m *Manager) Stop() error {
logrus.Info("api server is stoping.")
m.cancel()
@ -132,12 +132,12 @@ func (m *Manager) Stop() error {
return nil
}
//GetRouter GetRouter
// GetRouter GetRouter
func (m *Manager) GetRouter() *chi.Mux {
return m.router
}
//HandleClusterScrape prometheus handle
// HandleClusterScrape prometheus handle
func (m *Manager) HandleClusterScrape(w http.ResponseWriter, r *http.Request) {
gatherers := prometheus.Gatherers{
prometheus.DefaultGatherer,

View File

@ -32,7 +32,7 @@ import (
v1 "k8s.io/api/core/v1" //"github.com/sirupsen/logrus"
)
//Resource 资源
// Resource 资源
type Resource struct {
CPU int `json:"cpu"`
MemR int `json:"mem"`
@ -128,7 +128,7 @@ type PrometheusAPI struct {
API string
}
//Query Get
// Query Get
func (s *PrometheusAPI) Query(query string) (*Prome, *utils.APIHandleError) {
resp, code, err := DoRequest(s.API, query, "query", "GET", nil)
if err != nil {
@ -151,7 +151,7 @@ func (s *PrometheusAPI) Query(query string) (*Prome, *utils.APIHandleError) {
return &prome, nil
}
//QueryRange Get
// QueryRange Get
func (s *PrometheusAPI) QueryRange(query string, start, end, step string) (*Prome, *utils.APIHandleError) {
//logrus.Infof("prometheus api is %s",s.API)
uri := fmt.Sprintf("%v&start=%v&end=%v&step=%v", query, start, end, step)
@ -204,7 +204,7 @@ func DoRequest(baseAPI, query, queryType, method string, body []byte) ([]byte, i
return data, resp.StatusCode, nil
}
//ClusterResource 资源
// ClusterResource 资源
type ClusterResource struct {
AllNode int `json:"all_node"`
NotReadyNode int `json:"notready_node"`
@ -227,7 +227,7 @@ type ClusterResource struct {
MaxAllocatableMemoryNodeResource *NodeResource `json:"max_allocatable_memory_node_resource"`
}
//NodeResourceResponse 资源
// NodeResourceResponse 资源
type NodeResourceResponse struct {
CapCPU int `json:"cap_cpu"`
CapMem int `json:"cap_mem"`
@ -259,7 +259,7 @@ type Config struct {
Value string `json:"value"`
}
//ConfigUnit 一个配置单元
// ConfigUnit 一个配置单元
type ConfigUnit struct {
//配置名称 例如:network
Name string `json:"name" validate:"name|required"`
@ -279,18 +279,18 @@ func (c ConfigUnit) String() string {
return string(res)
}
//GlobalConfig 全局配置
// GlobalConfig 全局配置
type GlobalConfig struct {
Configs map[string]*ConfigUnit `json:"configs"`
}
//String String
// String String
func (g *GlobalConfig) String() string {
res, _ := ffjson.Marshal(g)
return string(res)
}
//Add 添加配置
// Add 添加配置
func (g *GlobalConfig) Add(c ConfigUnit) {
//具有依赖配置
if c.DependConfig != nil || len(c.DependConfig) > 0 {
@ -305,25 +305,25 @@ func (g *GlobalConfig) Add(c ConfigUnit) {
g.Configs[c.Name] = &c
}
//Get 获取配置
// Get 获取配置
func (g *GlobalConfig) Get(name string) *ConfigUnit {
return g.Configs[name]
}
//Delete 删除配置
// Delete 删除配置
func (g *GlobalConfig) Delete(Name string) {
if _, ok := g.Configs[Name]; ok {
delete(g.Configs, Name)
}
}
//Bytes Bytes
// Bytes Bytes
func (g GlobalConfig) Bytes() []byte {
res, _ := ffjson.Marshal(&g)
return res
}
//CreateDefaultGlobalConfig 生成默认配置
// CreateDefaultGlobalConfig 生成默认配置
func CreateDefaultGlobalConfig() *GlobalConfig {
gconfig := &GlobalConfig{
Configs: make(map[string]*ConfigUnit),
@ -413,7 +413,7 @@ func CreateDefaultGlobalConfig() *GlobalConfig {
return gconfig
}
//CreateGlobalConfig 生成配置
// CreateGlobalConfig 生成配置
func CreateGlobalConfig(kvs []*mvccpb.KeyValue) (*GlobalConfig, error) {
dgc := &GlobalConfig{
Configs: make(map[string]*ConfigUnit),
@ -473,7 +473,7 @@ type Pods struct {
Status string `json:"status"`
}
//NodeDetails NodeDetails
// NodeDetails NodeDetails
type NodeDetails struct {
Name string `json:"name"`
Role []string `json:"role"`
@ -511,7 +511,7 @@ type RulesConfig struct {
Annotations map[string]string `yaml:"annotations" json:"annotations"`
}
//NotificationEvent NotificationEvent
// NotificationEvent NotificationEvent
type NotificationEvent struct {
//Kind could be service, tenant, cluster, node
Kind string `json:"Kind"`

View File

@ -34,7 +34,7 @@ import (
"github.com/sirupsen/logrus"
)
//DataCenterConfig 数据中心配置
// DataCenterConfig 数据中心配置
type DataCenterConfig struct {
config *model.GlobalConfig
options *option.Conf
@ -46,7 +46,7 @@ type DataCenterConfig struct {
var dataCenterConfig *DataCenterConfig
//GetDataCenterConfig 获取
// GetDataCenterConfig 获取
func GetDataCenterConfig() *DataCenterConfig {
if dataCenterConfig == nil {
return CreateDataCenterConfig()
@ -54,7 +54,7 @@ func GetDataCenterConfig() *DataCenterConfig {
return dataCenterConfig
}
//CreateDataCenterConfig 创建
// CreateDataCenterConfig 创建
func CreateDataCenterConfig() *DataCenterConfig {
ctx, cancel := context.WithCancel(context.Background())
dataCenterConfig = &DataCenterConfig{
@ -85,7 +85,7 @@ func CreateDataCenterConfig() *DataCenterConfig {
return dataCenterConfig
}
//Start 启动,监听配置变化
// Start 启动,监听配置变化
func (d *DataCenterConfig) Start() {
go util.Exec(d.ctx, func() error {
ctx, cancel := context.WithCancel(d.ctx)
@ -106,18 +106,18 @@ func (d *DataCenterConfig) Start() {
}, 1)
}
//Stop 停止监听
// Stop 停止监听
func (d *DataCenterConfig) Stop() {
d.cancel()
logrus.Info("datacenter config listener stop")
}
//GetDataCenterConfig 获取配置
// GetDataCenterConfig 获取配置
func (d *DataCenterConfig) GetDataCenterConfig() (*model.GlobalConfig, error) {
return d.config, nil
}
//PutDataCenterConfig 更改配置
// PutDataCenterConfig 更改配置
func (d *DataCenterConfig) PutDataCenterConfig(c *model.GlobalConfig) (err error) {
if c == nil {
return
@ -129,12 +129,12 @@ func (d *DataCenterConfig) PutDataCenterConfig(c *model.GlobalConfig) (err error
return err
}
//GetConfig 获取全局配置
// GetConfig 获取全局配置
func (d *DataCenterConfig) GetConfig(name string) *model.ConfigUnit {
return d.config.Get(name)
}
//CacheConfig 更新配置缓存
// CacheConfig 更新配置缓存
func (d *DataCenterConfig) CacheConfig(c *model.ConfigUnit) error {
if c.Name == "" {
return fmt.Errorf("config name can not be empty")
@ -170,7 +170,7 @@ func (d *DataCenterConfig) CacheConfig(c *model.ConfigUnit) error {
return nil
}
//PutConfig 增加or更新配置
// PutConfig 增加or更新配置
func (d *DataCenterConfig) PutConfig(c *model.ConfigUnit) error {
if c.Name == "" {
return fmt.Errorf("config name can not be empty")
@ -212,7 +212,7 @@ func (d *DataCenterConfig) PutConfig(c *model.ConfigUnit) error {
return nil
}
//PutConfigKV 更新
// PutConfigKV 更新
func (d *DataCenterConfig) PutConfigKV(kv *mvccpb.KeyValue) {
var cn model.ConfigUnit
if err := ffjson.Unmarshal(kv.Value, &cn); err == nil {
@ -222,12 +222,12 @@ func (d *DataCenterConfig) PutConfigKV(kv *mvccpb.KeyValue) {
}
}
//DeleteConfig 删除配置
// DeleteConfig 删除配置
func (d *DataCenterConfig) DeleteConfig(name string) {
d.config.Delete(name)
}
//GetGroupConfig get group config
// GetGroupConfig get group config
func (d *DataCenterConfig) GetGroupConfig(groupID string) *GroupContext {
if c, ok := d.groupConfigs[groupID]; ok {
return c

View File

@ -20,23 +20,23 @@ package service
import (
"fmt"
"github.com/coreos/etcd/clientv3"
"github.com/goodrain/rainbond/cmd/node/option"
"github.com/goodrain/rainbond/discover/config"
"github.com/goodrain/rainbond/node/core/store"
"strconv"
"strings"
"github.com/coreos/etcd/clientv3"
"github.com/sirupsen/logrus"
)
//AppService app service
// AppService app service
type AppService struct {
Prefix string
c *option.Conf
}
//CreateAppService create
// CreateAppService create
func CreateAppService(c *option.Conf) *AppService {
return &AppService{
c: c,
@ -44,7 +44,7 @@ func CreateAppService(c *option.Conf) *AppService {
}
}
//FindAppEndpoints 获取app endpoint
// FindAppEndpoints 获取app endpoint
func (a *AppService) FindAppEndpoints(appName string) []*config.Endpoint {
var ends = make(map[string]*config.Endpoint)
res, err := store.DefalutClient.Get(fmt.Sprintf("%s/backends/%s/servers", a.Prefix, appName), clientv3.WithPrefix())

View File

@ -39,13 +39,13 @@ var (
DefalutClient *Client
)
//Client etcd client
// Client etcd client
type Client struct {
*client.Client
reqTimeout time.Duration
}
//NewClient 创建client
// NewClient 创建client
func NewClient(ctx context.Context, cfg *conf.Conf, etcdClientArgs *etcdutil.ClientArgs) (err error) {
cli, err := etcdutil.NewClient(ctx, etcdClientArgs)
if err != nil {
@ -63,7 +63,7 @@ func NewClient(ctx context.Context, cfg *conf.Conf, etcdClientArgs *etcdutil.Cli
return
}
//ErrKeyExists key exist error
// ErrKeyExists key exist error
var ErrKeyExists = errors.New("key already exists")
// Post attempts to create the given key, only succeeding if the key did
@ -83,28 +83,28 @@ func (c *Client) Post(key, val string, opts ...client.OpOption) (*client.PutResp
return txnresp.OpResponse().Put(), nil
}
//Put etcd v3 Put
// Put etcd v3 Put
func (c *Client) Put(key, val string, opts ...client.OpOption) (*client.PutResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), c.reqTimeout)
defer cancel()
return c.Client.Put(ctx, key, val, opts...)
}
//NewRunnable NewRunnable
// NewRunnable NewRunnable
func (c *Client) NewRunnable(key, val string, opts ...client.OpOption) (*client.PutResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), c.reqTimeout)
defer cancel()
return c.Client.Put(ctx, key, val, opts...)
}
//DelRunnable DelRunnable
// DelRunnable DelRunnable
func (c *Client) DelRunnable(key string, opts ...client.OpOption) (*client.DeleteResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), c.reqTimeout)
defer cancel()
return c.Client.Delete(ctx, key, opts...)
}
//PutWithModRev PutWithModRev
// PutWithModRev PutWithModRev
func (c *Client) PutWithModRev(key, val string, rev int64) (*client.PutResponse, error) {
if rev == 0 {
return c.Put(key, val)
@ -128,7 +128,7 @@ func (c *Client) PutWithModRev(key, val string, rev int64) (*client.PutResponse,
return &resp, nil
}
//IsRunnable IsRunnable
// IsRunnable IsRunnable
func (c *Client) IsRunnable(key string, opts ...client.OpOption) bool {
ctx, cancel := context.WithTimeout(context.Background(), c.reqTimeout)
defer cancel()
@ -144,38 +144,38 @@ func (c *Client) IsRunnable(key string, opts ...client.OpOption) bool {
return true
}
//Get get
// Get get
func (c *Client) Get(key string, opts ...client.OpOption) (*client.GetResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), c.reqTimeout)
defer cancel()
return c.Client.Get(ctx, key, opts...)
}
//Delete delete v3 etcd
// Delete delete v3 etcd
func (c *Client) Delete(key string, opts ...client.OpOption) (*client.DeleteResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), c.reqTimeout)
defer cancel()
return c.Client.Delete(ctx, key, opts...)
}
//Watch etcd v3 watch
// Watch etcd v3 watch
func (c *Client) Watch(key string, opts ...client.OpOption) client.WatchChan {
return c.Client.Watch(context.Background(), key, opts...)
}
//WatchByCtx watch by ctx
// WatchByCtx watch by ctx
func (c *Client) WatchByCtx(ctx context.Context, key string, opts ...client.OpOption) client.WatchChan {
return c.Client.Watch(ctx, key, opts...)
}
//KeepAliveOnce etcd v3 KeepAliveOnce
// KeepAliveOnce etcd v3 KeepAliveOnce
func (c *Client) KeepAliveOnce(id client.LeaseID) (*client.LeaseKeepAliveResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), c.reqTimeout)
defer cancel()
return c.Client.KeepAliveOnce(ctx, id)
}
//GetLock GetLock
// GetLock GetLock
func (c *Client) GetLock(key string, id client.LeaseID) (bool, error) {
key = conf.Config.LockPath + key
ctx, cancel := context.WithTimeout(context.Background(), c.reqTimeout)
@ -192,20 +192,20 @@ func (c *Client) GetLock(key string, id client.LeaseID) (bool, error) {
return resp.Succeeded, nil
}
//DelLock DelLock
// DelLock DelLock
func (c *Client) DelLock(key string) error {
_, err := c.Delete(conf.Config.LockPath + key)
return err
}
//Grant etcd v3 Grant
// Grant etcd v3 Grant
func (c *Client) Grant(ttl int64) (*client.LeaseGrantResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), c.reqTimeout)
defer cancel()
return c.Client.Grant(ctx, ttl)
}
//IsValidAsKeyPath IsValidAsKeyPath
// IsValidAsKeyPath IsValidAsKeyPath
func IsValidAsKeyPath(s string) bool {
return strings.IndexByte(s, '/') == -1
}

View File

@ -30,8 +30,6 @@ import (
"github.com/goodrain/rainbond/discover/config"
etcdutil "github.com/goodrain/rainbond/util/etcd"
"github.com/sirupsen/logrus"
"github.com/prometheus/common/log"
)
//UDPServer udp server
@ -111,7 +109,7 @@ func (u *UDPServer) server() error {
fmt.Println(err)
return err
}
log.Infof("UDP Server Listener: %s", listener.LocalAddr().String())
logrus.Infof("UDP Server Listener: %s", listener.LocalAddr().String())
buf := make([]byte, 65535)
go func() {
defer listener.Close()

View File

@ -40,7 +40,7 @@ import (
// RainbondEndpointPrefix is the prefix of the key of the rainbond endpoints in etcd
const RainbondEndpointPrefix = "/rainbond/endpoint"
//ClusterClient ClusterClient
// ClusterClient ClusterClient
type ClusterClient interface {
UpdateStatus(*HostNode, []NodeConditionType) error
DownNode(*HostNode) error
@ -54,7 +54,7 @@ type ClusterClient interface {
DelEndpoints(key string)
}
//NewClusterClient new cluster client
// NewClusterClient new cluster client
func NewClusterClient(conf *option.Conf) ClusterClient {
return &etcdClusterClient{
conf: conf,
@ -157,7 +157,7 @@ func checkURL(source string) bool {
return true
}
//SetEndpoints service name and hostip must set
// SetEndpoints service name and hostip must set
func (e *etcdClusterClient) SetEndpoints(serviceName, hostIP string, value []string) {
if serviceName == "" {
return
@ -196,7 +196,7 @@ func (e *etcdClusterClient) DelEndpoints(key string) {
logrus.Infof("Delete endpoints: %s", key)
}
//ErrorNotFound node not found.
// ErrorNotFound node not found.
var ErrorNotFound = fmt.Errorf("node not found")
func (e *etcdClusterClient) GetNode(nodeID string) (*HostNode, error) {
@ -225,7 +225,7 @@ func (e *etcdClusterClient) RegistNode(node *HostNode) error {
return nil
}
//Update update node info
// Update update node info
func (e *etcdClusterClient) Update(h *HostNode) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
defer cancel()
@ -235,7 +235,7 @@ func (e *etcdClusterClient) Update(h *HostNode) error {
return err
}
//Down node set node status is offline
// Down node set node status is offline
func (e *etcdClusterClient) DownNode(h *HostNode) error {
existNode, err := e.GetNode(h.ID)
if err != nil {

View File

@ -24,7 +24,6 @@ import (
"testing"
"time"
"github.com/coreos/etcd/clientv3"
"github.com/goodrain/rainbond/cmd/node/option"
"github.com/goodrain/rainbond/node/core/store"
"github.com/goodrain/rainbond/util"

View File

@ -21,12 +21,12 @@ package controller
import (
"context"
"fmt"
"github.com/coreos/etcd/clientv3"
"regexp"
"strings"
"sync"
"time"
"github.com/coreos/etcd/clientv3"
"github.com/goodrain/rainbond/builder/parser"
"github.com/goodrain/rainbond/cmd/node/option"
"github.com/goodrain/rainbond/event"
@ -41,7 +41,7 @@ var (
ArgsReg = regexp.MustCompile(`\$\{(\w+)\|{0,1}(.{0,1})\}`)
)
//ManagerService manager service
// ManagerService manager service
type ManagerService struct {
node *client.HostNode
ctx context.Context
@ -59,12 +59,12 @@ type ManagerService struct {
lock sync.Mutex
}
//GetAllService get all service
// GetAllService get all service
func (m *ManagerService) GetAllService() ([]*service.Service, error) {
return m.allservice, nil
}
//GetService get service
// GetService get service
func (m *ManagerService) GetService(serviceName string) *service.Service {
for _, s := range m.allservice {
if s.Name == serviceName {
@ -74,7 +74,7 @@ func (m *ManagerService) GetService(serviceName string) *service.Service {
return nil
}
//Start start and monitor all service
// Start start and monitor all service
func (m *ManagerService) Start(node *client.HostNode) error {
logrus.Info("Starting node controller manager.")
m.loadServiceConfig()
@ -96,13 +96,13 @@ func (m *ManagerService) loadServiceConfig() {
m.services = controllerServices
}
//Stop stop manager
// Stop stop manager
func (m *ManagerService) Stop() error {
m.cancel()
return nil
}
//Online start all service of on the node
// Online start all service of on the node
func (m *ManagerService) Online() error {
logrus.Info("Doing node online by node controller manager")
if ok := m.ctr.CheckBeforeStart(); !ok {
@ -129,7 +129,7 @@ func (m *ManagerService) SetEndpoints(hostIP string) {
}
}
//StartServices start services
// StartServices start services
func (m *ManagerService) StartServices() {
for _, service := range m.services {
if !service.Disable {
@ -154,7 +154,7 @@ func (m *ManagerService) StartServices() {
}
}
//Offline stop all service of on the node
// Offline stop all service of on the node
func (m *ManagerService) Offline() error {
logrus.Info("Doing node offline by node controller manager")
services, _ := m.GetAllService()
@ -168,7 +168,7 @@ func (m *ManagerService) Offline() error {
return nil
}
//DownOneServiceEndpoint down service endpoint
// DownOneServiceEndpoint down service endpoint
func (m *ManagerService) DownOneServiceEndpoint(s *service.Service) {
hostIP := m.cluster.GetOptions().HostIP
for _, end := range s.Endpoints {
@ -188,7 +188,7 @@ func (m *ManagerService) DownOneServiceEndpoint(s *service.Service) {
logrus.Infof("node %s down service %s endpoints", hostIP, s.Name)
}
//UpOneServiceEndpoint up service endpoint
// UpOneServiceEndpoint up service endpoint
func (m *ManagerService) UpOneServiceEndpoint(s *service.Service) {
if s.OnlyHealthCheck || s.Disable {
return
@ -203,7 +203,7 @@ func (m *ManagerService) UpOneServiceEndpoint(s *service.Service) {
}
}
//SyncServiceStatusController synchronize all service status to as we expect
// SyncServiceStatusController synchronize all service status to as we expect
func (m *ManagerService) SyncServiceStatusController() {
m.lock.Lock()
defer m.lock.Unlock()
@ -322,7 +322,7 @@ func (m *ManagerService) StopSyncService() {
}
}
//WaitStart waiting service healty
// WaitStart waiting service healty
func (m *ManagerService) WaitStart(name string, duration time.Duration) bool {
max := time.Now().Add(duration)
t := time.Tick(time.Second * 3)
@ -407,7 +407,7 @@ func (m *ManagerService) ReLoadServices() error {
return nil
}
//StartService start a service
// StartService start a service
func (m *ManagerService) StartService(serviceName string) error {
for _, service := range m.services {
if service.Name == serviceName {
@ -420,7 +420,7 @@ func (m *ManagerService) StartService(serviceName string) error {
return nil
}
//StopService start a service
// StopService start a service
func (m *ManagerService) StopService(serviceName string) error {
for i, service := range m.services {
if service.Name == serviceName {
@ -439,7 +439,7 @@ func (m *ManagerService) StopService(serviceName string) error {
return nil
}
//WriteServices write services
// WriteServices write services
func (m *ManagerService) WriteServices() error {
for _, s := range m.services {
if s.OnlyHealthCheck {
@ -483,7 +483,7 @@ func toEndpoint(reg *service.Endpoint, ip string) string {
return fmt.Sprintf("%s://%s:%s", reg.Protocol, ip, reg.Port)
}
//InjectConfig inject config
// InjectConfig inject config
func (m *ManagerService) InjectConfig(content string) string {
for _, parantheses := range ArgsReg.FindAllString(content, -1) {
logrus.Debugf("discover inject args template %s", parantheses)
@ -540,7 +540,7 @@ func (m *ManagerService) ListServiceImages() []string {
return images
}
//NewManagerService new controller manager
// NewManagerService new controller manager
func NewManagerService(conf *option.Conf, healthyManager healthy.Manager, cluster client.ClusterClient) *ManagerService {
ctx, cancel := context.WithCancel(context.Background())
manager := &ManagerService{

View File

@ -24,7 +24,6 @@ import (
"testing"
"time"
"github.com/coreos/etcd/clientv3"
"github.com/goodrain/rainbond/cmd/node/option"
"github.com/goodrain/rainbond/node/nodem/client"
"github.com/goodrain/rainbond/node/nodem/service"

View File

@ -20,7 +20,7 @@ package logger
import (
"context"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
"sync"
"time"

View File

@ -17,7 +17,7 @@ import (
"k8s.io/klog/v2"
v1 "k8s.io/api/core/v1"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
"k8s.io/kubernetes/pkg/kubelet/types"
"k8s.io/kubernetes/pkg/util/tail"
)

View File

@ -23,7 +23,7 @@ import (
"encoding/json"
"fmt"
"github.com/goodrain/rainbond/builder/sources"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
"strings"
"sync"
"time"

View File

@ -23,7 +23,7 @@ import (
"github.com/sirupsen/logrus"
)
//STREAMLOGNAME driver name
// STREAMLOGNAME driver name
const name = "streamlog"
const defaultClusterAddress = "http://rbd-eventlog:6363/docker-instance"
const defaultAddress = "rbd-eventlog:6362"
@ -31,7 +31,7 @@ const defaultAddress = "rbd-eventlog:6362"
var etcdV3Endpoints = []string{"rbd-etcd:2379"}
var clusterAddress = []string{defaultClusterAddress}
//Dis dis manage
// Dis dis manage
type Dis struct {
discoverAddress string
}
@ -67,7 +67,7 @@ func (c *Dis) discoverEventServer() {
}
}
//ResponseBody api返回数据格式
// ResponseBody api返回数据格式
type ResponseBody struct {
ValidationError url.Values `json:"validation_error,omitempty"`
Msg string `json:"msg,omitempty"`
@ -79,7 +79,7 @@ type ResponseBody struct {
Page int `json:"page,omitempty"`
}
//Endpoint endpoint
// Endpoint endpoint
type Endpoint struct {
Name string `json:"name"`
URL string `json:"url"`
@ -87,7 +87,7 @@ type Endpoint struct {
Mode int `json:"-"` //0 表示URL变化1表示Weight变化 ,2表示全变化
}
//ParseResponseBody 解析成ResponseBody
// ParseResponseBody 解析成ResponseBody
func ParseResponseBody(red io.ReadCloser) (re ResponseBody, err error) {
if red == nil {
err = errors.New("readcloser can not be nil")
@ -109,7 +109,7 @@ func init() {
go dis.discoverEventServer()
}
//StreamLog 消息流log
// StreamLog 消息流log
type StreamLog struct {
writer *Client
serviceID string
@ -130,7 +130,7 @@ type StreamLog struct {
once sync.Once
}
//New new logger
// New new logger
func New(ctx logger.Info) (logger.Logger, error) {
var (
env = make(map[string]string)
@ -202,7 +202,7 @@ func getTCPConnConfig(serviceID, address string) string {
return address
}
//ValidateLogOpt 验证参数
// ValidateLogOpt 验证参数
func ValidateLogOpt(cfg map[string]string) error {
for key, value := range cfg {
switch key {
@ -278,7 +278,7 @@ func (s *StreamLog) ping() {
s.sendMsg(pingMsg)
}
//Log log
// Log log
func (s *StreamLog) Log(msg *logger.Message) error {
defer func() {
if err := recover(); err != nil {
@ -351,7 +351,7 @@ func (s *StreamLog) reConect() {
}
}
//Close 关闭
// Close 关闭
func (s *StreamLog) Close() error {
s.cancel()
<-s.closedChan
@ -362,7 +362,7 @@ func (s *StreamLog) Close() error {
return nil
}
//Name 返回logger name
// Name 返回logger name
func (s *StreamLog) Name() string {
return name
}

View File

@ -23,6 +23,7 @@ import (
"bytes"
"encoding/binary"
"fmt"
"github.com/sirupsen/logrus"
"hash/fnv"
"io"
"net"
@ -33,9 +34,7 @@ import (
"unicode/utf8"
"github.com/goodrain/rainbond/node/statsd/prometheus"
"github.com/prometheus/common/log"
"github.com/prometheus/common/model"
"github.com/sirupsen/logrus"
)
const (
@ -256,7 +255,7 @@ func (b *Exporter) Listen(e <-chan Events) {
for {
events, ok := <-e
if !ok {
log.Debug("Channel is closed. Break out of Exporter.Listener.")
logrus.Debug("Channel is closed. Break out of Exporter.Listener.")
return
}
for _, event := range events {
@ -289,7 +288,7 @@ func (b *Exporter) Listen(e <-chan Events) {
// We don't accept negative values for counters. Incrementing the counter with a negative number
// will cause the exporter to panic. Instead we will warn and continue to the next event.
if event.Value() < 0.0 {
log.Debugf("Counter %q is: '%f' (counter must be non-negative value)", metricName, event.Value())
logrus.Debugf("Counter %q is: '%f' (counter must be non-negative value)", metricName, event.Value())
eventStats.WithLabelValues("illegal_negative_counter").Inc()
continue
}
@ -304,7 +303,7 @@ func (b *Exporter) Listen(e <-chan Events) {
counter.SetTimestamp(timestamp)
eventStats.WithLabelValues("counter").Inc()
} else {
log.Debugf(regErrF, metricName, err)
logrus.Debugf(regErrF, metricName, err)
conflictingEventStats.WithLabelValues("counter").Inc()
}
@ -325,7 +324,7 @@ func (b *Exporter) Listen(e <-chan Events) {
gauge.SetTimestamp(timestamp)
eventStats.WithLabelValues("gauge").Inc()
} else {
log.Debugf(regErrF, metricName, err)
logrus.Debugf(regErrF, metricName, err)
conflictingEventStats.WithLabelValues("gauge").Inc()
}
@ -351,7 +350,7 @@ func (b *Exporter) Listen(e <-chan Events) {
histogram.SetTimestamp(timestamp)
eventStats.WithLabelValues("timer").Inc()
} else {
log.Debugf(regErrF, metricName, err)
logrus.Debugf(regErrF, metricName, err)
conflictingEventStats.WithLabelValues("timer").Inc()
}
@ -366,7 +365,7 @@ func (b *Exporter) Listen(e <-chan Events) {
summary.SetTimestamp(timestamp)
eventStats.WithLabelValues("timer").Inc()
} else {
log.Debugf(regErrF, metricName, err)
logrus.Debugf(regErrF, metricName, err)
conflictingEventStats.WithLabelValues("timer").Inc()
}
@ -375,14 +374,14 @@ func (b *Exporter) Listen(e <-chan Events) {
}
default:
log.Debugln("Unsupported event type")
logrus.Debugln("Unsupported event type")
eventStats.WithLabelValues("illegal").Inc()
}
}
}
}
//GCollector 循环检查Exporter对象中的性能指标数据是否有过期有则清除
// GCollector 循环检查Exporter对象中的性能指标数据是否有过期有则清除
func (b *Exporter) GCollector() {
var HP = b.vitality
timer := time.NewTicker(time.Second * 10)
@ -431,7 +430,7 @@ func (b *Exporter) GCollector() {
}
}
//NewExporter new exporter
// NewExporter new exporter
func NewExporter(mapper *MetricMapper, Register prometheus.Registerer) *Exporter {
return &Exporter{
Counters: NewCounterContainer(Register),
@ -481,7 +480,7 @@ func parseDogStatsDTagsToLabels(component string) map[string]string {
if len(kv) < 2 || len(kv[1]) == 0 {
tagErrors.Inc()
log.Debugf("Malformed or empty DogStatsD tag %s in component %s", t, component)
logrus.Debugf("Malformed or empty DogStatsD tag %s in component %s", t, component)
continue
}
@ -499,7 +498,7 @@ func lineToEvents(line string) Events {
elements := strings.SplitN(line, ":", 2)
if len(elements) < 2 || len(elements[0]) == 0 || !utf8.ValidString(line) {
sampleErrors.WithLabelValues("malformed_line").Inc()
log.Debugln("Bad line from StatsD:", line)
logrus.Debugln("Bad line from StatsD:", line)
return events
}
metric := elements[0]
@ -517,7 +516,7 @@ samples:
samplingFactor := 1.0
if len(components) < 2 || len(components) > 4 {
sampleErrors.WithLabelValues("malformed_component").Inc()
log.Debugln("Bad component on line:", line)
logrus.Debugln("Bad component on line:", line)
continue
}
valueStr, statType := components[0], components[1]
@ -529,7 +528,7 @@ samples:
value, err := strconv.ParseFloat(valueStr, 64)
if err != nil {
log.Debugf("Bad value %s on line: %s", valueStr, line)
logrus.Debugf("Bad value %s on line: %s", valueStr, line)
sampleErrors.WithLabelValues("malformed_value").Inc()
continue
}
@ -539,7 +538,7 @@ samples:
if len(components) >= 3 {
for _, component := range components[2:] {
if len(component) == 0 {
log.Debugln("Empty component on line: ", line)
logrus.Debugln("Empty component on line: ", line)
sampleErrors.WithLabelValues("malformed_component").Inc()
continue samples
}
@ -549,13 +548,13 @@ samples:
switch component[0] {
case '@':
if statType != "c" && statType != "ms" {
log.Debugln("Illegal sampling factor for non-counter metric on line", line)
logrus.Debugln("Illegal sampling factor for non-counter metric on line", line)
sampleErrors.WithLabelValues("illegal_sample_factor").Inc()
continue
}
samplingFactor, err = strconv.ParseFloat(component[1:], 64)
if err != nil {
log.Debugf("Invalid sampling factor %s on line %s", component[1:], line)
logrus.Debugf("Invalid sampling factor %s on line %s", component[1:], line)
sampleErrors.WithLabelValues("invalid_sample_factor").Inc()
}
if samplingFactor == 0 {
@ -570,7 +569,7 @@ samples:
case '#':
labels = parseDogStatsDTagsToLabels(component)
default:
log.Debugf("Invalid sampling factor or tag section %s on line %s", components[2], line)
logrus.Debugf("Invalid sampling factor or tag section %s on line %s", components[2], line)
sampleErrors.WithLabelValues("invalid_sample_factor").Inc()
continue
}
@ -580,7 +579,7 @@ samples:
for i := 0; i < multiplyEvents; i++ {
event, err := buildEvent(statType, metric, value, relative, labels)
if err != nil {
log.Debugf("Error building event on line %s: %s", line, err)
logrus.Debugf("Error building event on line %s: %s", line, err)
sampleErrors.WithLabelValues("illegal_event").Inc()
continue
}
@ -599,7 +598,7 @@ func (l *StatsDUDPListener) Listen(e chan<- Events) {
for {
n, _, err := l.Conn.ReadFromUDP(buf)
if err != nil {
log.Fatal(err)
logrus.Fatal(err)
}
l.handlePacket(buf[0:n], e)
}
@ -625,7 +624,7 @@ func (l *StatsDTCPListener) Listen(e chan<- Events) {
for {
c, err := l.Conn.AcceptTCP()
if err != nil {
log.Fatalf("AcceptTCP failed: %v", err)
logrus.Fatalf("AcceptTCP failed: %v", err)
}
go l.handleConn(c, e)
}
@ -642,13 +641,13 @@ func (l *StatsDTCPListener) handleConn(c *net.TCPConn, e chan<- Events) {
if err != nil {
if err != io.EOF {
tcpErrors.Inc()
log.Debugf("Read %s failed: %v", c.RemoteAddr(), err)
logrus.Debugf("Read %s failed: %v", c.RemoteAddr(), err)
}
break
}
if isPrefix {
tcpLineTooLong.Inc()
log.Debugf("Read %s failed: line too long", c.RemoteAddr())
logrus.Debugf("Read %s failed: line too long", c.RemoteAddr())
break
}
linesReceived.Inc()

View File

@ -15,7 +15,7 @@ elif [ $(arch) = "x86_64" ]; then
GOARCH=amd64
fi
GO_VERSION=1.18-alpine3.16
GO_VERSION=1.19-alpine3.16
GOPROXY=${GOPROXY:-'https://goproxy.cn'}

View File

@ -6,7 +6,7 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
"k8s.io/cri-api/pkg/apis/runtime/v1"
"k8s.io/kubernetes/pkg/kubelet/util"
"time"
)
@ -51,13 +51,13 @@ func getConnection(endPoints []string, timeout time.Duration) (*grpc.ClientConn,
return conn, nil
}
func GetRuntimeClient(ctx context.Context, endpoint string, timeout time.Duration) (v1alpha2.RuntimeServiceClient, *grpc.ClientConn, error) {
func GetRuntimeClient(ctx context.Context, endpoint string, timeout time.Duration) (v1.RuntimeServiceClient, *grpc.ClientConn, error) {
// Set up a connection to the server.
conn, err := getRuntimeClientConnection(ctx, endpoint, timeout)
if err != nil {
return nil, nil, errors.Wrap(err, "connect")
}
runtimeClient := v1alpha2.NewRuntimeServiceClient(conn)
runtimeClient := v1.NewRuntimeServiceClient(conn)
return runtimeClient, conn, nil
}
@ -65,12 +65,12 @@ func getRuntimeClientConnection(ctx context.Context, endpoint string, timeout ti
return getConnection([]string{endpoint}, timeout)
}
func GetImageClient(ctx context.Context, endpoint string, timeout time.Duration) (v1alpha2.ImageServiceClient, *grpc.ClientConn, error) {
func GetImageClient(ctx context.Context, endpoint string, timeout time.Duration) (v1.ImageServiceClient, *grpc.ClientConn, error) {
// Set up a connection to the server.
conn, err := getRuntimeClientConnection(ctx, endpoint, timeout)
if err != nil {
return nil, nil, errors.Wrap(err, "connect")
}
runtimeClient := v1alpha2.NewImageServiceClient(conn)
runtimeClient := v1.NewImageServiceClient(conn)
return runtimeClient, conn, nil
}

View File

@ -22,6 +22,7 @@ import (
"context"
"fmt"
"github.com/goodrain/rainbond/cmd/worker/option"
"kubevirt.io/client-go/kubecli"
"sync"
"github.com/goodrain/rainbond/util"
@ -32,28 +33,28 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)
//Controller service operating controller interface
// Controller service operating controller interface
type Controller interface {
Begin()
Stop() error
}
//TypeController controller type
// TypeController controller type
type TypeController string
//TypeStartController start service type
// TypeStartController start service type
var TypeStartController TypeController = "start"
//TypeStopController start service type
// TypeStopController start service type
var TypeStopController TypeController = "stop"
//TypeRestartController restart service type
// TypeRestartController restart service type
var TypeRestartController TypeController = "restart"
//TypeUpgradeController start service type
// TypeUpgradeController start service type
var TypeUpgradeController TypeController = "upgrade"
//TypeScalingController start service type
// TypeScalingController start service type
var TypeScalingController TypeController = "scaling"
// TypeApplyRuleController -
@ -65,7 +66,7 @@ var TypeApplyConfigController TypeController = "apply_config"
// TypeControllerRefreshHPA -
var TypeControllerRefreshHPA TypeController = "refreshhpa"
//Manager controller manager
// Manager controller manager
type Manager struct {
ctx context.Context
cancel context.CancelFunc
@ -76,10 +77,11 @@ type Manager struct {
store store.Storer
lock sync.Mutex
config option.Config
kubevirtCli kubecli.KubevirtClient
}
//NewManager new manager
func NewManager(config option.Config, store store.Storer, client kubernetes.Interface, runtimeClient client.Client) *Manager {
// NewManager new manager
func NewManager(config option.Config, store store.Storer, client kubernetes.Interface, runtimeClient client.Client, kubevirtCli kubecli.KubevirtClient) *Manager {
ctx, cancel := context.WithCancel(context.Background())
return &Manager{
ctx: ctx,
@ -90,23 +92,24 @@ func NewManager(config option.Config, store store.Storer, client kubernetes.Inte
controllers: make(map[string]Controller),
store: store,
config: config,
kubevirtCli: kubevirtCli,
}
}
//Stop stop all controller
// Stop stop all controller
func (m *Manager) Stop() error {
m.cancel()
return nil
}
//GetControllerSize get running controller number
// GetControllerSize get running controller number
func (m *Manager) GetControllerSize() int {
m.lock.Lock()
defer m.lock.Unlock()
return len(m.controllers)
}
//ExportController -
// ExportController -
func (m *Manager) ExportController(AppName, AppVersion string, EventIDs []string, end bool, apps ...v1.AppService) error {
controllerID := util.NewUUID()
controller := &exportController{
@ -125,7 +128,7 @@ func (m *Manager) ExportController(AppName, AppVersion string, EventIDs []string
return nil
}
//StartController create and start service controller
// StartController create and start service controller
func (m *Manager) StartController(controllerType TypeController, apps ...v1.AppService) error {
var controller Controller
controllerID := util.NewUUID()

View File

@ -143,6 +143,12 @@ func (s *startController) startOne(app v1.AppService) error {
return fmt.Errorf("create deployment failure:%s;", err.Error())
}
}
if vm := app.GetVirtualMachine(); vm != nil {
_, err = s.manager.kubevirtCli.VirtualMachine(app.GetNamespace()).Create(s.ctx, vm)
if err != nil {
return fmt.Errorf("create vm failure:%s;", err.Error())
}
}
if job := app.GetJob(); job != nil {
_, err = s.manager.client.BatchV1().Jobs(app.GetNamespace()).Create(s.ctx, job, metav1.CreateOptions{})
if err != nil {
@ -245,7 +251,7 @@ func (s *startController) startOne(app v1.AppService) error {
return s.WaitingReady(app)
}
//WaitingReady wait app start or upgrade ready
// WaitingReady wait app start or upgrade ready
func (s *startController) WaitingReady(app v1.AppService) error {
storeAppService := s.manager.store.GetAppService(app.ServiceID)
var initTime int32

View File

@ -153,6 +153,13 @@ func (s *stopController) stopOne(app v1.AppService) error {
logrus.Errorf("delete custom component manifest %s/%s failure %s", kind, name, err.Error())
}
}
if vm := app.GetVirtualMachine(); vm != nil {
err := s.manager.kubevirtCli.VirtualMachine(app.GetNamespace()).Delete(s.ctx, vm.Name, &metav1.DeleteOptions{})
if err != nil && !errors.IsNotFound(err) {
return fmt.Errorf("delete vm failure:%s", err.Error())
}
s.manager.store.OnDeletes(vm)
}
//step 5: delete statefulset or deployment
if statefulset := app.GetStatefulSet(); statefulset != nil {
err := s.manager.client.AppsV1().StatefulSets(app.GetNamespace()).Delete(s.ctx, statefulset.Name, metav1.DeleteOptions{})
@ -249,7 +256,7 @@ func (s *stopController) Stop() error {
return nil
}
//WaitingReady wait app start or upgrade ready
// WaitingReady wait app start or upgrade ready
func (s *stopController) WaitingReady(app v1.AppService) error {
storeAppService := s.manager.store.GetAppService(app.ServiceID)
//at least waiting time is 40 second

View File

@ -223,7 +223,7 @@ func (s *upgradeController) upgradeOne(app v1.AppService) error {
return s.WaitingReady(app)
}
//WaitingReady wait app start or upgrade ready
// WaitingReady wait app start or upgrade ready
func (s *upgradeController) WaitingReady(app v1.AppService) error {
storeAppService := s.manager.store.GetAppService(app.ServiceID)
var initTime int32

View File

@ -40,8 +40,11 @@ import (
typesv1 "github.com/goodrain/rainbond/worker/appm/types/v1"
)
//TenantServicePlugin conv service all plugin
// TenantServicePlugin conv service all plugin
func TenantServicePlugin(as *typesv1.AppService, dbmanager db.Manager) error {
if as.GetVirtualMachine() != nil {
return nil
}
initContainers, preContainers, postContainers, err := conversionServicePlugin(as, dbmanager)
if err != nil {
logrus.Errorf("create plugin containers for component %s failure: %s", as.ServiceID, err.Error())
@ -327,7 +330,7 @@ func createProbeMeshInitContainer(as *typesv1.AppService, pluginID, serviceAlias
}
}
//ApplyPluginConfig applyPluginConfig
// ApplyPluginConfig applyPluginConfig
func ApplyPluginConfig(as *typesv1.AppService, servicePluginRelation *model.TenantServicePluginRelation,
dbmanager db.Manager, inboundPluginConfig *api_model.ResourceSpec) {
config, err := dbmanager.TenantPluginVersionConfigDao().GetPluginConfig(servicePluginRelation.ServiceID,
@ -369,7 +372,7 @@ func ApplyPluginConfig(as *typesv1.AppService, servicePluginRelation *model.Tena
}
}
//applyDefaultMeshPluginConfig applyDefaultMeshPluginConfig
// applyDefaultMeshPluginConfig applyDefaultMeshPluginConfig
func applyDefaultMeshPluginConfig(as *typesv1.AppService, dbmanager db.Manager) (string, *api_model.ResourceSpec, error) {
var baseServices []*api_model.BaseService
deps, err := dbmanager.TenantServiceRelationDao().GetTenantServiceRelations(as.ServiceID)
@ -448,7 +451,7 @@ func getXDSHostIPAndPort() (string, string, string) {
return xdsHost, xdsHostPort, apiHostPort
}
//container envs
// container envs
func createPluginEnvs(pluginID, tenantID, serviceAlias string, mainEnvs []v1.EnvVar, versionID, serviceID string, dbmanager db.Manager) (*[]v1.EnvVar, error) {
versionEnvs, err := dbmanager.TenantPluginVersionENVDao().GetVersionEnvByServiceID(serviceID, pluginID)
if err != nil && err.Error() != gorm.ErrRecordNotFound.Error() {
@ -490,7 +493,8 @@ func createPluginEnvs(pluginID, tenantID, serviceAlias string, mainEnvs []v1.Env
}
func createPluginResources(memory int, cpu int) v1.ResourceRequirements {
return createResourcesBySetting(memory, int64(cpu), int64(cpu), 0)
res, _ := createResourcesBySetting(memory, int64(cpu), int64(cpu), 0, false)
return *res
}
func createTCPUDPMeshRecources(as *typesv1.AppService) v1.ResourceRequirements {
@ -508,12 +512,13 @@ func createTCPUDPMeshRecources(as *typesv1.AppService) v1.ResourceRequirements {
memory = requestint
}
}
return createResourcesBySetting(memory, cpu, func() int64 {
res, _ := createResourcesBySetting(memory, cpu, func() int64 {
if 0 < cpu && cpu < 120 {
return 120
}
return cpu
}(), 0)
}(), 0, false)
return *res
}
func xdsHostIPEnv(xdsHost string) corev1.EnvVar {
@ -527,7 +532,7 @@ func xdsHostIPEnv(xdsHost string) corev1.EnvVar {
return v1.EnvVar{Name: "XDS_HOST_IP", Value: xdsHost}
}
//IsContainMount 判断存储路径是否冲突,以及进一步实现创建存储或配置文件
// IsContainMount 判断存储路径是否冲突,以及进一步实现创建存储或配置文件
func IsContainMount(volumeMounts *[]v1.VolumeMount, as *typesv1.AppService, plugin api_model.PluginStorage, pluginID string) bool {
for _, mountValue := range *volumeMounts {

View File

@ -23,12 +23,12 @@ import (
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
kubevirtv1 "kubevirt.io/api/core/v1"
)
func createResourcesBySetting(memory int, setCPURequest, setCPULimit, setGPULimit int64) corev1.ResourceRequirements {
func createResourcesBySetting(memory int, setCPURequest, setCPULimit, setGPULimit int64, vmResource bool) (*corev1.ResourceRequirements, *kubevirtv1.ResourceRequirements) {
limits := corev1.ResourceList{}
request := corev1.ResourceList{}
if memory > 0 {
limits[corev1.ResourceMemory] = *resource.NewQuantity(int64(memory*1024*1024), resource.BinarySI)
}
@ -47,8 +47,14 @@ func createResourcesBySetting(memory int, setCPURequest, setCPULimit, setGPULimi
if setCPURequest > 0 {
request[corev1.ResourceCPU] = *resource.NewMilliQuantity(setCPURequest, resource.DecimalSI)
}
return corev1.ResourceRequirements{
if vmResource {
return nil, &kubevirtv1.ResourceRequirements{
Limits: limits,
Requests: request,
}
}
return &corev1.ResourceRequirements{
Limits: limits,
Requests: request,
}
}, nil
}

View File

@ -24,6 +24,7 @@ import (
k8sutil "github.com/goodrain/rainbond/util/k8s"
batchv1beta1 "k8s.io/api/batch/v1beta1"
utilversion "k8s.io/apimachinery/pkg/util/version"
kubevirtv1 "kubevirt.io/api/core/v1"
"strconv"
"strings"
@ -43,7 +44,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
//ServiceSource conv ServiceSource
// ServiceSource conv ServiceSource
func ServiceSource(as *v1.AppService, dbmanager db.Manager) error {
sscs, err := dbmanager.ServiceSourceDao().GetServiceSource(as.ServiceID)
if err != nil {
@ -87,7 +88,7 @@ func int32Ptr(i int) *int32 {
return &j
}
//TenantServiceBase conv tenant service base info
// TenantServiceBase conv tenant service base info
func TenantServiceBase(as *v1.AppService, dbmanager db.Manager) error {
tenantService, err := dbmanager.TenantServiceDao().GetServiceByID(as.ServiceID)
if err != nil {
@ -146,6 +147,10 @@ func TenantServiceBase(as *v1.AppService, dbmanager db.Manager) error {
initBaseCronJob(as, tenantService)
return nil
}
if tenantService.IsVM() {
initBaseVirtualMachine(as, tenantService)
return nil
}
if !tenantService.IsState() {
initBaseDeployment(as, tenantService)
return nil
@ -206,6 +211,29 @@ func initBaseStatefulSet(as *v1.AppService, service *dbmodel.TenantServices) {
as.SetStatefulSet(stateful)
}
func initBaseVirtualMachine(as *v1.AppService, service *dbmodel.TenantServices) {
as.ServiceType = v1.TypeVirtualMachine
vm := as.GetVirtualMachine()
if vm == nil {
vm = &kubevirtv1.VirtualMachine{}
}
vm.Namespace = as.GetNamespace()
vm.Name = as.GetK8sWorkloadName()
vmTem := kubevirtv1.VirtualMachineInstanceTemplateSpec{ObjectMeta: metav1.ObjectMeta{}}
vm.Spec.Template = &vmTem
vm.GenerateName = strings.Replace(service.ServiceAlias, "_", "-", -1)
injectLabels := getInjectLabels(as)
vm.Labels = as.GetCommonLabels(vm.Labels, map[string]string{
"name": service.ServiceAlias,
"version": service.DeployVersion,
"kubevirt.io/domain": as.GetK8sWorkloadName(),
}, injectLabels)
r := kubevirtv1.RunStrategyAlways
vm.Spec.RunStrategy = &r
as.SetVirtualMachine(vm)
}
func initBaseDeployment(as *v1.AppService, service *dbmodel.TenantServices) {
as.ServiceType = v1.TypeDeployment
deployment := as.GetDeployment()

View File

@ -21,6 +21,7 @@ package conversion
import (
"encoding/json"
"fmt"
kubevirtv1 "kubevirt.io/api/core/v1"
"net"
"os"
"sort"
@ -46,7 +47,7 @@ import (
"sigs.k8s.io/yaml"
)
//TenantServiceVersion service deploy version conv. define pod spec
// TenantServiceVersion service deploy version conv. define pod spec
func TenantServiceVersion(as *v1.AppService, dbmanager db.Manager) error {
version, err := dbmanager.VersionInfoDao().GetVersionByDeployVersion(as.DeployVersion, as.ServiceID)
if err != nil {
@ -64,10 +65,6 @@ func TenantServiceVersion(as *v1.AppService, dbmanager db.Manager) error {
if err != nil {
return fmt.Errorf("create volume in pod template error :%s", err.Error())
}
container, err := getMainContainer(as, version, dv, envs, envVarSecrets, dbmanager)
if err != nil {
return fmt.Errorf("conv service main container failure %s", err.Error())
}
//need service mesh sidecar, volume kubeconfig
if as.NeedProxy {
dv.SetVolume(dbmodel.ShareFileVolumeType, "kube-config", "/etc/kubernetes", "/grdata/kubernetes", corev1.HostPathDirectoryOrCreate, true)
@ -84,10 +81,6 @@ func TenantServiceVersion(as *v1.AppService, dbmanager db.Manager) error {
if err != nil {
return fmt.Errorf("create toleration %v", err)
}
volumes, err := getVolumes(dv, as, dbmanager)
if err != nil {
return fmt.Errorf("get volume failure: %v", err)
}
dnsPolicy, err := createDNSPolicy(as, dbmanager)
if err != nil {
return fmt.Errorf("create dns policy failure: %v", err)
@ -111,50 +104,153 @@ func TenantServiceVersion(as *v1.AppService, dbmanager db.Manager) error {
if err != nil {
return fmt.Errorf("craete service account name failure: %v", err)
}
podtmpSpec := corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
Annotations: annotations,
Name: as.GetK8sWorkloadName() + "-pod-spec",
},
Spec: corev1.PodSpec{
ImagePullSecrets: setImagePullSecrets(),
Volumes: volumes,
Containers: []corev1.Container{*container},
NodeSelector: nodeSelector,
Tolerations: tolerations,
Affinity: affinity,
HostAliases: createHostAliases(as),
Hostname: func() string {
if nodeID, ok := as.ExtensionSet["hostname"]; ok {
return nodeID
}
return ""
}(),
NodeName: func() string {
if nodeID, ok := as.ExtensionSet["selectnode"]; ok {
return nodeID
}
return ""
}(),
HostNetwork: func() bool {
if _, ok := as.ExtensionSet["hostnetwork"]; ok {
return true
}
return false
}(),
SchedulerName: func() string {
if name, ok := as.ExtensionSet["shcedulername"]; ok {
return name
}
return ""
}(),
ServiceAccountName: san,
ShareProcessNamespace: util.Bool(createShareProcessNamespace(as, dbmanager)),
DNSPolicy: corev1.DNSPolicy(dnsPolicy),
HostIPC: createHostIPC(as, dbmanager),
},
var terminationGracePeriodSeconds int64 = 10
vmt := kubevirtv1.VirtualMachineInstanceTemplateSpec{}
podtmpSpec := corev1.PodTemplateSpec{}
if as.GetVirtualMachine() != nil {
labels["kubevirt.io/domain"] = as.GetK8sWorkloadName()
network := []kubevirtv1.Network{
{
Name: "default",
NetworkSource: kubevirtv1.NetworkSource{
Pod: &kubevirtv1.PodNetwork{},
},
},
}
volumes := dv.GetVMVolume()
volumes = append([]kubevirtv1.Volume{
{
Name: "vmimage",
VolumeSource: kubevirtv1.VolumeSource{
ContainerDisk: &kubevirtv1.ContainerDiskSource{
Image: fmt.Sprintf("%v/%v", builder.REGISTRYDOMAIN, version.ImageName),
ImagePullSecret: os.Getenv("IMAGE_PULL_SECRET"),
},
},
},
}, volumes...)
disks := dv.GetVMDisk()
bootOrder := uint(len(disks) + 1)
disks = append(disks, []kubevirtv1.Disk{{
BootOrder: &bootOrder,
DiskDevice: kubevirtv1.DiskDevice{CDRom: &kubevirtv1.CDRomTarget{
Bus: kubevirtv1.DiskBusSATA,
}},
Name: "vmimage",
}}...)
reource := createVMResources(as)
vmt = kubevirtv1.VirtualMachineInstanceTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: as.GetK8sWorkloadName() + "-vmi-spec",
Labels: labels,
Annotations: annotations,
},
Spec: kubevirtv1.VirtualMachineInstanceSpec{
Domain: kubevirtv1.DomainSpec{
Resources: reource,
CPU: &kubevirtv1.CPU{
Cores: 2,
},
Machine: &kubevirtv1.Machine{Type: "q35"},
Devices: kubevirtv1.Devices{
Disks: disks,
Interfaces: []kubevirtv1.Interface{
{
Name: "default",
Model: "e1000",
InterfaceBindingMethod: kubevirtv1.InterfaceBindingMethod{
Masquerade: &kubevirtv1.InterfaceMasquerade{},
},
},
},
},
},
NodeSelector: nodeSelector,
ReadinessProbe: createVMProbe(as, dbmanager, "liveness"),
LivenessProbe: createVMProbe(as, dbmanager, "readiness"),
Affinity: affinity,
SchedulerName: func() string {
if name, ok := as.ExtensionSet["shcedulername"]; ok {
return name
}
return ""
}(),
Tolerations: tolerations,
TerminationGracePeriodSeconds: &terminationGracePeriodSeconds,
Volumes: volumes,
Hostname: func() string {
if nodeID, ok := as.ExtensionSet["hostname"]; ok {
return nodeID
}
return ""
}(),
Networks: network,
DNSPolicy: corev1.DNSPolicy(dnsPolicy),
},
}
if dnsPolicy == "None" {
dnsConfig, err := createDNSConfig(as, dbmanager)
if err != nil {
return fmt.Errorf("create dns config %v", err)
}
vmt.Spec.DNSConfig = dnsConfig
}
} else {
volumes, err := getVolumes(dv, as, dbmanager)
if err != nil {
return fmt.Errorf("get volume failure: %v", err)
}
container, err := getMainContainer(as, version, dv, envs, envVarSecrets, dbmanager)
if err != nil {
return fmt.Errorf("conv service main container failure %s", err.Error())
}
podtmpSpec = corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
Annotations: annotations,
Name: as.GetK8sWorkloadName() + "-pod-spec",
},
Spec: corev1.PodSpec{
ImagePullSecrets: setImagePullSecrets(),
Volumes: volumes,
Containers: []corev1.Container{*container},
NodeSelector: nodeSelector,
Tolerations: tolerations,
Affinity: affinity,
HostAliases: createHostAliases(as),
Hostname: func() string {
if nodeID, ok := as.ExtensionSet["hostname"]; ok {
return nodeID
}
return ""
}(),
NodeName: func() string {
if nodeID, ok := as.ExtensionSet["selectnode"]; ok {
return nodeID
}
return ""
}(),
HostNetwork: func() bool {
if _, ok := as.ExtensionSet["hostnetwork"]; ok {
return true
}
return false
}(),
SchedulerName: func() string {
if name, ok := as.ExtensionSet["shcedulername"]; ok {
return name
}
return ""
}(),
ServiceAccountName: san,
ShareProcessNamespace: util.Bool(createShareProcessNamespace(as, dbmanager)),
DNSPolicy: corev1.DNSPolicy(dnsPolicy),
HostIPC: createHostIPC(as, dbmanager),
},
}
}
if dnsPolicy == "None" {
dnsConfig, err := createDNSConfig(as, dbmanager)
if err != nil {
@ -162,7 +258,6 @@ func TenantServiceVersion(as *v1.AppService, dbmanager db.Manager) error {
}
podtmpSpec.Spec.DNSConfig = dnsConfig
}
var terminationGracePeriodSeconds int64 = 10
if as.GetDeployment() != nil {
podtmpSpec.Spec.TerminationGracePeriodSeconds = &terminationGracePeriodSeconds
}
@ -173,7 +268,7 @@ func TenantServiceVersion(as *v1.AppService, dbmanager db.Manager) error {
podtmpSpec.Spec.RestartPolicy = "OnFailure"
}
//set to deployment or statefulset job or cronjob
as.SetPodTemplate(podtmpSpec, vct)
as.SetPodAndVMTemplate(podtmpSpec, vmt, vct)
return nil
}
@ -204,7 +299,7 @@ func getMainContainer(as *v1.AppService, version *dbmodel.VersionInfo, dv *volum
if imagename == "" {
if version.DeliveredType == "slug" {
imagename = builder.RUNNERIMAGENAME
if err := sources.ImagesPullAndPush(builder.RUNNERIMAGENAME, builder.ONLINERUNNERIMAGENAME, "", "", nil); err != nil {
if err := sources.ImagesPullAndPush(builder.RUNNERIMAGENAME, builder.GetRunnerImage(""), "", "", nil); err != nil {
logrus.Errorf("[getMainContainer] get runner image failed: %v", err)
}
} else {
@ -275,7 +370,7 @@ func createArgs(version *dbmodel.VersionInfo, envs []corev1.EnvVar) (args []stri
return args
}
//createEnv create service container env
// createEnv create service container env
func createEnv(as *v1.AppService, dbmanager db.Manager, envVarSecrets []*corev1.Secret) ([]corev1.EnvVar, error) {
var envs []corev1.EnvVar
var envsAll []*dbmodel.TenantServiceEnvVar
@ -655,6 +750,28 @@ func getVolumes(dv *volume.Define, as *v1.AppService, dbmanager db.Manager) ([]c
return volumes, nil
}
func createVMResources(as *v1.AppService) kubevirtv1.ResourceRequirements {
var cpuRequest, cpuLimit int64
if limit, ok := as.ExtensionSet["cpulimit"]; ok {
limitint, _ := strconv.Atoi(limit)
if limitint > 0 {
cpuLimit = int64(limitint)
}
}
if request, ok := as.ExtensionSet["cpurequest"]; ok {
requestint, _ := strconv.Atoi(request)
if requestint > 0 {
cpuRequest = int64(requestint)
}
}
if as.ContainerCPU > 0 && cpuRequest == 0 && cpuLimit == 0 {
cpuLimit = int64(as.ContainerCPU)
cpuRequest = int64(as.ContainerCPU)
}
_, res := createResourcesBySetting(as.ContainerMemory, cpuRequest, cpuLimit, int64(as.ContainerGPU), true)
return *res
}
func createResources(as *v1.AppService) corev1.ResourceRequirements {
var cpuRequest, cpuLimit int64
if limit, ok := as.ExtensionSet["cpulimit"]; ok {
@ -673,8 +790,8 @@ func createResources(as *v1.AppService) corev1.ResourceRequirements {
cpuLimit = int64(as.ContainerCPU)
cpuRequest = int64(as.ContainerCPU)
}
rr := createResourcesBySetting(as.ContainerMemory, cpuRequest, cpuLimit, int64(as.ContainerGPU))
return rr
res, _ := createResourcesBySetting(as.ContainerMemory, cpuRequest, cpuLimit, int64(as.ContainerGPU), false)
return *res
}
func getGPULableKey() corev1.ResourceName {
@ -747,6 +864,29 @@ func createPorts(as *v1.AppService, dbmanager db.Manager) (ports []corev1.Contai
}
func createProbe(as *v1.AppService, dbmanager db.Manager, mode string) *corev1.Probe {
if mode == "liveness" {
var probe *corev1.Probe
probeAttribute, err := dbmanager.ComponentK8sAttributeDao().GetByComponentIDAndName(as.ServiceID, model.K8sAttributeNameLiveNessProbe)
if probeAttribute != nil && probeAttribute.AttributeValue != "" {
err = yaml.Unmarshal([]byte(probeAttribute.AttributeValue), probe)
if err != nil {
logrus.Errorf("create vm probe failure: %v", err)
return nil
}
return probe
}
} else {
var probe *corev1.Probe
probeAttribute, err := dbmanager.ComponentK8sAttributeDao().GetByComponentIDAndName(as.ServiceID, model.K8sAttributeNameReadinessProbe)
if probeAttribute != nil && probeAttribute.AttributeValue != "" {
err = yaml.Unmarshal([]byte(probeAttribute.AttributeValue), probe)
if err != nil {
logrus.Errorf("create vm probe failure: %v", err)
return nil
}
return probe
}
}
probe, err := dbmanager.ServiceProbeDao().GetServiceUsedProbe(as.ServiceID, mode)
if err == nil && probe != nil {
if mode == "liveness" {
@ -806,6 +946,90 @@ func createProbe(as *v1.AppService, dbmanager db.Manager, mode string) *corev1.P
return nil
}
func createVMProbe(as *v1.AppService, dbmanager db.Manager, mode string) *kubevirtv1.Probe {
if mode == "liveness" {
var probe *kubevirtv1.Probe
probeAttribute, err := dbmanager.ComponentK8sAttributeDao().GetByComponentIDAndName(as.ServiceID, model.K8sAttributeNameLiveNessProbe)
if probeAttribute != nil && probeAttribute.AttributeValue != "" {
err = yaml.Unmarshal([]byte(probeAttribute.AttributeValue), probe)
if err != nil {
logrus.Errorf("create vm probe failure: %v", err)
return nil
}
return probe
}
} else {
var probe *kubevirtv1.Probe
probeAttribute, err := dbmanager.ComponentK8sAttributeDao().GetByComponentIDAndName(as.ServiceID, model.K8sAttributeNameReadinessProbe)
if probeAttribute != nil && probeAttribute.AttributeValue != "" {
err = yaml.Unmarshal([]byte(probeAttribute.AttributeValue), probe)
if err != nil {
logrus.Errorf("create vm probe failure: %v", err)
return nil
}
return probe
}
}
probe, err := dbmanager.ServiceProbeDao().GetServiceUsedProbe(as.ServiceID, mode)
if err == nil && probe != nil {
if mode == "liveness" {
probe.SuccessThreshold = 1
}
if mode == "readiness" && probe.FailureThreshold < 1 {
probe.FailureThreshold = 3
}
p := &kubevirtv1.Probe{
FailureThreshold: int32(probe.FailureThreshold),
SuccessThreshold: int32(probe.SuccessThreshold),
InitialDelaySeconds: int32(probe.InitialDelaySecond),
TimeoutSeconds: int32(probe.TimeoutSecond),
PeriodSeconds: int32(probe.PeriodSecond),
}
if probe.Scheme == "tcp" {
tcp := &corev1.TCPSocketAction{
Port: intstr.FromInt(probe.Port),
}
p.TCPSocket = tcp
return p
} else if probe.Scheme == "http" {
action := corev1.HTTPGetAction{Path: probe.Path, Port: intstr.FromInt(probe.Port)}
if probe.HTTPHeader != "" {
hds := strings.Split(probe.HTTPHeader, ",")
var headers []corev1.HTTPHeader
for _, hd := range hds {
kv := strings.Split(hd, "=")
if len(kv) == 1 {
header := corev1.HTTPHeader{
Name: kv[0],
Value: "",
}
headers = append(headers, header)
} else if len(kv) == 2 {
header := corev1.HTTPHeader{
Name: kv[0],
Value: kv[1],
}
headers = append(headers, header)
}
}
action.HTTPHeaders = headers
}
p.HTTPGet = &action
return p
} else if probe.Scheme == "cmd" {
p.Exec = &corev1.ExecAction{Command: strings.Split(probe.Cmd, " ")}
return p
}
return nil
}
if err != nil {
logrus.Error("query probe error:", err.Error())
}
//TODO:create default probe
return nil
}
func createNodeSelector(as *v1.AppService, dbmanager db.Manager) (map[string]string, error) {
selector := make(map[string]string)
labels, err := dbmanager.TenantServiceLabelDao().GetTenantServiceNodeSelectorLabel(as.ServiceID)

View File

@ -26,6 +26,7 @@ import (
batchv1beta1 "k8s.io/api/batch/v1beta1"
betav1 "k8s.io/api/networking/v1beta1"
utilversion "k8s.io/apimachinery/pkg/util/version"
"kubevirt.io/client-go/kubecli"
"os"
"strconv"
"strings"
@ -77,7 +78,7 @@ var rc2RecordType = map[string]string{
"HorizontalPodAutoscaler": "hpa",
}
//Storer app runtime store interface
// Storer app runtime store interface
type Storer interface {
Start() error
Ready() bool
@ -135,8 +136,8 @@ type Event struct {
Obj interface{}
}
//appRuntimeStore app runtime store
//cache all kubernetes object and appservice
// appRuntimeStore app runtime store
// cache all kubernetes object and appservice
type appRuntimeStore struct {
kubeconfig *rest.Config
clientset kubernetes.Interface
@ -160,16 +161,18 @@ type appRuntimeStore struct {
volumeTypeListenerLock sync.Mutex
resourceCache *ResourceCache
k8sVersion *utilversion.Version
kubevirtCli kubecli.KubevirtClient
}
//NewStore new app runtime store
// NewStore new app runtime store
func NewStore(
kubeconfig *rest.Config,
clientset kubernetes.Interface,
rainbondClient rainbondversioned.Interface,
dbmanager db.Manager,
conf option.Config,
k8sVersion *utilversion.Version) Storer {
k8sVersion *utilversion.Version,
kubevirtCli kubecli.KubevirtClient) Storer {
ctx, cancel := context.WithCancel(context.Background())
store := &appRuntimeStore{
kubeconfig: kubeconfig,
@ -187,6 +190,7 @@ func NewStore(
podUpdateListeners: make(map[string]chan<- *corev1.Pod, 1),
volumeTypeListeners: make(map[string]chan<- *model.TenantServiceVolumeType, 1),
k8sVersion: k8sVersion,
kubevirtCli: kubevirtCli,
}
crdClient, err := internalclientset.NewForConfig(kubeconfig)
if err != nil {
@ -394,12 +398,12 @@ func (a *appRuntimeStore) Start() error {
return nil
}
//Ready if all kube informers is syncd, store is ready
// Ready if all kube informers is syncd, store is ready
func (a *appRuntimeStore) Ready() bool {
return a.informers.Ready()
}
//checkReplicasetWhetherDelete if rs is old version,if it is old version and it always delete all pod.
// checkReplicasetWhetherDelete if rs is old version,if it is old version and it always delete all pod.
// will delete it
func (a *appRuntimeStore) checkReplicasetWhetherDelete(app *v1.AppService, rs *appsv1.ReplicaSet) {
current := app.GetCurrentReplicaSet()
@ -761,7 +765,7 @@ func (a *appRuntimeStore) OnAdd(obj interface{}) {
}
}
//getAppService if creator is true, will create new app service where not found in store
// getAppService if creator is true, will create new app service where not found in store
func (a *appRuntimeStore) getAppService(serviceID, version, createrID string, creator bool) (*v1.AppService, error) {
var appservice *v1.AppService
appservice = a.GetAppService(serviceID)
@ -837,6 +841,31 @@ func (a *appRuntimeStore) OnDeletes(objs ...interface{}) {
}
}
}
if pod, ok := obj.(*corev1.Pod); ok {
if vmName, t := pod.Labels["kubevirt.io/domain"]; t {
serviceID := pod.Labels["service_id"]
version := pod.Labels["version"]
createrID := pod.Labels["creater_id"]
if serviceID != "" && version != "" && createrID != "" {
appservice, _ := a.getAppService(serviceID, version, createrID, false)
if appservice != nil {
vm, err := a.kubevirtCli.VirtualMachine(pod.Namespace).Get(context.Background(), vmName, &metav1.GetOptions{})
if err != nil && !k8sErrors.IsNotFound(err) {
logrus.Errorf("get vm failure: %v", err)
return
}
if !k8sErrors.IsNotFound(err) {
appservice.DeleteVirtualMachine(vm)
if appservice.IsClosed() {
a.DeleteAppService(appservice)
}
return
}
return
}
}
}
}
if deployment, ok := obj.(*appsv1.Deployment); ok {
serviceID := deployment.Labels["service_id"]
version := deployment.Labels["version"]
@ -1029,7 +1058,7 @@ func (a *appRuntimeStore) OnDeletes(objs ...interface{}) {
}
}
//RegistAppService regist a app model to store.
// RegistAppService regist a app model to store.
func (a *appRuntimeStore) RegistAppService(app *v1.AppService) {
a.appServices.Store(v1.GetCacheKeyOnlyServiceID(app.ServiceID), app)
a.appCount++
@ -1044,14 +1073,14 @@ func (a *appRuntimeStore) GetPod(namespace, name string) (*corev1.Pod, error) {
return a.listers.Pod.Pods(namespace).Get(name)
}
//DeleteAppService delete cache app service
// DeleteAppService delete cache app service
func (a *appRuntimeStore) DeleteAppService(app *v1.AppService) {
//a.appServices.Delete(v1.GetCacheKeyOnlyServiceID(app.ServiceID))
//a.appCount--
//logrus.Debugf("current have %d app after delete \n", a.appCount)
}
//DeleteAppServiceByKey delete cache app service
// DeleteAppServiceByKey delete cache app service
func (a *appRuntimeStore) DeleteAppServiceByKey(key v1.CacheKey) {
a.appServices.Delete(key)
a.appCount--
@ -1092,6 +1121,15 @@ func (a *appRuntimeStore) UpdateGetAppService(serviceID string) *v1.AppService {
appService.SetStatefulSet(stateful)
}
}
if vm := appService.GetVirtualMachine(); vm != nil {
vm, err := a.kubevirtCli.VirtualMachine(vm.Namespace).Get(context.Background(), vm.Name, &metav1.GetOptions{})
if err != nil && k8sErrors.IsNotFound(err) {
appService.DeleteVirtualMachine(vm)
}
if vm != nil {
appService.SetVirtualMachine(vm)
}
}
if deployment := appService.GetDeployment(); deployment != nil {
deploy, err := a.listers.Deployment.Deployments(deployment.Namespace).Get(deployment.Name)
if err != nil && k8sErrors.IsNotFound(err) {
@ -1384,7 +1422,7 @@ func (a *appRuntimeStore) HandleOperatorManagedStatefulSet(app *v1.OperatorManag
return stsList
}
//ExtractPodData processing pod data
// ExtractPodData processing pod data
func ExtractPodData(pods []corev1.Pod, deployName string) (podList []*pb.ManagedPod, images []string) {
for index, pod := range pods {
if value, ok := pod.Labels["creator"]; ok && value == "rainbond" {
@ -1596,17 +1634,17 @@ func (a *appRuntimeStore) addAbnormalInfo(ai *v1.AbnormalInfo) {
}
}
//GetTenantResource get tenant resource
// GetTenantResource get tenant resource
func (a *appRuntimeStore) GetTenantResource(tenantID string) TenantResource {
return a.resourceCache.GetTenantResource(tenantID)
}
//GetTenantResource get tenant resource
// GetTenantResource get tenant resource
func (a *appRuntimeStore) GetTenantResourceList() []TenantResource {
return a.resourceCache.GetAllTenantResource()
}
//GetTenantRunningApp get running app by tenant
// GetTenantRunningApp get running app by tenant
func (a *appRuntimeStore) GetTenantRunningApp(tenantID string) (list []*v1.AppService) {
a.appServices.Range(func(k, v interface{}) bool {
appService, _ := v.(*v1.AppService)
@ -1630,6 +1668,14 @@ func (a *appRuntimeStore) podEventHandler() cache.ResourceEventHandlerFuncs {
a.conf.KubeClient.CoreV1().Pods(pod.Namespace).Delete(context.Background(), pod.Name, metav1.DeleteOptions{})
}
if appservice != nil {
if vmName, t := pod.Labels["kubevirt.io/domain"]; t {
vm, err := a.kubevirtCli.VirtualMachine(pod.Namespace).Get(context.Background(), vmName, &metav1.GetOptions{})
if err != nil {
logrus.Errorf("get vm failure: %v", err)
}
appservice.SetVirtualMachine(vm)
}
appservice.SetPods(pod)
}
}
@ -1658,6 +1704,13 @@ func (a *appRuntimeStore) podEventHandler() cache.ResourceEventHandlerFuncs {
a.conf.KubeClient.CoreV1().Pods(pod.Namespace).Delete(context.Background(), pod.Name, metav1.DeleteOptions{})
}
if appservice != nil {
if vmName, t := pod.Labels["kubevirt.io/domain"]; t {
vm, err := a.kubevirtCli.VirtualMachine(pod.Namespace).Get(context.Background(), vmName, &metav1.GetOptions{})
if err != nil {
logrus.Errorf("get vm failure: %v", err)
}
appservice.SetVirtualMachine(vm)
}
appservice.SetPods(pod)
}
}

View File

@ -22,6 +22,7 @@ import (
"crypto/sha256"
"encoding/json"
"fmt"
v1 "kubevirt.io/api/core/v1"
"time"
"github.com/goodrain/rainbond/pkg/apis/rainbond/v1alpha1"
@ -32,7 +33,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
)
//IsEmpty is empty
// IsEmpty is empty
func (a *AppService) IsEmpty() bool {
empty := len(a.pods) == 0
if !empty {
@ -47,7 +48,7 @@ func (a *AppService) IsEmpty() bool {
return empty
}
//IsClosed is closed
// IsClosed is closed
func (a *AppService) IsClosed() bool {
if a.IsCustomComponent() {
return a.workload == nil
@ -66,6 +67,9 @@ func (a *AppService) IsClosed() bool {
if a.IsEmpty() && a.deployment != nil && a.deployment.ResourceVersion == "" {
return true
}
if a.IsEmpty() && a.virtualmachine != nil && a.virtualmachine.ResourceVersion == "" {
return true
}
}
return false
}
@ -95,6 +99,8 @@ var (
UNDEPLOY = "undeploy"
//SUCCEEDED if job and cronjob is succeeded
SUCCEEDED = "succeeded"
//PAUSED -
PAUSED = "paused"
)
func conversionThirdComponent(obj runtime.Object) *v1alpha1.ThirdComponent {
@ -113,7 +119,7 @@ func conversionThirdComponent(obj runtime.Object) *v1alpha1.ThirdComponent {
return nil
}
//GetServiceStatus get service status
// GetServiceStatus get service status
func (a *AppService) GetServiceStatus() string {
if a.IsThirdComponent() {
endpoints := a.GetEndpoints(false)
@ -160,6 +166,31 @@ func (a *AppService) GetServiceStatus() string {
if a.IsClosed() {
return CLOSED
}
if a.virtualmachine != nil {
if a.virtualmachine.Status.PrintableStatus == v1.VirtualMachineStatusPaused {
return PAUSED
}
succeed := 0
failed := 0
for _, po := range a.pods {
if po.Status.Phase == "Succeeded" {
succeed++
}
if po.Status.Phase == "Failed" {
failed++
}
if po.Status.Phase == "Pending" {
failed++
}
}
if len(a.pods) == succeed {
return SUCCEEDED
}
if failed > 0 {
return ABNORMAL
}
return RUNNING
}
if a.job != nil {
succeed := 0
failed := 0
@ -282,7 +313,7 @@ func isHaveNormalTerminatedContainer(pods []*corev1.Pod) bool {
return false
}
//Ready Whether ready
// Ready Whether ready
func (a *AppService) Ready() bool {
if a.statefulset != nil {
if a.statefulset.Status.ReadyReplicas >= int32(a.Replicas) {
@ -294,11 +325,16 @@ func (a *AppService) Ready() bool {
return true
}
}
if a.virtualmachine != nil {
if a.virtualmachine.Status.Ready {
return true
}
}
return false
}
//IsWaitting service status is waitting
//init container init-probe is running
// IsWaitting service status is waitting
// init container init-probe is running
func (a *AppService) IsWaitting() bool {
var initcontainer []corev1.Container
if a.statefulset != nil {
@ -336,7 +372,7 @@ func (a *AppService) IsWaitting() bool {
return false
}
//GetReadyReplicas get already ready pod number
// GetReadyReplicas get already ready pod number
func (a *AppService) GetReadyReplicas() int32 {
if a.statefulset != nil {
return a.statefulset.Status.ReadyReplicas
@ -347,7 +383,7 @@ func (a *AppService) GetReadyReplicas() int32 {
return 0
}
//GetRunningVersion get running version
// GetRunningVersion get running version
func (a *AppService) GetRunningVersion() string {
if a.statefulset != nil {
return a.statefulset.Labels["version"]
@ -358,7 +394,7 @@ func (a *AppService) GetRunningVersion() string {
return ""
}
//UpgradeComlete upgrade comlete
// UpgradeComlete upgrade comlete
func (a *AppService) UpgradeComlete() bool {
for _, pod := range a.pods {
if pod.Labels["version"] != a.DeployVersion {
@ -368,8 +404,8 @@ func (a *AppService) UpgradeComlete() bool {
return a.Ready()
}
//AbnormalInfo pod Abnormal info
//Record the container exception exit information in pod.
// AbnormalInfo pod Abnormal info
// Record the container exception exit information in pod.
type AbnormalInfo struct {
ServiceID string `json:"service_id"`
TenantID string `json:"tenant_id"`
@ -382,7 +418,7 @@ type AbnormalInfo struct {
Count int `json:"count"`
}
//Hash get AbnormalInfo hash
// Hash get AbnormalInfo hash
func (a AbnormalInfo) Hash() string {
hash := sha256.New()
hash.Write([]byte(a.ServiceID + a.ServiceAlias))

View File

@ -20,6 +20,8 @@ package v1
import (
"fmt"
"github.com/goodrain/rainbond/event"
kubevirtv1 "kubevirt.io/api/core/v1"
"os"
"sigs.k8s.io/controller-runtime/pkg/client"
"strconv"
@ -31,7 +33,6 @@ import (
"github.com/goodrain/rainbond/builder"
"github.com/goodrain/rainbond/db/model"
dbmodel "github.com/goodrain/rainbond/db/model"
"github.com/goodrain/rainbond/event"
monitorv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"github.com/sirupsen/logrus"
v1 "k8s.io/api/apps/v1"
@ -64,37 +65,40 @@ type Event struct {
IsInner bool
}
//AppServiceStatus the status of service, calculate in real time from kubernetes
// AppServiceStatus the status of service, calculate in real time from kubernetes
type AppServiceStatus string
//AppServiceType the deploy type of service.
// AppServiceType the deploy type of service.
type AppServiceType string
//TypeStatefulSet statefulset
// TypeStatefulSet statefulset
var TypeStatefulSet AppServiceType = "statefulset"
//TypeDeployment deployment
// TypeDeployment deployment
var TypeDeployment AppServiceType = "deployment"
//TypeJob deployment
// TypeJob deployment
var TypeJob AppServiceType = "job"
//TypeCronJob deployment
// TypeVirtualMachine vm
var TypeVirtualMachine AppServiceType = "virtualmachine"
// TypeCronJob deployment
var TypeCronJob AppServiceType = "cronjob"
//TypeReplicationController rc
// TypeReplicationController rc
var TypeReplicationController AppServiceType = "replicationcontroller"
//TypeUpgradeMethod upgrade service method type
// TypeUpgradeMethod upgrade service method type
type TypeUpgradeMethod string
//Rolling Start the new version before stoping the old version the rolling upgrade
// Rolling Start the new version before stoping the old version the rolling upgrade
var Rolling TypeUpgradeMethod = "Rolling"
//OnDelete Stop the old version before starting the new version the upgrade
// OnDelete Stop the old version before starting the new version the upgrade
var OnDelete TypeUpgradeMethod = "OnDelete"
//AppServiceBase app service base info
// AppServiceBase app service base info
type AppServiceBase struct {
TenantID string
TenantName string
@ -123,7 +127,7 @@ type AppServiceBase struct {
SharedStorageClass string
}
//GetComponentDefinitionName get component definition name by component kind
// GetComponentDefinitionName get component definition name by component kind
func (a AppServiceBase) GetComponentDefinitionName() string {
if strings.HasPrefix(a.ServiceKind.String(), dbmodel.ServiceKindCustom.String()) {
return strings.Replace(a.ServiceKind.String(), dbmodel.ServiceKindCustom.String(), "", 1)
@ -150,6 +154,10 @@ func (a AppServiceBase) IsThirdComponent() bool {
return a.ServiceKind.String() == dbmodel.ServiceKindThirdParty.String()
}
func (a AppServiceBase) ISVM() bool {
return string(a.ServiceType) == dbmodel.ServiceKindVirtualMachine.String()
}
// SetDiscoveryCfg -
func (a *AppServiceBase) SetDiscoveryCfg(discoveryCfg *dbmodel.ThirdPartySvcDiscoveryCfg) {
a.discoveryCfg = discoveryCfg
@ -160,7 +168,7 @@ func (a *AppServiceBase) GetK8sWorkloadName() string {
return fmt.Sprintf("%s-%s", a.K8sApp, a.K8sComponentName)
}
//OperatorManaged -
// OperatorManaged -
type OperatorManaged struct {
AppID string
services []*corev1.Service
@ -168,12 +176,13 @@ type OperatorManaged struct {
deployment []*v1.Deployment
}
//AppService a service of rainbond app state in kubernetes
// AppService a service of rainbond app state in kubernetes
type AppService struct {
AppServiceBase
tenant *corev1.Namespace
statefulset *v1.StatefulSet
deployment *v1.Deployment
virtualmachine *kubevirtv1.VirtualMachine
job *batchv1.Job
cronjob *batchv1.CronJob
betaCronJob *batchv1beta1.CronJob
@ -210,30 +219,50 @@ type AppService struct {
manifests []*unstructured.Unstructured
}
//CacheKey app cache key
// CacheKey app cache key
type CacheKey string
//Equal cache key serviceid and version and createID Equal
// Equal cache key serviceid and version and createID Equal
func (c CacheKey) Equal(end CacheKey) bool {
return string(c) == string(end)
}
//GetCacheKeyOnlyServiceID get cache key only service id
// GetCacheKeyOnlyServiceID get cache key only service id
func GetCacheKeyOnlyServiceID(serviceID string) CacheKey {
return CacheKey(serviceID)
}
//GetCacheKeyOnlyAppID get cache key only app id
// GetCacheKeyOnlyAppID get cache key only app id
func GetCacheKeyOnlyAppID(appID string) CacheKey {
return CacheKey(appID)
}
//GetDeployment get kubernetes deployment model
func (a AppService) GetVirtualMachine() *kubevirtv1.VirtualMachine {
return a.virtualmachine
}
// SetVirtualMachine set kubernetes vm model
func (a *AppService) SetVirtualMachine(vm *kubevirtv1.VirtualMachine) {
a.virtualmachine = vm
a.workload = vm
if v, ok := vm.Spec.Template.ObjectMeta.Labels["version"]; ok && v != "" {
a.DeployVersion = v
}
a.Replicas = 1
a.calculateComponentMemoryRequest()
}
// DeleteVirtualMachine delete kubernetes vm model
func (a *AppService) DeleteVirtualMachine(vm *kubevirtv1.VirtualMachine) {
a.virtualmachine = nil
}
// GetDeployment get kubernetes deployment model
func (a AppService) GetDeployment() *v1.Deployment {
return a.deployment
}
//SetDeployment set kubernetes deployment model
// SetDeployment set kubernetes deployment model
func (a *AppService) SetDeployment(d *v1.Deployment) {
a.deployment = d
a.workload = d
@ -244,32 +273,32 @@ func (a *AppService) SetDeployment(d *v1.Deployment) {
a.calculateComponentMemoryRequest()
}
//DeleteDeployment delete kubernetes deployment model
// DeleteDeployment delete kubernetes deployment model
func (a *AppService) DeleteDeployment(d *v1.Deployment) {
a.deployment = nil
}
//DeleteJob delete kubernetes job model
// DeleteJob delete kubernetes job model
func (a *AppService) DeleteJob(d *batchv1.Job) {
a.job = nil
}
//DeleteCronJob delete kubernetes cronjob model
// DeleteCronJob delete kubernetes cronjob model
func (a *AppService) DeleteCronJob(d *batchv1.CronJob) {
a.cronjob = nil
}
//DeleteBetaCronJob delete kubernetes cronjob model
// DeleteBetaCronJob delete kubernetes cronjob model
func (a *AppService) DeleteBetaCronJob(d *batchv1beta1.CronJob) {
a.betaCronJob = nil
}
//GetStatefulSet get kubernetes statefulset model
// GetStatefulSet get kubernetes statefulset model
func (a AppService) GetStatefulSet() *v1.StatefulSet {
return a.statefulset
}
//SetStatefulSet set kubernetes statefulset model
// SetStatefulSet set kubernetes statefulset model
func (a *AppService) SetStatefulSet(d *v1.StatefulSet) {
a.statefulset = d
a.workload = d
@ -280,12 +309,12 @@ func (a *AppService) SetStatefulSet(d *v1.StatefulSet) {
a.calculateComponentMemoryRequest()
}
//GetJob get kubernetes job model
// GetJob get kubernetes job model
func (a AppService) GetJob() *batchv1.Job {
return a.job
}
//SetJob set kubernetes job model
// SetJob set kubernetes job model
func (a *AppService) SetJob(d *batchv1.Job) {
a.job = d
a.workload = d
@ -295,17 +324,17 @@ func (a *AppService) SetJob(d *batchv1.Job) {
a.calculateComponentMemoryRequest()
}
//GetCronJob get kubernetes cronjob model
// GetCronJob get kubernetes cronjob model
func (a AppService) GetCronJob() *batchv1.CronJob {
return a.cronjob
}
//GetBetaCronJob get kubernetes cronjob model
// GetBetaCronJob get kubernetes cronjob model
func (a AppService) GetBetaCronJob() *batchv1beta1.CronJob {
return a.betaCronJob
}
//SetCronJob set kubernetes cronjob model
// SetCronJob set kubernetes cronjob model
func (a *AppService) SetCronJob(d *batchv1.CronJob) {
a.cronjob = d
a.workload = d
@ -325,7 +354,7 @@ func (a *AppService) SetBetaCronJob(d *batchv1beta1.CronJob) {
a.calculateComponentMemoryRequest()
}
//SetReplicaSets set kubernetes replicaset
// SetReplicaSets set kubernetes replicaset
func (a *AppService) SetReplicaSets(d *v1.ReplicaSet) {
if len(a.replicasets) > 0 {
for i, replicaset := range a.replicasets {
@ -338,7 +367,7 @@ func (a *AppService) SetReplicaSets(d *v1.ReplicaSet) {
a.replicasets = append(a.replicasets, d)
}
//DeleteReplicaSet delete replicaset
// DeleteReplicaSet delete replicaset
func (a *AppService) DeleteReplicaSet(d *v1.ReplicaSet) {
for i, c := range a.replicasets {
if c.GetName() == d.GetName() {
@ -348,7 +377,7 @@ func (a *AppService) DeleteReplicaSet(d *v1.ReplicaSet) {
}
}
//GetReplicaSets get replicaset
// GetReplicaSets get replicaset
func (a *AppService) GetReplicaSets() []*v1.ReplicaSet {
return a.replicasets
}
@ -367,7 +396,7 @@ func (a *AppService) GetNewestReplicaSet() (newest *v1.ReplicaSet) {
return
}
//GetReplicaSetVersion get rs version
// GetReplicaSetVersion get rs version
func GetReplicaSetVersion(rs *v1.ReplicaSet) int {
if version, ok := rs.Annotations["deployment.kubernetes.io/revision"]; ok {
v, _ := strconv.Atoi(version)
@ -376,7 +405,7 @@ func GetReplicaSetVersion(rs *v1.ReplicaSet) int {
return 0
}
//GetCurrentReplicaSet get current replicaset
// GetCurrentReplicaSet get current replicaset
func (a *AppService) GetCurrentReplicaSet() *v1.ReplicaSet {
if a.deployment != nil {
revision, ok := a.deployment.Annotations["deployment.kubernetes.io/revision"]
@ -391,12 +420,12 @@ func (a *AppService) GetCurrentReplicaSet() *v1.ReplicaSet {
return nil
}
//DeleteStatefulSet set kubernetes statefulset model
// DeleteStatefulSet set kubernetes statefulset model
func (a *AppService) DeleteStatefulSet(d *v1.StatefulSet) {
a.statefulset = nil
}
//SetConfigMap set kubernetes configmap model
// SetConfigMap set kubernetes configmap model
func (a *AppService) SetConfigMap(d *corev1.ConfigMap) {
if len(a.configMaps) > 0 {
for i, configMap := range a.configMaps {
@ -409,7 +438,7 @@ func (a *AppService) SetConfigMap(d *corev1.ConfigMap) {
a.configMaps = append(a.configMaps, d)
}
//GetConfigMaps get configmaps
// GetConfigMaps get configmaps
func (a *AppService) GetConfigMaps() []*corev1.ConfigMap {
if len(a.configMaps) > 0 {
return a.configMaps
@ -417,7 +446,7 @@ func (a *AppService) GetConfigMaps() []*corev1.ConfigMap {
return nil
}
//DeleteConfigMaps delete configmaps
// DeleteConfigMaps delete configmaps
func (a *AppService) DeleteConfigMaps(config *corev1.ConfigMap) {
for i, c := range a.configMaps {
if c.GetName() == config.GetName() {
@ -427,7 +456,7 @@ func (a *AppService) DeleteConfigMaps(config *corev1.ConfigMap) {
}
}
//SetService set kubernetes service model
// SetService set kubernetes service model
func (a *AppService) SetService(d *corev1.Service) {
if len(a.services) > 0 {
for i, service := range a.services {
@ -445,7 +474,7 @@ func (a *AppService) SetServices(svcs []*corev1.Service) {
a.services = svcs
}
//GetServices get services
// GetServices get services
func (a *AppService) GetServices(canCopy bool) []*corev1.Service {
if canCopy {
return append(a.services[:0:0], a.services...)
@ -453,12 +482,12 @@ func (a *AppService) GetServices(canCopy bool) []*corev1.Service {
return a.services
}
//GetDelServices returns services that need to be deleted.
// GetDelServices returns services that need to be deleted.
func (a *AppService) GetDelServices() []*corev1.Service {
return a.delServices
}
//DeleteServices delete service
// DeleteServices delete service
func (a *AppService) DeleteServices(service *corev1.Service) {
for i, c := range a.services {
if c.GetName() == service.GetName() {
@ -499,7 +528,7 @@ func (a *AppService) GetEndpointsByName(name string) *corev1.Endpoints {
return nil
}
//DelEndpoints deletes *corev1.Endpoints
// DelEndpoints deletes *corev1.Endpoints
func (a *AppService) DelEndpoints(ep *corev1.Endpoints) {
for i, c := range a.endpoints {
if c.GetName() == ep.GetName() {
@ -509,7 +538,7 @@ func (a *AppService) DelEndpoints(ep *corev1.Endpoints) {
}
}
//GetIngress get ingress
// GetIngress get ingress
func (a *AppService) GetIngress(canCopy bool) ([]*networkingv1.Ingress, []*betav1.Ingress) {
if k8s.IsHighVersion() {
if canCopy {
@ -528,12 +557,12 @@ func (a *AppService) GetIngress(canCopy bool) ([]*networkingv1.Ingress, []*betav
}
//GetDelIngs gets delIngs which need to be deleted
// GetDelIngs gets delIngs which need to be deleted
func (a *AppService) GetDelIngs() ([]*networkingv1.Ingress, []*betav1.Ingress) {
return a.delIngs, a.delBetaIngresses
}
//SetIngress set kubernetes ingress model
// SetIngress set kubernetes ingress model
func (a *AppService) SetIngress(d interface{}) {
nwkIngress, ok := d.(*networkingv1.Ingress)
if ok {
@ -566,7 +595,7 @@ func (a *AppService) SetIngresses(i []*networkingv1.Ingress) {
a.ingresses = i
}
//DeleteIngress delete kubernetes ingress model
// DeleteIngress delete kubernetes ingress model
func (a *AppService) DeleteIngress(d *networkingv1.Ingress) {
for i, c := range a.ingresses {
if c.GetName() == d.GetName() {
@ -576,7 +605,7 @@ func (a *AppService) DeleteIngress(d *networkingv1.Ingress) {
}
}
//DeleteBetaIngress delete kubernetes networking v1beta1 ingress model
// DeleteBetaIngress delete kubernetes networking v1beta1 ingress model
func (a *AppService) DeleteBetaIngress(d *betav1.Ingress) {
for i, c := range a.betaIngresses {
if c.GetName() == d.GetName() {
@ -605,8 +634,8 @@ func (a *AppService) calculateComponentMemoryRequest() {
a.podCPURequest = cpuRequest
}
//SetPodTemplate set pod template spec
func (a *AppService) SetPodTemplate(d corev1.PodTemplateSpec, vct []corev1.PersistentVolumeClaim) {
// SetPodAndVMTemplate set pod and template spec
func (a *AppService) SetPodAndVMTemplate(d corev1.PodTemplateSpec, vmt kubevirtv1.VirtualMachineInstanceTemplateSpec, vct []corev1.PersistentVolumeClaim) {
if a.statefulset != nil {
a.statefulset.Spec.Template = d
a.statefulset.Spec.VolumeClaimTemplates = append(a.statefulset.Spec.VolumeClaimTemplates, vct...)
@ -620,10 +649,13 @@ func (a *AppService) SetPodTemplate(d corev1.PodTemplateSpec, vct []corev1.Persi
if a.cronjob != nil {
a.cronjob.Spec.JobTemplate.Spec.Template = d
}
if a.virtualmachine != nil {
a.virtualmachine.Spec.Template = &vmt
}
a.calculateComponentMemoryRequest()
}
//GetPodTemplate get pod template
// GetPodTemplate get pod template
func (a *AppService) GetPodTemplate() *corev1.PodTemplateSpec {
if a.statefulset != nil {
return &a.statefulset.Spec.Template
@ -640,7 +672,7 @@ func (a *AppService) GetPodTemplate() *corev1.PodTemplateSpec {
return nil
}
//SetSecret set srcrets
// SetSecret set srcrets
func (a *AppService) SetSecret(d *corev1.Secret) {
if d == nil {
return
@ -661,12 +693,12 @@ func (a *AppService) SetSecrets(s []*corev1.Secret) {
a.secrets = s
}
//SetAllSecrets sets secrets
// SetAllSecrets sets secrets
func (a *AppService) SetAllSecrets(secrets []*corev1.Secret) {
a.secrets = secrets
}
//DeleteSecrets set secrets
// DeleteSecrets set secrets
func (a *AppService) DeleteSecrets(d *corev1.Secret) {
for i, c := range a.secrets {
if c.GetName() == d.GetName() {
@ -676,7 +708,7 @@ func (a *AppService) DeleteSecrets(d *corev1.Secret) {
}
}
//GetSecrets get secrets
// GetSecrets get secrets
func (a *AppService) GetSecrets(canCopy bool) []*corev1.Secret {
if canCopy {
return append(a.secrets[:0:0], a.secrets...)
@ -684,7 +716,7 @@ func (a *AppService) GetSecrets(canCopy bool) []*corev1.Secret {
return a.secrets
}
//GetDelSecrets get delSecrets which need to be deleted
// GetDelSecrets get delSecrets which need to be deleted
func (a *AppService) GetDelSecrets() []*corev1.Secret {
return a.delSecrets
}
@ -702,7 +734,7 @@ func (a *AppService) GetEnvVarSecrets(canCopy bool) []*corev1.Secret {
return a.envVarSecrets
}
//SetPods set pod
// SetPods set pod
func (a *AppService) SetPods(d *corev1.Pod) {
if len(a.pods) > 0 {
for i, pod := range a.pods {
@ -715,7 +747,7 @@ func (a *AppService) SetPods(d *corev1.Pod) {
a.pods = append(a.pods, d)
}
//DeletePods delete pod
// DeletePods delete pod
func (a *AppService) DeletePods(d *corev1.Pod) {
for i, c := range a.pods {
if c.GetName() == d.GetName() {
@ -725,7 +757,7 @@ func (a *AppService) DeletePods(d *corev1.Pod) {
}
}
//GetPods get pods
// GetPods get pods
func (a *AppService) GetPods(canCopy bool) []*corev1.Pod {
if canCopy {
return append(a.pods[:0:0], a.pods...)
@ -743,17 +775,17 @@ func (a *AppService) GetPodsByName(podname string) *corev1.Pod {
return nil
}
//SetTenant set tenant
// SetTenant set tenant
func (a *AppService) SetTenant(d *corev1.Namespace) {
a.tenant = d
}
//GetTenant get tenant namespace
// GetTenant get tenant namespace
func (a *AppService) GetTenant() *corev1.Namespace {
return a.tenant
}
//GetNamespace get tenant namespace name
// GetNamespace get tenant namespace name
func (a *AppService) GetNamespace() string {
return a.tenant.Name
}
@ -968,7 +1000,7 @@ func (a *AppService) SetServiceMonitor(sm *monitorv1.ServiceMonitor) {
a.serviceMonitor = append(a.serviceMonitor, sm)
}
//DeleteServiceMonitor delete service monitor
// DeleteServiceMonitor delete service monitor
func (a *AppService) DeleteServiceMonitor(sm *monitorv1.ServiceMonitor) {
if len(a.serviceMonitor) == 0 {
return
@ -1060,7 +1092,7 @@ func (a *AppService) DeleteStorageClass(sc *storagev1.StorageClass) {
}
}
//GetMemoryRequest get component memory request
// GetMemoryRequest get component memory request
func (a *AppService) GetMemoryRequest() (res int64) {
for _, pod := range a.pods {
res += CalculatePodResource(pod).MemoryRequest / 1024 / 1024
@ -1068,7 +1100,7 @@ func (a *AppService) GetMemoryRequest() (res int64) {
return
}
//GetCPURequest get component cpu request
// GetCPURequest get component cpu request
func (a *AppService) GetCPURequest() (res int64) {
for _, pod := range a.pods {
res += CalculatePodResource(pod).CPURequest
@ -1076,27 +1108,27 @@ func (a *AppService) GetCPURequest() (res int64) {
return
}
//GetManifests get component custom manifest
// GetManifests get component custom manifest
func (a *AppService) GetManifests() []*unstructured.Unstructured {
return a.manifests
}
//SetManifests get component custom manifest
// SetManifests get component custom manifest
func (a *AppService) SetManifests(manifests []*unstructured.Unstructured) {
a.manifests = manifests
}
//SetWorkload set component workload
// SetWorkload set component workload
func (a *AppService) SetWorkload(workload client.Object) {
a.workload = workload
}
//GetWorkload get component workload
// GetWorkload get component workload
func (a *AppService) GetWorkload() client.Object {
return a.workload
}
//DeleteWorkload delete component workload
// DeleteWorkload delete component workload
func (a *AppService) DeleteWorkload(workload runtime.Object) {
a.workload = nil
}
@ -1138,7 +1170,7 @@ func (a *AppService) String() string {
)
}
//GetService -
// GetService -
func (o *OperatorManaged) GetService() []*corev1.Service {
if o.services != nil {
return o.services
@ -1146,7 +1178,7 @@ func (o *OperatorManaged) GetService() []*corev1.Service {
return []*corev1.Service{}
}
//GetDeployment -
// GetDeployment -
func (o *OperatorManaged) GetDeployment() []*v1.Deployment {
if o.deployment != nil {
return o.deployment
@ -1154,7 +1186,7 @@ func (o *OperatorManaged) GetDeployment() []*v1.Deployment {
return []*v1.Deployment{}
}
//GetStatefulSet -
// GetStatefulSet -
func (o *OperatorManaged) GetStatefulSet() []*v1.StatefulSet {
if o.statefulSet != nil {
return o.statefulSet
@ -1162,7 +1194,7 @@ func (o *OperatorManaged) GetStatefulSet() []*v1.StatefulSet {
return []*v1.StatefulSet{}
}
//SetService -
// SetService -
func (o *OperatorManaged) SetService(d *corev1.Service) {
if len(o.services) > 0 {
for i, service := range o.services {
@ -1176,7 +1208,7 @@ func (o *OperatorManaged) SetService(d *corev1.Service) {
o.services = append(o.services, d)
}
//SetStatefulSet -
// SetStatefulSet -
func (o *OperatorManaged) SetStatefulSet(d *v1.StatefulSet) {
if len(o.statefulSet) > 0 {
for i, sts := range o.statefulSet {
@ -1190,7 +1222,7 @@ func (o *OperatorManaged) SetStatefulSet(d *v1.StatefulSet) {
o.statefulSet = append(o.statefulSet, d)
}
//SetDeployment -
// SetDeployment -
func (o *OperatorManaged) SetDeployment(d *v1.Deployment) {
if len(o.deployment) > 0 {
for i, deploy := range o.deployment {
@ -1204,7 +1236,7 @@ func (o *OperatorManaged) SetDeployment(d *v1.Deployment) {
o.deployment = append(o.deployment, d)
}
//DeleteDeployment -
// DeleteDeployment -
func (o *OperatorManaged) DeleteDeployment(d *v1.Deployment) {
for i, old := range o.deployment {
if old.GetName() == d.GetName() {
@ -1214,7 +1246,7 @@ func (o *OperatorManaged) DeleteDeployment(d *v1.Deployment) {
}
}
//DeleteService -
// DeleteService -
func (o *OperatorManaged) DeleteService(d *corev1.Service) {
for i, old := range o.services {
if old.GetName() == d.GetName() {
@ -1224,7 +1256,7 @@ func (o *OperatorManaged) DeleteService(d *corev1.Service) {
}
}
//DeleteStatefulSet -
// DeleteStatefulSet -
func (o *OperatorManaged) DeleteStatefulSet(d *v1.StatefulSet) {
for i, old := range o.statefulSet {
if old.GetName() == d.GetName() {
@ -1234,7 +1266,7 @@ func (o *OperatorManaged) DeleteStatefulSet(d *v1.StatefulSet) {
}
}
//TenantResource tenant resource statistical models
// TenantResource tenant resource statistical models
type TenantResource struct {
TenantID string `json:"tenant_id,omitempty"`
CPURequest int64 `json:"cpu_request,omitempty"`
@ -1254,7 +1286,7 @@ type K8sResources struct {
Ingresses []interface{}
}
//GetTCPMeshImageName get tcp mesh image name
// GetTCPMeshImageName get tcp mesh image name
func GetTCPMeshImageName() string {
if d := os.Getenv("TCPMESH_DEFAULT_IMAGE_NAME"); d != "" {
return d
@ -1262,7 +1294,7 @@ func GetTCPMeshImageName() string {
return builder.REGISTRYDOMAIN + "/rbd-mesh-data-panel"
}
//GetOnlineTCPMeshImageName get online tcp mesh image name
// GetOnlineTCPMeshImageName get online tcp mesh image name
func GetOnlineTCPMeshImageName() string {
if d := os.Getenv("TCPMESH_DEFAULT_IMAGE_NAME"); d != "" {
return d
@ -1270,7 +1302,7 @@ func GetOnlineTCPMeshImageName() string {
return builder.ONLINEREGISTRYDOMAIN + "/rbd-mesh-data-panel:" + builder.CIVERSION
}
//GetProbeMeshImageName get probe init mesh image name
// GetProbeMeshImageName get probe init mesh image name
func GetProbeMeshImageName() string {
if d := os.Getenv("PROBE_MESH_IMAGE_NAME"); d != "" {
return d
@ -1278,7 +1310,7 @@ func GetProbeMeshImageName() string {
return builder.REGISTRYDOMAIN + "/rbd-init-probe"
}
//GetOnlineProbeMeshImageName get online probe init mesh image name
// GetOnlineProbeMeshImageName get online probe init mesh image name
func GetOnlineProbeMeshImageName() string {
if d := os.Getenv("PROBE_MESH_IMAGE_NAME"); d != "" {
return d
@ -1286,7 +1318,7 @@ func GetOnlineProbeMeshImageName() string {
return builder.ONLINEREGISTRYDOMAIN + "/rbd-init-probe:" + builder.CIVERSION
}
//CalculatePodResource calculate pod resource
// CalculatePodResource calculate pod resource
func CalculatePodResource(pod *corev1.Pod) *PodResource {
for _, con := range pod.Status.Conditions {
if con.Type == corev1.PodScheduled && con.Status == corev1.ConditionFalse {
@ -1304,7 +1336,7 @@ func CalculatePodResource(pod *corev1.Pod) *PodResource {
return &pr
}
//PodResource resource struct
// PodResource resource struct
type PodResource struct {
MemoryRequest int64
MemoryLimit int64

View File

@ -23,6 +23,7 @@ import (
v1 "github.com/goodrain/rainbond/worker/appm/types/v1"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
kubevirtv1 "kubevirt.io/api/core/v1"
"os"
"path"
"strings"
@ -57,6 +58,56 @@ func (v *ShareFileVolume) CreateVolume(define *Define) error {
vo.PersistentVolumeClaim = &corev1.PersistentVolumeClaimVolumeSource{ClaimName: claim.GetName(), ReadOnly: volumeReadOnly}
define.volumes = append(define.volumes, vo)
v.generateVolumeSubPath(define, vm)
define.volumeMounts = append(define.volumeMounts, *vm)
} else if v.as.GetVirtualMachine() != nil {
labels := v.as.GetCommonLabels(map[string]string{
"volume_name": volumeMountName,
"stateless": "",
})
annotations := map[string]string{"volume_name": v.svm.VolumeName}
claim := newVolumeClaim(volumeMountName, path.Join(volumeMountPath, volumeMountName), v.svm.AccessMode, v1.RainbondStatefuleShareStorageClass, v.svm.VolumeCapacity, labels, annotations)
v.as.SetClaim(claim)
v.as.SetClaimManually(claim)
vo := kubevirtv1.Volume{
Name: volumeMountName,
VolumeSource: kubevirtv1.VolumeSource{
PersistentVolumeClaim: &kubevirtv1.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: claim.Name,
},
Hotpluggable: false,
},
},
}
var dd kubevirtv1.DiskDevice
switch volumeMountPath {
case "/disk":
dd = kubevirtv1.DiskDevice{
Disk: &kubevirtv1.DiskTarget{
Bus: kubevirtv1.DiskBusSATA,
},
}
case "/lun":
dd = kubevirtv1.DiskDevice{
LUN: &kubevirtv1.LunTarget{
Bus: kubevirtv1.DiskBusSATA,
},
}
case "/cdrom":
dd = kubevirtv1.DiskDevice{
CDRom: &kubevirtv1.CDRomTarget{
Bus: kubevirtv1.DiskBusSATA,
},
}
}
bootOrder := uint(len(define.vmDisk) + 1)
dk := kubevirtv1.Disk{
BootOrder: &bootOrder,
DiskDevice: dd,
Name: volumeMountName,
}
define.vmDisk = append(define.vmDisk, dk)
define.vmVolume = append(define.vmVolume, vo)
} else {
for _, m := range define.volumeMounts {
if m.MountPath == volumeMountPath { // TODO move to prepare
@ -82,8 +133,8 @@ func (v *ShareFileVolume) CreateVolume(define *Define) error {
vo.PersistentVolumeClaim = &corev1.PersistentVolumeClaimVolumeSource{ClaimName: claim.GetName(), ReadOnly: volumeReadOnly}
define.volumes = append(define.volumes, vo)
v.generateVolumeSubPath(define, vm)
define.volumeMounts = append(define.volumeMounts, *vm)
}
define.volumeMounts = append(define.volumeMounts, *vm)
return nil
}

View File

@ -20,6 +20,7 @@ package volume
import (
"fmt"
kubevirtv1 "kubevirt.io/api/core/v1"
"os"
"path"
"sort"
@ -73,6 +74,8 @@ func NewVolumeManager(as *v1.AppService,
}
case dbmodel.ConfigFileVolumeType.String():
v = &ConfigFileVolume{envs: envs, envVarSecrets: envVarSecrets}
case dbmodel.VMVolumeType.String():
v = new(ShareFileVolume)
case dbmodel.MemoryFSVolumeType.String():
v = new(MemoryFSVolume)
case dbmodel.LocalVolumeType.String():
@ -135,9 +138,9 @@ func newVolumeClaim(name, volumePath, accessMode, storageClassName string, capac
}
/*
RWO - ReadWriteOnce
ROX - ReadOnlyMany
RWX - ReadWriteMany
RWO - ReadWriteOnce
ROX - ReadOnlyMany
RWX - ReadWriteMany
*/
func parseAccessMode(accessMode string) corev1.PersistentVolumeAccessMode {
accessMode = strings.ToUpper(accessMode)
@ -158,6 +161,8 @@ type Define struct {
as *v1.AppService
volumeMounts []corev1.VolumeMount
volumes []corev1.Volume
vmVolume []kubevirtv1.Volume
vmDisk []kubevirtv1.Disk
}
// GetVolumes get define volumes
@ -165,6 +170,16 @@ func (v *Define) GetVolumes() []corev1.Volume {
return v.volumes
}
// GetVMVolume get define vm volumes
func (v *Define) GetVMVolume() []kubevirtv1.Volume {
return v.vmVolume
}
// GetVMDisk get define vm devices
func (v *Define) GetVMDisk() []kubevirtv1.Disk {
return v.vmDisk
}
// GetVolumeMounts get define volume mounts
func (v *Define) GetVolumeMounts() []corev1.VolumeMount {
return v.volumeMounts
@ -335,7 +350,7 @@ func convertRulesToEnvs(as *v1.AppService, dbmanager db.Manager, ports []*dbmode
return
}
//RewriteHostPathInWindows rewrite host path
// RewriteHostPathInWindows rewrite host path
func RewriteHostPathInWindows(hostPath string) string {
localPath := os.Getenv("LOCAL_DATA_PATH")
sharePath := os.Getenv("SHARE_DATA_PATH")
@ -350,7 +365,7 @@ func RewriteHostPathInWindows(hostPath string) string {
return hostPath
}
//RewriteContainerPathInWindows mount path in windows
// RewriteContainerPathInWindows mount path in windows
func RewriteContainerPathInWindows(mountPath string) string {
if mountPath == "" {
return ""

View File

@ -22,7 +22,6 @@ import (
"context"
"os"
"path/filepath"
"testing"
"time"
"github.com/goodrain/rainbond/util"
@ -35,7 +34,6 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)
@ -46,14 +44,6 @@ var rainbondClient versioned.Interface
var testEnv *envtest.Environment
var stopCh = make(chan struct{})
func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t,
"HelmApp Controller Suite",
[]Reporter{printer.NewlineReporter{}})
}
var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

View File

@ -378,7 +378,7 @@ func createEndpoint(component *v1alpha1.ThirdComponent, service *corev1.Service,
}
// UpdateStatus updates ThirdComponent's Status with retry.RetryOnConflict
func (r *Reconciler) updateStatus(ctx context.Context, appd *v1alpha1.ThirdComponent, opts ...client.UpdateOption) error {
func (r *Reconciler) updateStatus(ctx context.Context, appd *v1alpha1.ThirdComponent, opts ...client.SubResourceUpdateOption) error {
status := appd.DeepCopy().Status
return retry.RetryOnConflict(retry.DefaultBackoff, func() (err error) {
if err = r.Client.Get(ctx, client.ObjectKey{Namespace: appd.Namespace, Name: appd.Name}, appd); err != nil {

View File

@ -31,11 +31,10 @@ import (
"github.com/goodrain/rainbond/worker/monitor/collector"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log"
"github.com/sirupsen/logrus"
)
//ExporterManager app resource exporter
// ExporterManager app resource exporter
type ExporterManager struct {
ctx context.Context
cancel context.CancelFunc
@ -45,7 +44,7 @@ type ExporterManager struct {
controllermanager *controller.Manager
}
//NewManager return *NewManager
// NewManager return *NewManager
func NewManager(c option.Config, masterController *master.Controller, controllermanager *controller.Manager) *ExporterManager {
ctx, cancel := context.WithCancel(context.Background())
return &ExporterManager{
@ -70,7 +69,7 @@ func (t *ExporterManager) handler(w http.ResponseWriter, r *http.Request) {
h.ServeHTTP(w, r)
}
//Start 启动
// Start 启动
func (t *ExporterManager) Start() error {
http.HandleFunc(t.config.PrometheusMetricPath, t.handler)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
@ -90,15 +89,15 @@ func (t *ExporterManager) Start() error {
}
httputil.ReturnSuccess(r, w, healthStatus)
})
log.Infoln("Listening on", t.config.Listen)
logrus.Infoln("Listening on", t.config.Listen)
go func() {
log.Fatal(http.ListenAndServe(t.config.Listen, nil))
logrus.Fatal(http.ListenAndServe(t.config.Listen, nil))
}()
logrus.Info("start app resource exporter success.")
return nil
}
//Stop 停止
// Stop 停止
func (t *ExporterManager) Stop() {
t.cancel()
}

View File

@ -2,6 +2,7 @@ package util
import (
"fmt"
virtv1 "kubevirt.io/api/core/v1"
"sort"
"strings"
@ -29,15 +30,16 @@ var PodStatusAdviceUnhealthy PodStatusAdvice = "Unhealthy"
var PodStatusAdviceInitiating PodStatusAdvice = "Initiating"
var podStatusTbl = map[string]pb.PodStatus_Type{
string(corev1.PodPending): pb.PodStatus_INITIATING,
string(corev1.PodRunning): pb.PodStatus_RUNNING,
string(corev1.PodSucceeded): pb.PodStatus_ABNORMAL,
string(corev1.PodFailed): pb.PodStatus_ABNORMAL,
string(corev1.PodUnknown): pb.PodStatus_UNKNOWN,
string(corev1.PodReady): pb.PodStatus_NOTREADY,
string(corev1.PodInitialized): pb.PodStatus_INITIATING,
string(corev1.PodScheduled): pb.PodStatus_SCHEDULING,
string(corev1.ContainersReady): pb.PodStatus_NOTREADY,
string(corev1.PodPending): pb.PodStatus_INITIATING,
string(corev1.PodRunning): pb.PodStatus_RUNNING,
string(corev1.PodSucceeded): pb.PodStatus_ABNORMAL,
string(corev1.PodFailed): pb.PodStatus_ABNORMAL,
string(corev1.PodUnknown): pb.PodStatus_UNKNOWN,
string(corev1.PodReady): pb.PodStatus_NOTREADY,
string(corev1.PodInitialized): pb.PodStatus_INITIATING,
string(corev1.PodScheduled): pb.PodStatus_SCHEDULING,
string(corev1.ContainersReady): pb.PodStatus_NOTREADY,
string(virtv1.VirtualMachineUnpaused): pb.PodStatus_RUNNING,
}
// DescribePodStatus -
@ -94,8 +96,8 @@ func DescribePodStatus(clientset kubernetes.Interface, pod *corev1.Pod, podStatu
if cstatus.State.Terminated.Reason == "OOMKilled" {
podStatus.Advice = PodStatusAdviceOOM.String()
}
for _, OwnerReference := range pod.OwnerReferences{
if OwnerReference.Kind == "Job"{
for _, OwnerReference := range pod.OwnerReferences {
if OwnerReference.Kind == "Job" {
if cstatus.State.Terminated.Reason == "Completed" {
podStatus.Type = pb.PodStatus_SUCCEEDED
}