2018-03-14 14:12:26 +08:00
// Copyright (C) 2014-2018 Goodrain Co., Ltd.
2017-11-07 11:40:44 +08:00
// RAINBOND, Application Management Platform
2018-03-14 14:33:31 +08:00
2017-11-07 11:40:44 +08:00
// 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.
2018-03-14 14:33:31 +08:00
2017-11-07 11:40:44 +08:00
// 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.
2018-03-14 14:33:31 +08:00
2017-11-07 11:40:44 +08:00
// 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 model
2018-03-04 22:48:50 +08:00
import (
"fmt"
"os"
"strings"
"time"
2021-06-21 16:48:25 +08:00
"github.com/goodrain/rainbond/util/commonutil"
2018-03-04 22:48:50 +08:00
)
2017-11-07 11:40:44 +08:00
2023-11-30 13:56:09 +08:00
// Model 默认字段
2017-11-07 11:40:44 +08:00
type Model struct {
2019-08-23 14:41:56 +08:00
ID uint ` gorm:"column:ID;primary_key" `
2019-08-22 14:20:08 +08:00
CreatedAt time . Time ` gorm:"column:create_time" json:"create_time" `
2017-11-07 11:40:44 +08:00
}
2023-11-30 13:56:09 +08:00
// IDModel 默认ID字段
2017-11-07 11:40:44 +08:00
type IDModel struct {
ID uint ` gorm:"column:ID;primary_key" `
}
2023-11-30 13:56:09 +08:00
// Interface model interface
2017-11-07 11:40:44 +08:00
type Interface interface {
TableName ( ) string
}
2019-11-05 14:27:54 +08:00
// TenantStatus -
type TenantStatus string
var (
// TenantStatusNormal -
TenantStatusNormal TenantStatus = "normal"
// TenantStatusDeleting -
TenantStatusDeleting TenantStatus = "deleting"
// TenantStatusDeleteFailed -
TenantStatusDeleteFailed TenantStatus = "delete_failed"
)
func ( t TenantStatus ) String ( ) string {
return string ( t )
}
2023-11-30 13:56:09 +08:00
// Tenants 租户信息
2017-11-07 11:40:44 +08:00
type Tenants struct {
Model
2018-11-14 23:08:30 +08:00
Name string ` gorm:"column:name;size:40;unique_index" `
UUID string ` gorm:"column:uuid;size:33;unique_index" `
EID string ` gorm:"column:eid" `
2018-10-23 18:11:27 +08:00
LimitMemory int ` gorm:"column:limit_memory" `
2019-11-05 14:27:54 +08:00
Status string ` gorm:"column:status;default:'normal'" `
2021-11-15 17:39:20 +08:00
Namespace string ` gorm:"column:namespace;size:32;unique_index" `
2017-11-07 11:40:44 +08:00
}
2023-11-30 13:56:09 +08:00
// TableName 返回租户表名称
2017-11-07 11:40:44 +08:00
func ( t * Tenants ) TableName ( ) string {
return "tenants"
}
2019-03-06 15:27:28 +08:00
// ServiceKind kind of service
type ServiceKind string
// ServiceKindThirdParty means third-party service
var ServiceKindThirdParty ServiceKind = "third_party"
2023-11-30 13:56:09 +08:00
// ServiceKindVirtualMachine -
var ServiceKindVirtualMachine ServiceKind = "virtualmachine"
2019-03-06 15:27:28 +08:00
// ServiceKindInternal means internal service
var ServiceKindInternal ServiceKind = "internal"
2021-06-30 16:46:39 +08:00
// ServiceKindCustom means custom component define
var ServiceKindCustom ServiceKind = "custom.componentdefinition."
2019-03-06 15:27:28 +08:00
func ( s ServiceKind ) String ( ) string {
return string ( s )
}
2020-02-18 22:41:18 +08:00
// ServiceType type of service
type ServiceType string
// String imple String
func ( s ServiceType ) String ( ) string {
return string ( s )
}
2020-02-20 16:15:40 +08:00
// IsState is state type or not
func ( s ServiceType ) IsState ( ) bool {
2020-03-16 16:19:08 +08:00
if s == ServiceTypeStateMultiple || s == ServiceTypeStateSingleton {
return true
2020-02-20 16:15:40 +08:00
}
2020-03-16 16:19:08 +08:00
return false
2020-02-20 16:15:40 +08:00
}
2023-11-30 13:56:09 +08:00
// IsVM is vm type or not
func ( s ServiceType ) IsVM ( ) bool {
if s == ServiceTypeVM {
return true
}
return false
}
2022-08-01 00:12:02 +08:00
// IsJob is job
func ( s ServiceType ) IsJob ( ) bool {
if s == ServiceTypeJob {
return true
}
return false
}
// IsCronJob is cronjob
func ( s ServiceType ) IsCronJob ( ) bool {
if s == ServiceTypeCronJob {
return true
}
return false
}
2020-02-20 16:15:40 +08:00
// IsSingleton is singleton or not
func ( s ServiceType ) IsSingleton ( ) bool {
if s == "" {
return false
}
if s == ServiceTypeStatelessMultiple || s == ServiceTypeStateMultiple {
return false
}
return true
}
2020-02-18 22:41:18 +08:00
// IsState is state service or stateless service
2021-04-09 16:24:00 +08:00
// TODO fanyangyang 根据组件简单判断是否是有状态
func ( t * TenantServices ) IsState ( ) bool {
if t . ExtendMethod == "" {
2020-02-18 22:41:18 +08:00
return false
}
2021-04-09 16:24:00 +08:00
return ServiceType ( t . ExtendMethod ) . IsState ( )
2020-02-20 16:15:40 +08:00
}
2023-11-30 13:56:09 +08:00
func ( t * TenantServices ) IsVM ( ) bool {
if t . ExtendMethod == "" {
return false
}
return ServiceType ( t . ExtendMethod ) . IsVM ( )
}
2022-08-01 00:12:02 +08:00
// IsJob is job
func ( t * TenantServices ) IsJob ( ) bool {
if ServiceType ( t . ExtendMethod ) . IsJob ( ) {
return true
}
return false
}
// IsCronJob is cronjob
func ( t * TenantServices ) IsCronJob ( ) bool {
if ServiceType ( t . ExtendMethod ) . IsCronJob ( ) {
return true
}
return false
}
2020-02-20 16:15:40 +08:00
// IsSingleton is singleton or multiple service
2021-04-09 16:24:00 +08:00
func ( t * TenantServices ) IsSingleton ( ) bool {
if t . ExtendMethod == "" {
2020-02-18 22:41:18 +08:00
return false
}
2021-04-09 16:24:00 +08:00
return ServiceType ( t . ExtendMethod ) . IsSingleton ( )
2020-02-18 22:41:18 +08:00
}
// ServiceTypeUnknown unknown
var ServiceTypeUnknown ServiceType = "unknown"
2023-11-30 13:56:09 +08:00
// ServiceTypeStatelessSingleton stateless_singleton
2020-02-18 22:41:18 +08:00
var ServiceTypeStatelessSingleton ServiceType = "stateless_singleton"
// ServiceTypeStatelessMultiple stateless_multiple
var ServiceTypeStatelessMultiple ServiceType = "stateless_multiple"
// ServiceTypeStateSingleton state_singleton
var ServiceTypeStateSingleton ServiceType = "state_singleton"
// ServiceTypeStateMultiple state_multiple
var ServiceTypeStateMultiple ServiceType = "state_multiple"
2023-11-30 13:56:09 +08:00
// ServiceTypeVM vm
var ServiceTypeVM ServiceType = "vm"
2022-07-26 18:13:29 +08:00
// ServiceTypeJob job
var ServiceTypeJob ServiceType = "job"
2022-08-01 00:12:02 +08:00
// ServiceTypeCronJob cronjob
2022-07-31 22:36:28 +08:00
var ServiceTypeCronJob ServiceType = "cronjob"
2022-07-26 18:13:29 +08:00
2023-11-30 13:56:09 +08:00
// TenantServices app service base info
2017-11-07 11:40:44 +08:00
type TenantServices struct {
Model
TenantID string ` gorm:"column:tenant_id;size:32" json:"tenant_id" `
ServiceID string ` gorm:"column:service_id;size:32" json:"service_id" `
// 服务key
ServiceKey string ` gorm:"column:service_key;size:32" json:"service_key" `
// 服务别名
ServiceAlias string ` gorm:"column:service_alias;size:30" json:"service_alias" `
2018-11-14 23:08:30 +08:00
// service regist endpoint name(host name), used of statefulset
ServiceName string ` gorm:"column:service_name;size:100" json:"service_name" `
2020-03-16 16:19:08 +08:00
// ( This field is not currently used, use ExtendMethod) Service type now service support
2020-02-18 22:41:18 +08:00
ServiceType string ` gorm:"column:service_type;size:32" json:"service_type" `
2017-11-07 11:40:44 +08:00
// 服务描述
Comment string ` gorm:"column:comment" json:"comment" `
// 容器CPU权重
2021-08-12 23:24:32 +08:00
// default is 0, This means that CPU resources are not limited
ContainerCPU int ` gorm:"column:container_cpu;default:0" json:"container_cpu" `
2017-11-07 11:40:44 +08:00
// 容器最大内存
2021-08-12 23:24:32 +08:00
// default is 0, This means that Memory resources are not limited
ContainerMemory int ` gorm:"column:container_memory;default:0" json:"container_memory" `
2021-06-17 22:59:05 +08:00
// container GPU, The amount of video memory applied for GPU. The unit is MiB
// default is 0, That means no GPU is required
ContainerGPU int ` gorm:"column:container_gpu;default:0" json:"container_gpu" `
2018-11-19 18:56:28 +08:00
//UpgradeMethod service upgrade controller type
//such as : `Rolling` `OnDelete`
UpgradeMethod string ` gorm:"column:upgrade_method;default:'Rolling'" json:"upgrade_method" `
2020-03-16 16:19:08 +08:00
// 组件类型 component deploy type stateless_singleton/stateless_multiple/state_singleton/state_multiple
2017-11-07 11:40:44 +08:00
ExtendMethod string ` gorm:"column:extend_method;default:'stateless';" json:"extend_method" `
// 节点数
Replicas int ` gorm:"column:replicas;default:1" json:"replicas" `
// 部署版本
DeployVersion string ` gorm:"column:deploy_version" json:"deploy_version" `
// 服务分类: application,cache,store
Category string ` gorm:"column:category" json:"category" `
2018-11-14 23:08:30 +08:00
// 服务当前状态: undeploy,running,closed,unusual,starting,checking,stoping(deprecated)
2017-11-07 11:40:44 +08:00
CurStatus string ` gorm:"column:cur_status;default:'undeploy'" json:"cur_status" `
2018-11-14 23:08:30 +08:00
// 计费状态 为1 计费, 为0不计费 (deprecated)
2017-11-07 11:40:44 +08:00
Status int ` gorm:"column:status;default:0" json:"status" `
// 最新操作ID
EventID string ` gorm:"column:event_id" json:"event_id" `
2018-11-14 23:08:30 +08:00
// 租户ID
2017-11-07 11:40:44 +08:00
Namespace string ` gorm:"column:namespace" json:"namespace" `
// 更新时间
UpdateTime time . Time ` gorm:"column:update_time" json:"update_time" `
// 服务创建类型cloud云市服务,assistant云帮服务
ServiceOrigin string ` gorm:"column:service_origin;default:'assistant'" json:"service_origin" `
2021-06-30 16:46:39 +08:00
// kind of service. option: internal, third_party, custom
2019-02-25 01:07:37 +08:00
Kind string ` gorm:"column:kind;default:'internal'" json:"kind" `
2020-09-17 18:28:37 +08:00
// service bind appID
2020-09-18 10:18:12 +08:00
AppID string ` gorm:"column:app_id" json:"app_id" `
2021-11-15 17:39:20 +08:00
// Component name in cluster
K8sComponentName string ` gorm:"column:k8s_component_name" json:"k8s_component_name" `
2022-07-31 22:36:28 +08:00
// Job任务策略
JobStrategy string ` gorm:"column:job_strategy" json:"job_strategy" `
2018-03-04 22:48:50 +08:00
}
2022-01-20 22:14:50 +08:00
// ComponentWorkload -
type ComponentWorkload struct {
K8sApp string ` gorm:"column:k8s_app" `
K8sComponentName string ` gorm:"column:k8s_component_name" `
ComponentID string ` gorm:"column:service_id" `
ServiceAlias string ` gorm:"column:service_alias" `
}
2023-11-30 13:56:09 +08:00
// Image 镜像
2018-03-04 22:48:50 +08:00
type Image struct {
Host string
Namespace string
Name string
}
func ( i Image ) String ( ) string {
2020-06-16 21:44:24 +08:00
if i . Namespace == "" {
return fmt . Sprintf ( "%s/%s" , i . Host , i . Name )
}
2018-03-04 22:48:50 +08:00
return fmt . Sprintf ( "%s/%s/%s" , i . Host , i . Namespace , i . Name )
}
2023-11-30 13:56:09 +08:00
// ParseImage 简单解析镜像名
2018-03-04 22:48:50 +08:00
func ParseImage ( name string ) ( image Image ) {
i := strings . IndexRune ( name , '/' )
if i == - 1 || ( ! strings . ContainsAny ( name [ : i ] , ".:" ) && name [ : i ] != "localhost" ) {
image . Host , image . Name = "docker.io" , name
} else {
image . Host , image . Name = name [ : i ] , name [ i + 1 : ]
}
j := strings . IndexRune ( image . Name , '/' )
if j != - 1 {
image . Namespace = image . Name [ : j ]
image . Name = image . Name [ j + 1 : ]
}
return
}
2023-11-30 13:56:09 +08:00
// CreateShareSlug 生成源码包分享的地址
2018-03-05 15:07:19 +08:00
func ( t * TenantServices ) CreateShareSlug ( servicekey , namespace , version string ) string {
return fmt . Sprintf ( "%s/%s/%s_%s.tgz" , namespace , servicekey , version , t . DeployVersion )
2018-03-04 22:48:50 +08:00
}
2023-11-30 13:56:09 +08:00
// ChangeDelete ChangeDelete
2017-11-07 11:40:44 +08:00
func ( t * TenantServices ) ChangeDelete ( ) * TenantServicesDelete {
delete := TenantServicesDelete ( * t )
2018-11-22 14:33:29 +08:00
delete . UpdateTime = time . Now ( )
2017-11-07 11:40:44 +08:00
return & delete
}
2023-11-30 13:56:09 +08:00
// Autodomain 构建默认域名
2017-11-07 11:40:44 +08:00
func ( t * TenantServices ) Autodomain ( tenantName string , containerPort int ) string {
exDomain := os . Getenv ( "EX_DOMAIN" )
if exDomain == "" {
return ""
}
if strings . Contains ( exDomain , ":" ) {
exDomain = strings . Split ( exDomain , ":" ) [ 0 ]
}
2018-03-14 12:43:35 +08:00
return fmt . Sprintf ( "%d.%s.%s.%s" , containerPort , t . ServiceAlias , tenantName , exDomain )
2017-11-07 11:40:44 +08:00
}
2023-11-30 13:56:09 +08:00
// TableName 表名
2017-11-07 11:40:44 +08:00
func ( t * TenantServices ) TableName ( ) string {
return "tenant_services"
}
2023-11-30 13:56:09 +08:00
// TenantServicesDelete 已删除的应用表
2017-11-07 11:40:44 +08:00
type TenantServicesDelete struct {
Model
TenantID string ` gorm:"column:tenant_id;size:32" json:"tenant_id" `
ServiceID string ` gorm:"column:service_id;size:32" json:"service_id" `
// 服务key
ServiceKey string ` gorm:"column:service_key;size:32" json:"service_key" `
// 服务别名
ServiceAlias string ` gorm:"column:service_alias;size:30" json:"service_alias" `
2018-11-14 23:08:30 +08:00
// service regist endpoint name(host name), used of statefulset
ServiceName string ` gorm:"column:service_name;size:100" json:"service_name" `
2020-02-18 22:41:18 +08:00
// Service type now service support stateless_singleton/stateless_multiple/state_singleton/state_multiple
ServiceType string ` gorm:"column:service_type;size:20" json:"service_type" `
2017-11-07 11:40:44 +08:00
// 服务描述
Comment string ` gorm:"column:comment" json:"comment" `
// 容器CPU权重
ContainerCPU int ` gorm:"column:container_cpu;default:500" json:"container_cpu" `
// 容器最大内存
ContainerMemory int ` gorm:"column:container_memory;default:128" json:"container_memory" `
2021-06-17 22:59:05 +08:00
// container GPU, The amount of video memory applied for GPU. The unit is MiB
// default is 0, That means no GPU is required
ContainerGPU int ` gorm:"column:container_gpu;default:0" json:"container_gpu" `
2018-11-19 18:56:28 +08:00
//UpgradeMethod service upgrade controller type
//such as : `Rolling` `OnDelete`
UpgradeMethod string ` gorm:"column:upgrade_method;default:'Rolling'" json:"upgrade_method" `
2017-11-07 11:40:44 +08:00
// 扩容方式; 0:无状态; 1:有状态; 2:分区
ExtendMethod string ` gorm:"column:extend_method;default:'stateless';" json:"extend_method" `
// 节点数
Replicas int ` gorm:"column:replicas;default:1" json:"replicas" `
// 部署版本
DeployVersion string ` gorm:"column:deploy_version" json:"deploy_version" `
// 服务分类: application,cache,store
Category string ` gorm:"column:category" json:"category" `
2018-11-22 14:33:29 +08:00
// 服务当前状态: undeploy,running,closed,unusual,starting,checking,stoping(deprecated)
2017-11-07 11:40:44 +08:00
CurStatus string ` gorm:"column:cur_status;default:'undeploy'" json:"cur_status" `
2018-11-22 14:33:29 +08:00
// 计费状态 为1 计费, 为0不计费 (deprecated)
2017-11-07 11:40:44 +08:00
Status int ` gorm:"column:status;default:0" json:"status" `
// 最新操作ID
EventID string ` gorm:"column:event_id" json:"event_id" `
2018-11-22 14:33:29 +08:00
// 租户ID
2017-11-07 11:40:44 +08:00
Namespace string ` gorm:"column:namespace" json:"namespace" `
// 更新时间
UpdateTime time . Time ` gorm:"column:update_time" json:"update_time" `
// 服务创建类型cloud云市服务,assistant云帮服务
ServiceOrigin string ` gorm:"column:service_origin;default:'assistant'" json:"service_origin" `
2019-02-25 01:07:37 +08:00
// kind of service. option: internal, third_party
Kind string ` gorm:"column:kind;default:'internal'" json:"kind" `
2020-09-17 18:28:37 +08:00
// service bind appID
2020-09-18 10:18:12 +08:00
AppID string ` gorm:"column:app_id" json:"app_id" `
2021-11-15 17:39:20 +08:00
// Component name in cluster
K8sComponentName string ` gorm:"column:k8s_component_name" json:"k8s_component_name" `
2022-07-31 22:36:28 +08:00
// Job任务策略
JobStrategy string ` gorm:"column:job_strategy" json:"job_strategy" `
2017-11-07 11:40:44 +08:00
}
2023-11-30 13:56:09 +08:00
// TableName 表名
2017-11-07 11:40:44 +08:00
func ( t * TenantServicesDelete ) TableName ( ) string {
return "tenant_services_delete"
}
2023-11-30 13:56:09 +08:00
// TenantServicesPort 应用端口信息
2018-11-19 18:56:28 +08:00
type TenantServicesPort struct {
2017-11-07 11:40:44 +08:00
Model
TenantID string ` gorm:"column:tenant_id;size:32" validate:"tenant_id|between:30,33" json:"tenant_id" `
ServiceID string ` gorm:"column:service_id;size:32" validate:"service_id|between:30,33" json:"service_id" `
ContainerPort int ` gorm:"column:container_port" validate:"container_port|required|numeric_between:1,65535" json:"container_port" `
MappingPort int ` gorm:"column:mapping_port" validate:"mapping_port|required|numeric_between:1,65535" json:"mapping_port" `
2019-02-25 20:04:48 +08:00
Protocol string ` gorm:"column:protocol" validate:"protocol|required|in:http,https,tcp,grpc,udp,mysql" json:"protocol" `
2017-11-07 11:40:44 +08:00
PortAlias string ` gorm:"column:port_alias" validate:"port_alias|required|alpha_dash" json:"port_alias" `
2019-05-18 17:59:35 +08:00
IsInnerService * bool ` gorm:"column:is_inner_service" validate:"is_inner_service|bool" json:"is_inner_service" `
IsOuterService * bool ` gorm:"column:is_outer_service" validate:"is_outer_service|bool" json:"is_outer_service" `
2020-09-27 16:27:46 +08:00
K8sServiceName string ` gorm:"column:k8s_service_name" json:"k8s_service_name" `
2022-09-01 22:20:38 +08:00
Name string ` gorm:"name" json:"name" `
2017-11-07 11:40:44 +08:00
}
2021-05-27 16:55:53 +08:00
// Key returns the key of TenantServicesPort.
func ( t * TenantServicesPort ) Key ( ) string {
return fmt . Sprintf ( "%s/%s/%d" , t . TenantID , t . ServiceID , t . ContainerPort )
}
2023-11-30 13:56:09 +08:00
// TableName 表名
2017-11-07 11:40:44 +08:00
func ( t * TenantServicesPort ) TableName ( ) string {
return "tenant_services_port"
}
2021-06-21 16:48:25 +08:00
// IsOpen checks if the port is opened.
func ( t * TenantServicesPort ) IsOpen ( ) bool {
return commonutil . BoolValue ( t . IsOuterService ) || commonutil . BoolValue ( t . IsInnerService )
}
2023-11-30 13:56:09 +08:00
// TenantServiceLBMappingPort stream应用端口映射情况
2017-11-07 11:40:44 +08:00
type TenantServiceLBMappingPort struct {
Model
ServiceID string ` gorm:"column:service_id;size:32" `
//负载均衡VS使用端口
Port int ` gorm:"column:port;unique_index" `
//此字段废除
// IP string `gorm:"column:ip"`
//应用原端口
ContainerPort int ` gorm:"column:container_port" `
}
2023-11-30 13:56:09 +08:00
// TableName 表名
2017-11-07 11:40:44 +08:00
func ( t * TenantServiceLBMappingPort ) TableName ( ) string {
return "tenant_lb_mapping_port"
}
2023-11-30 13:56:09 +08:00
// TenantServiceRelation 应用依赖关系
2017-11-07 11:40:44 +08:00
type TenantServiceRelation struct {
Model
TenantID string ` gorm:"column:tenant_id;size:32" validate:"tenant_id" json:"tenant_id" `
ServiceID string ` gorm:"column:service_id;size:32" validate:"service_id" json:"service_id" `
DependServiceID string ` gorm:"column:dep_service_id;size:32" validate:"depend_service_id" json:"depend_service_id" `
DependServiceType string ` gorm:"column:dep_service_type" validate:"dep_service_type" json:"dep_service_type" `
DependOrder int ` gorm:"column:dep_order" validate:"dep_order" json:"dep_order" `
}
2023-11-30 13:56:09 +08:00
// TableName 表名
2017-11-07 11:40:44 +08:00
func ( t * TenantServiceRelation ) TableName ( ) string {
2018-11-22 14:33:29 +08:00
return "tenant_services_relation"
2017-11-07 11:40:44 +08:00
}
2023-11-30 13:56:09 +08:00
// TenantServiceEnvVar 应用环境变量
2017-11-07 11:40:44 +08:00
type TenantServiceEnvVar struct {
Model
TenantID string ` gorm:"column:tenant_id;size:32" validate:"tenant_id|between:30,33" json:"tenant_id" `
ServiceID string ` gorm:"column:service_id;size:32" validate:"service_id|between:30,33" json:"service_id" `
ContainerPort int ` gorm:"column:container_port" validate:"container_port|numeric_between:1,65535" json:"container_port" `
2021-02-03 15:32:33 +08:00
Name string ` gorm:"column:name;size:1024" validate:"name" json:"name" `
AttrName string ` gorm:"column:attr_name;size:1024" validate:"env_name|required" json:"attr_name" `
2021-04-12 18:45:59 +08:00
AttrValue string ` gorm:"column:attr_value;type:text" validate:"env_value|required" json:"attr_value" `
2017-11-07 11:40:44 +08:00
IsChange bool ` gorm:"column:is_change" validate:"is_change|bool" json:"is_change" `
Scope string ` gorm:"column:scope;default:'outer'" validate:"scope|in:outer,inner,both" json:"scope" `
}
2023-11-30 13:56:09 +08:00
// TableName 表名
2017-11-07 11:40:44 +08:00
func ( t * TenantServiceEnvVar ) TableName ( ) string {
//TODO:表名修改
2018-11-22 14:33:29 +08:00
return "tenant_services_envs"
2017-11-07 11:40:44 +08:00
}
2023-11-30 13:56:09 +08:00
// TenantServiceMountRelation 应用挂载依赖纪录
2017-11-07 11:40:44 +08:00
type TenantServiceMountRelation struct {
Model
TenantID string ` gorm:"column:tenant_id;size:32" json:"tenant_id" validate:"tenant_id|between:30,33" `
ServiceID string ` gorm:"column:service_id;size:32" json:"service_id" validate:"service_id|between:30,33" `
DependServiceID string ` gorm:"column:dep_service_id;size:32" json:"dep_service_id" validate:"dep_service_id|between:30,33" `
//挂载路径(挂载应用可自定义)
VolumePath string ` gorm:"column:mnt_name" json:"volume_path" validate:"volume_path|required" `
//主机路径(依赖应用的共享存储对应的主机路径)
HostPath string ` gorm:"column:mnt_dir" json:"host_path" validate:"host_path" `
//存储名称(依赖应用的共享存储对应的名称)
VolumeName string ` gorm:"column:volume_name;size:40" json:"volume_name" validate:"volume_name|required" `
2019-01-08 14:43:32 +08:00
VolumeType string ` gorm:"column:volume_type" json:"volume_type" validate:"volume_type|required" `
2017-11-07 11:40:44 +08:00
}
2023-11-30 13:56:09 +08:00
// TableName 表名
2017-11-07 11:40:44 +08:00
func ( t * TenantServiceMountRelation ) TableName ( ) string {
2018-11-22 14:33:29 +08:00
return "tenant_services_mnt_relation"
2017-11-07 11:40:44 +08:00
}
2023-11-30 13:56:09 +08:00
// VolumeType 存储类型
2017-11-07 11:40:44 +08:00
type VolumeType string
2023-11-30 13:56:09 +08:00
// ShareFileVolumeType 共享文件存储
2017-11-07 11:40:44 +08:00
var ShareFileVolumeType VolumeType = "share-file"
2023-11-30 13:56:09 +08:00
// LocalVolumeType 本地文件存储
2017-11-07 11:40:44 +08:00
var LocalVolumeType VolumeType = "local"
2023-11-30 13:56:09 +08:00
// PluginStorageType 插件存储
2022-06-07 19:20:31 +08:00
var PluginStorageType VolumeType = "plugin-storage"
2023-11-30 13:56:09 +08:00
// MemoryFSVolumeType 内存文件存储
2017-11-07 11:40:44 +08:00
var MemoryFSVolumeType VolumeType = "memoryfs"
2023-11-30 13:56:09 +08:00
// ConfigFileVolumeType configuration file volume type
2019-01-04 14:26:29 +08:00
var ConfigFileVolumeType VolumeType = "config-file"
2023-11-30 13:56:09 +08:00
// VMVolumeType vm file volume type
var VMVolumeType VolumeType = "vm-file"
2019-11-18 19:22:17 +08:00
// CephRBDVolumeType ceph rbd volume type
var CephRBDVolumeType VolumeType = "ceph-rbd"
2019-12-02 16:03:39 +08:00
// AliCloudVolumeType alicloud volume type
var AliCloudVolumeType VolumeType = "alicloud-disk"
2019-12-12 11:59:02 +08:00
// MakeNewVolume make volumeType
func MakeNewVolume ( name string ) VolumeType {
return VolumeType ( name )
}
2017-11-07 11:40:44 +08:00
func ( vt VolumeType ) String ( ) string {
return string ( vt )
}
2023-11-30 13:56:09 +08:00
// TenantServiceVolume 应用持久化纪录
2017-11-07 11:40:44 +08:00
type TenantServiceVolume struct {
Model
ServiceID string ` gorm:"column:service_id;size:32" json:"service_id" `
//服务类型
Category string ` gorm:"column:category;size:50" json:"category" `
//存储类型( share,local,tmpfs)
2019-12-12 11:59:02 +08:00
VolumeType string ` gorm:"column:volume_type;size:64" json:"volume_type" `
2017-11-07 11:40:44 +08:00
//存储名称
VolumeName string ` gorm:"column:volume_name;size:40" json:"volume_name" `
//主机地址
2022-11-01 17:59:57 +08:00
HostPath string ` gorm:"column:host_path;type:text" json:"host_path" `
2017-11-07 11:40:44 +08:00
//挂载地址
VolumePath string ` gorm:"column:volume_path" json:"volume_path" `
//是否只读
2021-06-08 11:53:32 +08:00
IsReadOnly bool ` gorm:"column:is_read_only;default:0" json:"is_read_only" `
2019-11-18 19:22:17 +08:00
// VolumeCapacity 存储大小
VolumeCapacity int64 ` gorm:"column:volume_capacity" json:"volume_capacity" `
2019-11-25 20:03:26 +08:00
// AccessMode 读写模式( Important! A volume can only be mounted using one access mode at a time, even if it supports many. For example, a GCEPersistentDisk can be mounted as ReadWriteOnce by a single node or ReadOnlyMany by many nodes, but not at the same time. #https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes)
2019-11-18 19:22:17 +08:00
AccessMode string ` gorm:"column:access_mode" json:"access_mode" `
// SharePolicy 共享模式
SharePolicy string ` gorm:"column:share_policy" json:"share_policy" `
// BackupPolicy 备份策略
BackupPolicy string ` gorm:"column:backup_policy" json:"backup_policy" `
2019-11-27 14:53:14 +08:00
// ReclaimPolicy 回收策略
ReclaimPolicy string ` json:"reclaim_policy" `
2019-11-18 19:22:17 +08:00
// AllowExpansion 是否支持扩展
AllowExpansion bool ` gorm:"column:allow_expansion" json:"allow_expansion" `
2019-11-25 20:03:26 +08:00
// VolumeProviderName 使用的存储驱动别名
2021-06-08 11:53:32 +08:00
VolumeProviderName string ` gorm:"column:volume_provider_name" json:"volume_provider_name" `
2021-07-28 18:30:28 +08:00
Mode * int32 ` gorm:"column:mode" json:"mode" `
2017-11-07 11:40:44 +08:00
}
2023-11-30 13:56:09 +08:00
// TableName 表名
2017-11-07 11:40:44 +08:00
func ( t * TenantServiceVolume ) TableName ( ) string {
2018-11-22 14:33:29 +08:00
return "tenant_services_volume"
2017-11-07 11:40:44 +08:00
}
2021-06-07 09:37:15 +08:00
// Key returns the key of TenantServiceVolume.
func ( t * TenantServiceVolume ) Key ( ) string {
return fmt . Sprintf ( "%s/%s" , t . ServiceID , t . VolumeName )
}
2019-01-06 22:13:19 +08:00
// TenantServiceConfigFile represents a data in configMap which is one of the types of volumes
type TenantServiceConfigFile struct {
Model
2019-03-06 14:06:42 +08:00
ServiceID string ` gorm:"column:service_id;size:32" json:"service_id" `
2022-11-01 17:59:57 +08:00
VolumeName string ` gorm:"column:volume_name;size:128" json:"volume_name" `
2019-01-06 22:13:19 +08:00
FileContent string ` gorm:"column:file_content;size:65535" json:"filename" `
}
2019-03-06 14:06:42 +08:00
// TableName returns table name of TenantServiceConfigFile.
2019-01-06 22:13:19 +08:00
func ( t * TenantServiceConfigFile ) TableName ( ) string {
return "tenant_service_config_file"
}
2023-11-30 13:56:09 +08:00
// TenantServiceLable 应用高级标签
2017-11-07 11:40:44 +08:00
type TenantServiceLable struct {
Model
ServiceID string ` gorm:"column:service_id;size:32" `
LabelKey string ` gorm:"column:label_key;size:50" `
LabelValue string ` gorm:"column:label_value;size:50" `
}
2023-11-30 13:56:09 +08:00
// TableName 表名
2017-11-07 11:40:44 +08:00
func ( t * TenantServiceLable ) TableName ( ) string {
2018-11-22 14:33:29 +08:00
return "tenant_services_label"
2017-11-07 11:40:44 +08:00
}
2023-11-30 13:56:09 +08:00
// LabelKeyNodeSelector 节点选择标签
2017-11-07 11:40:44 +08:00
var LabelKeyNodeSelector = "node-selector"
2023-11-30 13:56:09 +08:00
// LabelKeyNodeAffinity 节点亲和标签
2017-11-07 11:40:44 +08:00
var LabelKeyNodeAffinity = "node-affinity"
2023-11-30 13:56:09 +08:00
// LabelKeyServiceType 应用部署类型标签
2021-04-09 16:24:00 +08:00
// TODO fanyangyang 待删除, 组件类型记录在tenant_service表中
2017-11-07 11:40:44 +08:00
var LabelKeyServiceType = "service-type"
2023-11-30 13:56:09 +08:00
// LabelKeyServiceAffinity 应用亲和标签
2017-11-07 11:40:44 +08:00
var LabelKeyServiceAffinity = "service-affinity"
2023-11-30 13:56:09 +08:00
// LabelKeyServiceAntyAffinity 应用反亲和标签
2017-11-07 11:40:44 +08:00
var LabelKeyServiceAntyAffinity = "service-anti-affinity"
2018-11-22 14:33:29 +08:00
2020-01-18 09:25:21 +08:00
// LabelKeyServicePrivileged -
var LabelKeyServicePrivileged = "privileged"
2023-11-30 13:56:09 +08:00
// TenantServiceProbe 应用探针信息
2018-11-22 14:33:29 +08:00
type TenantServiceProbe struct {
Model
ServiceID string ` gorm:"column:service_id;size:32" json:"service_id" validate:"service_id|between:30,33" `
ProbeID string ` gorm:"column:probe_id;size:32" json:"probe_id" validate:"probe_id|between:30,33" `
Mode string ` gorm:"column:mode;default:'liveness'" json:"mode" validate:"mode" `
Scheme string ` gorm:"column:scheme;default:'scheme'" json:"scheme" validate:"scheme" `
Path string ` gorm:"column:path" json:"path" validate:"path" `
Port int ` gorm:"column:port;size:5;default:80" json:"port" validate:"port|required|numeric_between:1,65535" `
2022-11-16 13:47:51 +08:00
Cmd string ` gorm:"column:cmd;type:longtext;" json:"cmd" validate:"cmd" `
2018-11-22 14:33:29 +08:00
//http请求头, key=value,key2=value2
HTTPHeader string ` gorm:"column:http_header;size:300" json:"http_header" validate:"http_header" `
//初始化等候时间
2020-01-09 15:56:59 +08:00
InitialDelaySecond int ` gorm:"column:initial_delay_second;size:2;default:4" json:"initial_delay_second" validate:"initial_delay_second" `
2018-11-22 14:33:29 +08:00
//检测间隔时间
PeriodSecond int ` gorm:"column:period_second;size:2;default:3" json:"period_second" validate:"period_second" `
//检测超时时间
2020-01-09 15:56:59 +08:00
TimeoutSecond int ` gorm:"column:timeout_second;size:3;default:5" json:"timeout_second" validate:"timeout_second" `
2018-11-22 14:33:29 +08:00
//是否启用
2019-03-31 13:03:38 +08:00
IsUsed * int ` gorm:"column:is_used;size:1;default:1" json:"is_used" validate:"is_used" `
2018-11-22 14:33:29 +08:00
//标志为失败的检测次数
FailureThreshold int ` gorm:"column:failure_threshold;size:2;default:3" json:"failure_threshold" validate:"failure_threshold" `
//标志为成功的检测次数
2019-02-27 09:44:41 +08:00
SuccessThreshold int ` gorm:"column:success_threshold;size:2;default:1" json:"success_threshold" validate:"success_threshold" `
FailureAction string ` gorm:"column:failure_action;" json:"failure_action" validate:"failure_action" `
2018-11-22 14:33:29 +08:00
}
2019-03-09 21:54:17 +08:00
// FailureActionType type of failure action.
type FailureActionType string
func ( fat FailureActionType ) String ( ) string {
return string ( fat )
}
const (
// IgnoreFailureAction do nothing when the probe result is a failure
IgnoreFailureAction FailureActionType = "ignore"
// OfflineFailureAction offline the probe object when the probe result is a failure
OfflineFailureAction FailureActionType = "readiness"
// RestartFailureAction restart the probe object when the probe result is a failure
RestartFailureAction FailureActionType = "liveness"
)
2023-11-30 13:56:09 +08:00
// TableName 表名
2018-11-22 14:33:29 +08:00
func ( t * TenantServiceProbe ) TableName ( ) string {
return "tenant_services_probe"
}
2019-11-13 11:05:25 +08:00
// TenantServiceAutoscalerRules -
type TenantServiceAutoscalerRules struct {
Model
RuleID string ` gorm:"column:rule_id;unique;size:32" `
ServiceID string ` gorm:"column:service_id;size:32" `
Enable bool ` gorm:"column:enable" `
XPAType string ` gorm:"column:xpa_type;size:3" `
MinReplicas int ` gorm:"colume:min_replicas" `
MaxReplicas int ` gorm:"colume:max_replicas" `
}
// TableName -
func ( t * TenantServiceAutoscalerRules ) TableName ( ) string {
return "tenant_services_autoscaler_rules"
}
// TenantServiceAutoscalerRuleMetrics -
type TenantServiceAutoscalerRuleMetrics struct {
Model
RuleID string ` gorm:"column:rule_id;size:32;not null" `
MetricsType string ` gorm:"column:metric_type;not null" `
MetricsName string ` gorm:"column:metric_name;not null" `
MetricTargetType string ` gorm:"column:metric_target_type;not null" `
MetricTargetValue int ` gorm:"column:metric_target_value;not null" `
}
// TableName -
func ( t * TenantServiceAutoscalerRuleMetrics ) TableName ( ) string {
return "tenant_services_autoscaler_rule_metrics"
}
2019-11-14 15:30:40 +08:00
// TenantServiceScalingRecords -
type TenantServiceScalingRecords struct {
Model
2019-11-18 15:34:24 +08:00
ServiceID string ` gorm:"column:service_id" json:"-" `
RuleID string ` gorm:"column:rule_id" json:"rule_id" `
2019-11-14 15:30:40 +08:00
EventName string ` gorm:"column:event_name;not null" json:"record_id" `
RecordType string ` gorm:"column:record_type" json:"record_type" `
Reason string ` gorm:"column:reason" json:"reason" `
Count int32 ` gorm:"column:count" json:"count" `
2019-11-18 15:34:24 +08:00
Description string ` gorm:"column:description;size:1023" json:"description" `
Operator string ` gorm:"column:operator" json:"operator" `
2019-11-14 15:30:40 +08:00
LastTime time . Time ` gorm:"column:last_time" json:"last_time" `
}
// TableName -
func ( t * TenantServiceScalingRecords ) TableName ( ) string {
return "tenant_services_scaling_records"
}
2020-09-22 14:37:52 +08:00
2020-09-23 14:48:53 +08:00
// ServiceID -
type ServiceID struct {
ServiceID string ` gorm:"column:service_id" json:"-" `
2020-09-22 14:37:52 +08:00
}