Documentation ¶
Index ¶
- Constants
- Variables
- func AlertRuleKey(cluster, namespace, name string) string
- func ChannelIDNameByReceiverName(recName string) (string, uint)
- func CheckGraphs(graphs []prometheus.MetricGraph, namespace string, ...) error
- func FillDefaultLimigrange(env *Environment) []byte
- func FormatMysqlError(me *mysql.MySQLError) error
- func GetErrMessage(err error) error
- func InitBaseData(db *gorm.DB) error
- func InitClusterData(ctx context.Context, db *gorm.DB, globalvalues string) error
- func IsNotFound(err error) bool
- func IsValidAlertRuleName(name string) error
- func MigrateDatabaseAndInitData(ctx context.Context, opts *database.Options, migrate, initData bool, ...) error
- func MigrateModels(db *gorm.DB) error
- func NewChannnelMappler(db *gorm.DB) *channels.ChannelMapper
- func NewPromqlTplMapperFromFile() *templates.PromqlTplMapper
- func WaitDatabaseServer(ctx context.Context, opts *database.Options) error
- func WaitRedis(ctx context.Context, redisopts redis.Options) error
- type AlertChannel
- type AlertInfo
- type AlertLevel
- type AlertLevels
- type AlertMessage
- type AlertReceiver
- type AlertRule
- type Announcement
- type Application
- type AuditLog
- type AuthSource
- type AuthSourceConfig
- type AuthSourceSimple
- type CPUMemoryStatus
- type ChartRepo
- type Cluster
- type CommonUserIface
- type Condition
- type Container
- type Environment
- type EnvironmentResource
- type EnvironmentUserRels
- type LogQueryHistory
- type LogQueryHistoryWithCount
- type LogQuerySnapshot
- type LogqlGenerator
- type Message
- type MonitorDashboard
- type MonitorDashboardTpl
- type Notice
- type Project
- type ProjectUserRels
- type PromqlGenerator
- type PromqlTplResource
- type PromqlTplRule
- type PromqlTplScope
- type Registry
- type SystemRole
- type Tenant
- type TenantResourceQuota
- type TenantResourceQuotaApply
- type TenantUserRels
- type User
- func (u *User) GetEmail() string
- func (u *User) GetID() uint
- func (u *User) GetMail() string
- func (u *User) GetSource() string
- func (u *User) GetSystemRoleID() uint
- func (u *User) GetUserKind() string
- func (u *User) GetUsername() string
- func (u User) MarshalBinary() ([]byte, error)
- func (u *User) SetLastLogin(t *time.Time)
- func (u *User) UnmarshalBinary(data []byte) error
- type UserCreate
- type UserMessageStatus
- type UserSel
- type UserToken
- type VirtualDomain
- type VirtualSpace
- type VirtualSpaceUserRels
- type Workload
Constants ¶
const ( SyncStatusRunning = "running" SyncStatusError = "error" SyncStatusSuccess = "success" )
const ( EnvironmentRoleReader = "reader" EnvironmentRoleOperator = "operator" ResEnvironment = "environment" )
const ( ProjectRoleAdmin = "admin" ProjectRoleDev = "dev" ProjectRoleTest = "test" ProjectRoleOps = "ops" ResProject = "project" )
const ( SystemRoleAdmin = "sysadmin" SystemRoleOrdinary = "ordinary" ResSystemRole = "systemrole" )
const ( TenantRoleAdmin = "admin" TenantRoleOrdinary = "ordinary" ResTenant = "tenant" )
const ( QuotaStatusApproved = "approved" QuotaStatusRejected = "rejected" QuotaStatusPending = "pending" )
const ( ResVirtualSpace = "virtualSpace" VirtualSpaceRoleAdmin = "admin" VirtualSpaceRoleNormal = "normal" )
const ( StatusVeryHigh = "very_high" // 非常高,要扩容 StatusHigh = "high" // 高,要扩容 StatusLow = "low" // 低,要缩容 ColorYellow = "yellow" ColorRed = "red" Ki = 1 << 10 // 1024 Mi = 1 << 20 Gi = 1 << 30 )
const (
ResUser = "user"
)
const (
ResVirtualDomain = "virtualDomain"
)
const SelfClusterAgentAddress = "https://kubegems-local-agent.kubegems-local:8041"
const WaitPerid = 5 * time.Second
Variables ¶
var ( DefaultChannel = &AlertChannel{ ID: 1, Name: defaultChannelName, ChannelConfig: channels.ChannelConfig{ ChannelIf: &channels.Webhook{ BaseChannel: channels.BaseChannel{ ChannelType: channels.TypeWebhook, SendResolved: true, }, URL: channels.KubegemsWebhookURL, InsecureSkipVerify: true, }, }, } DefaultReceiver = DefaultChannel.ChannelConfig.ChannelIf.ToReceiver(DefaultChannel.ReceiverName()) )
var ResChartRepo = "chartrepo"
Functions ¶
func AlertRuleKey ¶ added in v1.23.0
func ChannelIDNameByReceiverName ¶ added in v1.22.0
func CheckGraphs ¶ added in v1.22.0
func CheckGraphs(graphs []prometheus.MetricGraph, namespace string, tplGetter templates.TplGetter) error
func FillDefaultLimigrange ¶
func FillDefaultLimigrange(env *Environment) []byte
func FormatMysqlError ¶ added in v1.23.8
func FormatMysqlError(me *mysql.MySQLError) error
func GetErrMessage ¶
func InitClusterData ¶ added in v1.24.1
func IsNotFound ¶
func IsValidAlertRuleName ¶ added in v1.23.1
[metadata.name: Invalid value: "艹": a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'), metadata.labels: Invalid value: "艹": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue', or 'my_value', or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')]
func MigrateModels ¶ added in v1.23.0
func NewChannnelMappler ¶ added in v1.22.0
func NewChannnelMappler(db *gorm.DB) *channels.ChannelMapper
func NewPromqlTplMapperFromFile ¶ added in v1.22.0
func NewPromqlTplMapperFromFile() *templates.PromqlTplMapper
func WaitDatabaseServer ¶ added in v1.22.0
Types ¶
type AlertChannel ¶ added in v1.22.0
type AlertChannel struct { ID uint `gorm:"primarykey" json:"id"` Name string `gorm:"type:varchar(50)" binding:"min=1,max=50" json:"name"` ChannelConfig channels.ChannelConfig `json:"channelConfig"` TenantID *uint `json:"tenantID"` // 若为null,则表示系统预置 Tenant *Tenant `gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;" json:"tenant,omitempty"` CreatedAt *time.Time `json:"-"` UpdatedAt *time.Time `json:"-"` }
AlertChannel
func (*AlertChannel) ReceiverName ¶ added in v1.22.0
func (c *AlertChannel) ReceiverName() string
func (*AlertChannel) ToAlertmanagerReceiver ¶ added in v1.23.0
func (c *AlertChannel) ToAlertmanagerReceiver() v1alpha1.Receiver
type AlertInfo ¶
type AlertInfo struct { Fingerprint string `gorm:"type:varchar(50);primaryKey"` // 指纹作为主键 Name string `gorm:"type:varchar(50);"` Namespace string `gorm:"type:varchar(50);"` ClusterName string `gorm:"type:varchar(50);"` TenantName string `gorm:"type:varchar(50);index"` ProjectName string `gorm:"type:varchar(50);index"` EnvironmentName string `gorm:"type:varchar(50);index"` Labels datatypes.JSON LabelMap map[string]string `gorm:"-" json:"-"` SilenceStartsAt *time.Time SilenceUpdatedAt *time.Time SilenceEndsAt *time.Time SilenceCreator string `gorm:"type:varchar(50);"` Summary string `gorm:"-"` // 黑名单概要 }
type AlertLevel ¶ added in v1.23.0
type AlertLevels ¶ added in v1.23.0
type AlertLevels []AlertLevel
func (AlertLevels) GormDataType ¶ added in v1.23.0
func (m AlertLevels) GormDataType() string
func (*AlertLevels) Scan ¶ added in v1.23.0
func (m *AlertLevels) Scan(val interface{}) error
type AlertMessage ¶
type AlertMessage struct { ID uint // 级联删除 InfoFingerprint string `gorm:"type:varchar(50);column:fingerprint;"` AlertInfo *AlertInfo `gorm:"foreignKey:InfoFingerprint;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` Value string Message string StartsAt *time.Time `gorm:"index"` // 告警开始时间 EndsAt *time.Time // 告警结束时间 CreatedAt *time.Time `gorm:"index"` // 本次告警产生时间 Status string // firing or resolved }
func (*AlertMessage) ColumnSlice ¶
func (a *AlertMessage) ColumnSlice() []string
func (*AlertMessage) ToNormalMessage ¶
func (a *AlertMessage) ToNormalMessage() Message
func (*AlertMessage) ValueSlice ¶
func (a *AlertMessage) ValueSlice() []string
type AlertReceiver ¶ added in v1.23.0
type AlertReceiver struct { ID uint `gorm:"primarykey" json:"id"` AlertRuleID uint `json:"alertRuleID"` AlertRule *AlertRule `json:"-"` // 不展示给前端 AlertChannelID uint `json:"alertChannelID"` AlertChannel *AlertChannel `gorm:"constraint:OnUpdate:CASCADE,OnDelete:RESTRICT" json:"alertChannel"` // 删除channel时RESTRICT拒绝 Interval string `json:"interval"` }
type AlertRule ¶ added in v1.23.0
type AlertRule struct { ID uint `gorm:"primarykey" json:"id"` Cluster string `gorm:"type:varchar(50)" json:"cluster"` Namespace string `gorm:"type:varchar(50)" json:"namespace"` Name string `gorm:"type:varchar(50)" binding:"min=1,max=50" json:"name"` AlertType string `gorm:"type:varchar(50);default:monitor" json:"alertType"` // logging or monitor Expr string `json:"expr"` // promql/logql表达式,不能包含比较运算符(<, <=, >, >=, ==) For string `gorm:"type:varchar(50)" binding:"required" json:"for"` // 持续时间, eg. 10s, 1m, 1h Message string `json:"message"` // 告警消息 InhibitLabels gormdatatypes.JSONSlice `json:"inhibitLabels"` // 如果有多个告警级别,需要配置告警抑制的labels AlertLevels AlertLevels `json:"alertLevels"` // 告警级别 Receivers []*AlertReceiver `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"receivers"` // 接收器, 删除alertrule时级联删除 PromqlGenerator *PromqlGenerator `json:"promqlGenerator"` LogqlGenerator *LogqlGenerator `json:"logqlGenerator"` IsOpen bool `gorm:"default:true" json:"isOpen"` // 是否启用 State string `json:"state"` // 状态 RealTimeAlerts []*promv1.Alert `gorm:"-" json:"realTimeAlerts"` // 实时告警 // eg: status: ok/error // reason: alertmanagerconfig lost/receiver not matched/... K8sResourceStatus gormdatatypes.JSONMap `gorm:"type:varchar(50)" json:"k8sResourceStatus"` // 对应的k8s资源状态 Origin string `gorm:"-" json:"origin,omitempty"` // rule group CreatedAt *time.Time `json:"createdAt"` UpdatedAt *time.Time `json:"updatedAt"` }
AlertRule
type Announcement ¶ added in v1.22.0
type Announcement struct { ID uint `gorm:"primarykey" json:"id"` Type string `gorm:"type:varchar(50);" json:"type"` Message string `json:"message"` StartAt *time.Time `json:"startAt"` // 开始时间,默认现在 EndAt *time.Time `json:"endAt"` // 结束时间,默认一天后 CreatedAt *time.Time `json:"createdAt"` UpdatedAt *time.Time `json:"updatedAt"` }
type Application ¶
type Application struct { ID uint `gorm:"primarykey"` ApplicationName string `gorm:"type:varchar(50);uniqueIndex:uniq_idx_project_applicationname;<-:create"` // 应用名字 Environment *Environment `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` // 关联的环境 EnvironmentID *uint `gorm:"uniqueIndex:uniq_idx_project_applicationname;"` // 关联的环境 Project *Project `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` // 所属项 ProjectID uint `gorm:"uniqueIndex:uniq_idx_project_applicationname"` // 所属项目ID Remark string // 备注 Kind string // 类型 Images datatypes.JSON // 镜像,逗号分割 Labels datatypes.JSON // Label Creator string // 创建人 CreatedAt time.Time `sql:"DEFAULT:'current_timestamp'"` // 创建时间 }
Application 应用表
type AuditLog ¶
type AuditLog struct { ID uint `gorm:"primarykey"` CreatedAt time.Time `gorm:"index"` UpdatedAt time.Time DeletedAt gorm.DeletedAt `gorm:"index"` // 操作用户 Username string `gorm:"type:varchar(50)"` // 所属租户 Tenant string `gorm:"type:varchar(50)"` // 操作模块 (资源类型,租户,项目,环境,报警规则等等) Module string `gorm:"type:varchar(512)"` // 模块名字 Name string `gorm:"type:varchar(512)"` // 动作名字 (启用,禁用,开启,关闭,添加,删除,修改等) Action string `gorm:"type:varchar(255)"` // 是否成功 请求是否成功 Success bool // 客户端ip 发起请求的客户端IP ClientIP string `gorm:"type:varchar(255)"` // 标签 记录一些额外的环境租户等数据信息 Labels datatypes.JSON // 原始数据 记录的是request和response以及http_code RawData datatypes.JSON }
审计日志的描述格式为:
{用户名} {时间} {操作}
操作:
{动作,增删查改} {资源类型} {资源名字}
AuditLog 审计日志表
type AuthSource ¶
type AuthSource struct { ID uint `json:"id"` Name string `gorm:"unique" json:"name"` Kind string `json:"kind" binding:"oneof=LDAP OAUTH"` Vendor string `gorm:"type:varchar(30)" json:"vendor" binding:"omitempty,oneof=github gitlab oauth ldap"` Config AuthSourceConfig `json:"config" binding:"required,json"` TokenType string `json:"tokenType" binding:"required,oneof=Bearer"` Enabled bool `json:"enabled"` CreatedAt *time.Time `json:"createdAt"` UpdatedAt *time.Time `json:"updatedAt"` }
type AuthSourceConfig ¶
type AuthSourceConfig struct { AuthURL string `json:"authURL,omitempty" binding:"omitempty,url,required_with=TokenURL UserInfoURL RedirectURL AppID AppSecret"` TokenURL string `json:"tokenURL,omitempty" binding:"omitempty,url,required_with=AuthURL UserInfoURL RedirectURL AppID AppSecret"` UserInfoURL string `json:"userInfoURL,omitempty" binding:"omitempty,url,required_with=AuthURL TokenURL RedirectURL AppID AppSecret"` RedirectURL string `json:"redirectURL,omitempty" binding:"omitempty,url,required_with=AuthURL TokenURL UserInfoURL AppID AppSecret"` AppID string `json:"appID,omitempty" binding:"required_with=AuthURL TokenURL UserInfoURL RedirectURL AppSecret"` AppSecret string `json:"appSecret,omitempty" binding:"required_with=AuthURL TokenURL UserInfoURL RedirectURL AppID"` Scopes []string `json:"scopes,omitempty"` // ldap Name string `json:"name,omitempty"` LdapAddr string `json:"ldapaddr,omitempty" binding:"omitempty,hostname_port,required_with=BaseDN BindUsername BindPassword"` BaseDN string `json:"basedn,omitempty" binding:"required_with=LdapAddr BindUsername BindPassword"` EnableTLS bool `json:"enableTLS,omitempty"` Filter string `json:"filter,omitempty"` BindUsername string `json:"binduser,omitempty" binding:"required_with=LdapAddr BaseDN BindPassword"` BindPassword string `json:"password,omitempty" binding:"required_with=LdapAddr BaseDN BindUsername"` }
func (*AuthSourceConfig) Scan ¶
func (cfg *AuthSourceConfig) Scan(value interface{}) error
type AuthSourceSimple ¶
type AuthSourceSimple struct { ID uint `json:"id"` Name string `gorm:"unique" json:"name"` Kind string `json:"kind"` Enabled bool `json:"enabled"` Vendor string `json:"vendor"` }
func (AuthSourceSimple) TableName ¶
func (AuthSourceSimple) TableName() string
type CPUMemoryStatus ¶
type CPUMemoryStatus struct { CurrentRate float64 CurrentLimit string // 带单位 Status string // 扩容或缩容 SuggestLimit string // 带单位 SuggestMinLimit string // 带单位 SuggestMaxLimit string // 带单位 }
func (*CPUMemoryStatus) AddSuggest ¶
func (status *CPUMemoryStatus) AddSuggest(SuggestType string, currentUsage float64) *CPUMemoryStatus
type Cluster ¶
type Cluster struct { ID uint `gorm:"primarykey"` ClusterName string `gorm:"type:varchar(50);uniqueIndex" binding:"required,fqdn_item"` APIServer string `gorm:"type:varchar(250);uniqueIndex"` // APIServer地址 根据kubeconfig添加后,自动填充 KubeConfig datatypes.JSON `binding:""` // kubeconfig is not required when use agent rbac. // Vendor 集群提供商(gke tke ack selfhosted) Vendor string `gorm:"type:varchar(50);default:selfhosted" binding:"required,oneof=selfhosted gke ack tke"` // ImageRepo 安装kubegems核心组件时使用的镜像仓库 ImageRepo string `gorm:"type:varchar(255);default:docker.io/kubegems" binding:"required"` // DefaultStorageClass 默认storageclass, 默认local-path DefaultStorageClass string `gorm:"type:varchar(255);default:local-path" binding:"required"` InstallNamespace string // agent service namespace Version string // apiserver version AgentAddr string // if empty, using apiserver proxy AgentCA string `json:"-"` AgentCert string `json:"-"` AgentKey string `json:"-"` Runtime string // docker or containerd Primary bool // 是否主集群 OversoldConfig datatypes.JSON // 集群资源超卖设置 Environments []*Environment TenantResourceQuotas []*TenantResourceQuota ClusterResourceQuota datatypes.JSON DeletedAt gorm.DeletedAt // soft delete ClientCertExpireAt *time.Time // 证书过期时间 }
Cluster 集群表
type CommonUserIface ¶
type Condition ¶
type Condition struct { Pods []string CPUStatus *CPUMemoryStatus `json:"CPUStatus"` MemoryStatus *CPUMemoryStatus `json:"MemoryStatus"` MaxCPUContainer *Container `json:"-"` MaxMemoryContainer *Container `json:"-"` CPULimitCore float64 `json:"-"` MemoryLimitBytes int64 `json:"-"` }
type Container ¶
type Container struct { ID uint `gorm:"primarykey"` Name string PodName string CPULimitCore float64 MemoryLimitBytes int64 // 限制 CPUUsageCore float64 CPUPercent float64 // 使用率 MemoryUsageBytes float64 MemoryPercent float64 // 使用率 WorkloadID uint Workload *Workload `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` }
Container 不注册为gorm model
type Environment ¶
type Environment struct { ID uint `gorm:"primarykey"` // 环境名字 EnvironmentName string `gorm:"type:varchar(50);uniqueIndex:uniq_idx_project_env;uniqueIndex:environment_uniq"` // 环境关联的namespace Namespace string `gorm:"type:varchar(50)"` // 备注 Remark string // 元类型(开发(dev),测试(test),生产(prod))等选项之一 MetaType string // 删除策略(delNamespace删除namespace,delLabels仅删除关联LABEL) DeletePolicy string `sql:"DEFAULT:'delNamespace'"` // 创建者 Creator *User `gorm:"constraint:OnUpdate:RESTRICT,OnDelete:SET NULL;"` // 关联的集群 Cluster *Cluster `gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;"` // 所属项目 Project *Project `gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;"` // 环境资源限制(这个会和namespace下的ResourceQuota对等) ResourceQuota datatypes.JSON // 环境下的limitrage LimitRange datatypes.JSON // 所属项目ID ProjectID uint `gorm:"uniqueIndex:uniq_idx_project_env"` // 所属集群ID ClusterID uint // 创建人ID CreatorID uint `gorm:"default:NULL"` // 关联的应用 Applications []*Application `gorm:"many2many:application_environment_rels;"` // 关联的用户 Users []*User `gorm:"many2many:environment_user_rels;"` // 允许边缘集群注册 AllowEdgeRegistration bool // 虚拟空间 VirtualSpaceID *uint VirtualSpace *VirtualSpace `gorm:"constraint:OnUpdate:RESTRICT,OnDelete:SET NULL;"` NSLabels map[string]string `gorm:"-"` }
Environment 环境表 环境属于项目,项目id-环境名字 唯一索引
type EnvironmentResource ¶
type EnvironmentResource struct { ID uint `gorm:"primarykey"` CreatedAt time.Time `sql:"DEFAULT:'current_timestamp'"` ClusterName string TenantName string ProjectName string EnvironmentName string MaxCPUUsageCore float64 MaxMemoryUsageByte float64 MinCPUUsageCore float64 MinMemoryUsageByte float64 AvgCPUUsageCore float64 AvgMemoryUsageByte float64 NetworkReceiveByte float64 NetworkSendByte float64 MaxPVCUsageByte float64 MinPVCUsageByte float64 AvgPVCUsageByte float64 }
EnvironmentResource Project资源使用清单
type EnvironmentUserRels ¶
type EnvironmentUserRels struct { ID uint `gorm:"primarykey"` User *User `json:",omitempty" gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;"` Environment *Environment `json:"omitempty" gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;"` // 用户ID UserID uint `gorm:"uniqueIndex:uniq_idx_env_user_rel" binding:"required"` // EnvironmentID EnvironmentID uint `gorm:"uniqueIndex:uniq_idx_env_user_rel" binding:"required"` // 环境级角色("reader", "operator") Role string `binding:"required,eq=reader|eq=operator"` }
EnvironmentUserRels
type LogQueryHistory ¶
type LogQueryHistory struct { ID uint `gorm:"primarykey"` // 关联的集群 Cluster *Cluster `gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;"` // 所属集群ID ClusterID uint // 标签 LabelJSON string `gorm:"type:varchar(1024)"` // 正则标签 FilterJSON string `gorm:"type:varchar(1024)"` // logql LogQL string `gorm:"type:varchar(1024)"` // 时间区间 TimeRange string `gorm:"type:varchar(256);default:''"` // 创建时间 CreateAt time.Time `sql:"DEFAULT:'current_timestamp'"` // 创建者 Creator *User `gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;"` CreatorID uint }
LogQueryHistory 日志查询历史
type LogQuerySnapshot ¶
type LogQuerySnapshot struct { ID uint `gorm:"primarykey"` // 关联的集群 Cluster *Cluster `gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;"` // 所属集群ID ClusterID uint // 名称 SnapshotName string `gorm:"type:varchar(128)"` SourceFile string `gorm:"type:varchar(128)"` // 行数 SnapshotCount int // 下载地址 DownloadURL string `gorm:"type:varchar(512)"` StartTime time.Time EndTime time.Time // 创建时间 CreateAt time.Time `sql:"DEFAULT:'current_timestamp'"` // 创建者 Creator *User `gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;"` CreatorID uint }
LogQuerySnapshot 日志查询快照
func (*LogQuerySnapshot) BeforeCreate ¶
func (snapshot *LogQuerySnapshot) BeforeCreate(tx *gorm.DB) error
func (*LogQuerySnapshot) BeforeDelete ¶
func (snapshot *LogQuerySnapshot) BeforeDelete(tx *gorm.DB) error
type LogqlGenerator ¶ added in v1.23.0
type LogqlGenerator struct { Duration string `json:"duration"` // 时间范围 Match string `json:"match"` // 正则匹配的字符串 LabelMatchers []promql.LabelMatcher `json:"labelMatchers"` // 标签筛选器 }
func (LogqlGenerator) GormDataType ¶ added in v1.23.0
func (m LogqlGenerator) GormDataType() string
func (*LogqlGenerator) Scan ¶ added in v1.23.0
func (m *LogqlGenerator) Scan(val interface{}) error
type Message ¶
type Message struct { ID uint `gorm:"primarykey"` MessageType string `gorm:"type:varchar(50);"` Title string `gorm:"type:varchar(255);"` Content datatypes.JSON CreatedAt time.Time `gorm:"index" sql:"DEFAULT:'current_timestamp'"` ToUsers map[uint]struct{} `gorm:"-" json:"-"` IsRead bool `gorm:"-"` // 给前端用,不入库 }
func (*Message) ColumnSlice ¶
func (*Message) ValueSlice ¶
type MonitorDashboard ¶
type MonitorDashboard struct { ID uint `gorm:"primarykey" json:"id"` // 面板名 Name string `gorm:"type:varchar(50)" binding:"required" json:"name"` Step string `gorm:"type:varchar(50)" json:"step"` // 样本间隔,单位秒 Refresh string `gorm:"type:varchar(50)" json:"refresh"` // 刷新间隔,eg. 30s, 1m Start string `gorm:"type:varchar(50)" json:"start"` // 开始时间,eg. 2022-04-24 06:00:45.241, now, now-30m End string `gorm:"type:varchar(50)" json:"end"` // 结束时间 CreatedAt *time.Time `json:"createdAt"` Creator string `gorm:"type:varchar(50)" json:"creator"` // 创建者 Graphs prometheus.MonitorGraphs `json:"graphs"` // 图表 Variables gormdatatypes.JSONMap `json:"variables"` // 变量 Template string `gorm:"type:varchar(50)" json:"template"` // 模板名 EnvironmentID *uint `json:"environmentID"` Environment *Environment `gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;" json:"environment"` }
MonitorDashboard 监控面板
type MonitorDashboardTpl ¶ added in v1.22.0
type MonitorDashboardTpl struct { Name string `gorm:"type:varchar(50);primaryKey" json:"name"` Description string `json:"description"` Step string `gorm:"type:varchar(50)" json:"step"` // 样本间隔,单位秒 Refresh string `gorm:"type:varchar(50)" json:"refresh"` // 刷新间隔,eg. 30s, 1m Start string `gorm:"type:varchar(50)" json:"start"` // 开始时间,eg. 2022-04-24 06:00:45.241, now, now-30m End string `gorm:"type:varchar(50)" json:"end"` // 结束时间 Graphs prometheus.MonitorGraphs `json:"graphs"` // 图表 Variables gormdatatypes.JSONMap `json:"variables"` // 变量 CreatedAt *time.Time `json:"-"` UpdatedAt *time.Time `json:"-"` }
type Project ¶
type Project struct { ID uint `gorm:"primarykey"` // 创建时间 CreatedAt time.Time `sql:"DEFAULT:'current_timestamp'"` // 项目名字 ProjectName string `gorm:"type:varchar(50);uniqueIndex:uniq_idx_tenant_project_name"` // 项目别名 ProjectAlias string `gorm:"type:varchar(50)"` // 项目备注 Remark string // 项目资源限制 ResourceQuota datatypes.JSON Applications []*Application Environments []*Environment Registries []*Registry Users []*User `gorm:"many2many:project_user_rels;"` Tenant *Tenant `gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;"` // 所属的租户ID TenantID uint `gorm:"uniqueIndex:uniq_idx_tenant_project_name"` }
Project 项目表
type ProjectUserRels ¶
type ProjectUserRels struct { ID uint `gorm:"primarykey"` User *User `json:",omitempty" gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;"` Project *Project `json:",omitempty" gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;"` // 用户ID UserID uint `gorm:"uniqueIndex:uniq_idx_project_user_rel" binding:"required"` // ProjectID ProjectID uint `gorm:"uniqueIndex:uniq_idx_project_user_rel" binding:"required"` // 项目级角色(管理员admin, 开发dev, 测试test, 运维ops) Role string `gorm:"type:varchar(30)" binding:"required,eq=admin|eq=test|eq=dev|eq=ops"` }
ProjectUserRels
type PromqlGenerator ¶ added in v1.23.0
type PromqlGenerator struct { Scope string `json:"scope"` // scope Resource string `json:"resource"` // 告警资源, eg. node、pod Rule string `json:"rule"` // 告警规则名, eg. cpuUsage、memoryUsagePercent Unit string `json:"unit"` // 单位 LabelMatchers []promql.LabelMatcher `json:"labelMatchers"` // 标签筛选器 Tpl *templates.PromqlTpl `json:"-"` }
func (PromqlGenerator) GormDataType ¶ added in v1.23.0
func (m PromqlGenerator) GormDataType() string
func (*PromqlGenerator) Scan ¶ added in v1.23.0
func (m *PromqlGenerator) Scan(val interface{}) error
type PromqlTplResource ¶ added in v1.22.0
type PromqlTplResource struct { ID uint `gorm:"primarykey" json:"id"` Name string `gorm:"type:varchar(50);uniqueIndex" binding:"required" json:"name"` ShowName string `gorm:"type:varchar(50)" json:"showName"` ScopeID *uint `json:"scopeID"` Scope *PromqlTplScope `gorm:"foreignKey:ScopeID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"scope,omitempty"` Rules []*PromqlTplRule `json:"rules" gorm:"foreignKey:ResourceID"` CreatedAt *time.Time `json:"-"` UpdatedAt *time.Time `json:"-"` }
PromqlTplScope
type PromqlTplRule ¶ added in v1.22.0
type PromqlTplRule struct { ID uint `gorm:"primarykey" json:"id"` Name string `gorm:"type:varchar(50)" binding:"required" json:"name"` ShowName string `gorm:"type:varchar(50)" json:"showName"` Description string `json:"description"` Expr string `json:"expr"` // promql expr Unit string `gorm:"type:varchar(50)" json:"unit"` Labels gormdatatypes.JSONSlice `json:"labels"` ResourceID *uint `json:"resourceID"` Resource *PromqlTplResource `gorm:"foreignKey:ResourceID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"resource,omitempty"` TenantID *uint `json:"tenantID"` // 若为null,则表示系统预置 Tenant *Tenant `gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;" json:"tenant,omitempty"` CreatedAt *time.Time `json:"-"` UpdatedAt *time.Time `json:"-"` }
PromqlTplScope
type PromqlTplScope ¶ added in v1.22.0
type PromqlTplScope struct { ID uint `gorm:"primarykey" json:"id"` Name string `gorm:"type:varchar(50);uniqueIndex" binding:"required" json:"name"` ShowName string `gorm:"type:varchar(50)" json:"showName"` Namespaced bool `json:"namespaced"` Resources []*PromqlTplResource `json:"resources" gorm:"foreignKey:ScopeID"` CreatedAt *time.Time `json:"-"` UpdatedAt *time.Time `json:"-"` }
PromqlTplScope
type Registry ¶
type Registry struct { ID uint `gorm:"primarykey"` // 仓库名称 RegistryName string `gorm:"type:varchar(50);uniqueIndex:uniq_idx_project_registry;"` // 仓库地址 RegistryAddress string `gorm:"type:varchar(512)"` // 用户名 Username string `gorm:"type:varchar(50)"` // 密码 Password string `gorm:"type:varchar(512)"` // 创建者 Creator *User `gorm:"constraint:OnUpdate:RESTRICT,OnDelete:SET NULL;"` // 更新时间 UpdateTime time.Time CreatorID uint `gorm:"default:null"` Project *Project `gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;"` // 项目ID ProjectID uint `grom:"uniqueIndex:uniq_idx_project_registry;"` IsDefault bool EnableExtends bool // 是否启用扩展功能,支持harbor等高级仓库 }
Registry 镜像仓库表
type SystemRole ¶
type SystemRole struct { ID uint `gorm:"primarykey"` // 角色名字 RoleName string // 系统级角色Code(管理员admin, 普通用户ordinary) RoleCode string `gorm:"type:varchar(30)" binding:"required,eq=sysadmin|eq=normal"` Users []*User }
SystemRole 系统角色
type Tenant ¶
type Tenant struct { ID uint `gorm:"primarykey"` // 租户名字 TenantName string `gorm:"type:varchar(50);uniqueIndex"` // 备注 Remark string // 是否激活 IsActive bool CreatedAt time.Time `sql:"DEFAULT:'current_timestamp'"` UpdatedAt time.Time `sql:"DEFAULT:'current_timestamp'"` ResourceQuotas []*TenantResourceQuota Users []*User `gorm:"many2many:tenant_user_rels;"` Projects []*Project AllocatedResourcequota v1.ResourceList `gorm:"-"` }
Tenant 租户表
type TenantResourceQuota ¶
type TenantResourceQuota struct { ID uint Content datatypes.JSON TenantID uint `gorm:"uniqueIndex:uniq_tenant_cluster" binding:"required"` ClusterID uint `gorm:"uniqueIndex:uniq_tenant_cluster" binding:"required"` Tenant *Tenant `gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;"` Cluster *Cluster `gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;"` TenantResourceQuotaApply *TenantResourceQuotaApply `gorm:"constraint:OnUpdate:RESTRICT,OnDelete:SET NULL;"` TenantResourceQuotaApplyID *uint }
type TenantResourceQuotaApply ¶
type TenantResourceQuotaApply struct { ID uint Content datatypes.JSON Status string `gorm:"type:varchar(30);"` Username string `gorm:"type:varchar(255);"` UpdatedAt time.Time `sql:"DEFAULT:'current_timestamp'"` }
TenantResourceQuotaApply 集群资源申请
type TenantUserRels ¶
type TenantUserRels struct { ID uint `gorm:"primarykey"` Tenant *Tenant `json:",omitempty" gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;"` // 租户ID TenantID uint `gorm:"uniqueIndex:uniq_idx_tenant_user_rel"` User *User `json:",omitempty" gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;"` // 用户ID UserID uint `gorm:"uniqueIndex:uniq_idx_tenant_user_rel"` // 租户级角色(管理员admin, 普通用户ordinary) Role string `gorm:"type:varchar(30)" binding:"required"` }
TenantUserRels 租户-用户-关系表 租户id-用户id-类型 唯一索引
type User ¶
type User struct { ID uint `gorm:"primarykey"` // 用户名 Username string `gorm:"type:varchar(50);uniqueIndex" binding:"required"` // 邮箱 Email string `gorm:"type:varchar(50)" binding:"required"` // 电话 Phone string `gorm:"type:varchar(255)"` Password string `gorm:"type:varchar(255)" json:"-"` // 是否激活 IsActive *bool `sql:"DEFAULT:true"` // 加入时间 CreatedAt *time.Time `sql:"DEFAULT:'current_timestamp'"` // 最后登录时间 LastLoginAt *time.Time `sql:"DEFAULT:'current_timestamp'"` Source string `gorm:"type:varchar(50)"` SourceVendor string `gorm:"type:varchar(50)"` Tenants []*Tenant `gorm:"many2many:tenant_user_rels;"` SystemRole *SystemRole SystemRoleID uint // 角色,不同关联对象下表示的角色不同, 用来做join查询的时候处理角色字段的(请勿删除) Role string `sql:"-" json:",omitempty"` }
User 用户表
func (*User) GetSystemRoleID ¶
func (*User) GetUserKind ¶
func (*User) GetUsername ¶
func (*User) SetLastLogin ¶
func (*User) UnmarshalBinary ¶
type UserCreate ¶
type UserMessageStatus ¶
type UserMessageStatus struct { ID uint UserID uint User *User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` MessageID *uint Message *Message `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` IsRead bool AlertMessageID *uint AlertMessage *AlertMessage `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` }
func (*UserMessageStatus) ColumnSlice ¶
func (status *UserMessageStatus) ColumnSlice() []string
func (*UserMessageStatus) ValueSlice ¶
func (status *UserMessageStatus) ValueSlice() []string
type UserToken ¶ added in v1.22.0
type UserToken struct { ID uint `gorm:"primarykey" json:"id"` Token string `json:"token"` GrantType string `gorm:"type:varchar(50)" json:"grantType"` Scope string `gorm:"type:varchar(50)" json:"scope"` ExpireAt *time.Time `json:"expireAt"` UserID *uint `json:"userID"` User *User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"user,omitempty"` CreatedAt *time.Time `json:"createdAt"` Expired bool `gorm:"-" json:"expired"` }
type VirtualDomain ¶
type VirtualSpace ¶
type VirtualSpace struct { ID uint `gorm:"primarykey"` VirtualSpaceName string `gorm:"type:varchar(50);uniqueIndex"` CreatedAt time.Time `sql:"DEFAULT:'current_timestamp'"` UpdatedAt time.Time `sql:"DEFAULT:'current_timestamp'"` IsActive bool CreatedBy string Users []*User `gorm:"many2many:virtual_space_user_rels;"` Environments []*Environment }
type VirtualSpaceUserRels ¶
type VirtualSpaceUserRels struct { ID uint `gorm:"primarykey"` VirtualSpaceID uint `gorm:"uniqueIndex:uniq_idx_virtual_space_user_rel"` VirtualSpace *VirtualSpace `json:",omitempty" gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;"` UserID uint `gorm:"uniqueIndex:uniq_idx_virtual_space_user_rel;constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;"` User *User `json:",omitempty" gorm:"constraint:OnUpdate:RESTRICT,OnDelete:CASCADE;"` // 虚拟空间角色(管理员admin, 普通用户normal) Role string `gorm:"type:varchar(30)" binding:"required,eq=admin|eq=normal"` }
type Workload ¶
type Workload struct { ID uint `gorm:"primarykey"` CreatedAt time.Time `sql:"DEFAULT:'current_timestamp'"` ClusterName string Namespace string Type string Name string CPULimitStdvar float64 MemoryLimitStdvar float64 Containers []*Container `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"-"` *Notice `gorm:"-"` }
Workload workload资源使用清单
Source Files ¶
- base.go
- model_alert.go
- model_alert_channel.go
- model_alert_rule.go
- model_announcement.go
- model_application.go
- model_auditlogs.go
- model_auth.go
- model_chartrepo.go
- model_cluster.go
- model_environment.go
- model_environment_resource.go
- model_log.go
- model_message.go
- model_monitor_dashboard.go
- model_project.go
- model_promql_template.go
- model_registry.go
- model_systemrole.go
- model_tenant.go
- model_user.go
- model_virtual_domain.go
- model_virtual_space.go
- model_workload.go
- types.go
- useriface.go