cluster

package
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 16 Imported by: 0

README

应用集群

常见的应用部署场景: 等价于k8s当中的工作负载

  • 1个应用 部署为1个应用集群, 单部署,最常见
  • 1个应用 部署为多个应用集群, 比如 多组件应用, Server/Agent

Documentation

Index

Constants

View Source
const (
	APP_NAME = "cluster"
)
View Source
const (
	RESOURCE_PREFIX = "dep"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ActiveDeployConfigRequest

type ActiveDeployConfigRequest struct {
	DescribeClusterRequest
}

func NewActiveDeployConfigRequest

func NewActiveDeployConfigRequest(clusterId string) *ActiveDeployConfigRequest

type AutoDelete

type AutoDelete struct {
	// 是否启用
	Enabled *bool `json:"enabled" bson:"enabled" gorm:"column:enabled"`
	// 创建后 多久删除, 单位小时
	RetentionDuration int `json:"retention_duration" bson:"retention_duration" gorm:"column:retention_duration"`
}

type AutoDeploy

type AutoDeploy struct {
	// 是否启用
	Enabled *bool `json:"enabled" bson:"enabled" gorm:"column:enabled"`
	// 自动部署的分支
	Branch string `json:"branch" bson:"branch" gorm:"column:branch;type:varchar(200)"`
	// 自动部署的间隔,单位小时
	Interval int `json:"interval" bson:"interval" gorm:"column:interval"`
}

type Cluster

type Cluster struct {
	// 集群Id
	Id string `json:"id" bson:"_id" gorm:"column:id;primaryKey"`
	// 更新时间
	UpdateAt *time.Time `json:"update_at" bson:"update_at" gorm:"column:update_at"`
	// 删除时间
	DeleteAt *time.Time `json:"delete_at" bson:"delete_at" gorm:"column:delete_at"`
	// 删除人
	DeleteBy string `json:"delete_by" bson:"delete_by" gorm:"column:delete_by"`
	// 集群属性
	ClusterSpec
}

func NewCluster

func NewCluster(spec ClusterSpec) (*Cluster, error)

func (*Cluster) String

func (c *Cluster) String() string

func (*Cluster) TableName

func (c *Cluster) TableName() string

type ClusterCreateSpec

type ClusterCreateSpec struct {
	// 创建时间
	CreateAt time.Time `json:"create_at" bson:"create_at" gorm:"column:create_at"`
	// 应用Id
	AppServiceId string `json:"app_service_id" bson:"app_service_id" gorm:"column:app_service_id;varchar(64);"`
	// 集群类型, 承载应用运行的资源是什么, 例如: k8s, vm, baremetal, lambda, ...
	Type TYPE `json:"type" bson:"type" gorm:"column:type;type:varchar(60)"`
	// 用途
	Purpose PURPOSE `json:"purpose" bson:"purpose" gorm:"column:purpose;type:varchar(60)"`
	// 允许更新的属性
	ClusterUpdateSpec
	// 集群部署状态
	DeployStatus
}

type ClusterServiceClient

type ClusterServiceClient struct {
	// contains filtered or unexported fields
}

要封装原始的 不友好的rpc call

func NewClusterServiceClient

func NewClusterServiceClient() *ClusterServiceClient

func (*ClusterServiceClient) RPCUpdateDeployStatus

func (c *ClusterServiceClient) RPCUpdateDeployStatus(ctx context.Context, in *UpdateDeployStatusRequest) (*Cluster, error)

type ClusterSpec

type ClusterSpec struct {
	// 集群所属域
	Domain string `json:"domain" form:"domain" bson:"domain" gorm:"column:domain;type:varchar(120)"`
	// 集群所属空间
	Namespace string `json:"namespace" form:"namespace" bson:"namespace" gorm:"column:namespace;type:varchar(120)"`
	// 创建人
	Creator string `json:"creator" bson:"creator" gorm:"column:creator;type:varchar(60)"`
	// 创建信息
	ClusterCreateSpec
}

类似于Docker Compose,或者Stack,应用集群可以关联应用的各种部署资源

func NewClusterSpec

func NewClusterSpec() *ClusterSpec

func (*ClusterSpec) SetAutoDeleteEnabled

func (r *ClusterSpec) SetAutoDeleteEnabled(v bool) *ClusterSpec

func (*ClusterSpec) SetAutoDeployEnabled

func (r *ClusterSpec) SetAutoDeployEnabled(v bool) *ClusterSpec

func (*ClusterSpec) Validate

func (r *ClusterSpec) Validate() error

type ClusterUpdateSpec

type ClusterUpdateSpec struct {
	// 名称
	Name string `json:"name" bson:"name" validate:"required" gorm:"column:name;type:varchar(120)"`
	// 集群描述
	Description string `json:"description" bson:"description" gorm:"column:description"`

	// K8s部署信息
	K8sDeployConfig K8sDeployConfig `json:"k8s_deploy_config" bson:"k8s_deploy_config" gorm:"embedded"`
	// 虚拟机部署配置
	VmDeployConfig VmDeployConfig `json:"vm_deploy_config" bson:"vm_deploy_config" gorm:"embedded"`
	// 自动部署配置
	AutoDeploy AutoDeploy `json:"auto_deploy" bson:"auto_deploy" gorm:"embedded"`
	// 自动清理配置
	AutoDelete AutoDelete `json:"auto_delete" bson:"auto_delete" gorm:"embedded"`

	// 集群标签, env=prod
	Lables map[string]string `json:"lables" form:"lables" bson:"lables" gorm:"column:lables;serializer:json;"`
	// 额外的其他属性
	Extras map[string]string `json:"extras" form:"extras" bson:"extras" gorm:"column:extras;serializer:json;"`
}

type DEPLOY_STATUS

type DEPLOY_STATUS string
const (
	// 未部署
	DEPLOY_STATUS_UNDEPLOYED DEPLOY_STATUS = "UNDEPLOYED"
	// 正在滚动更新(新 ReplicaSet 正在创建 Pod)
	DEPLOY_STATUS_PROGRESSING DEPLOY_STATUS = "PROGRESSING"
	// 所有 Pod 已就绪,且最小可用副本数(minReadySeconds)已满足
	DEPLOY_STATUS_AVAILABLE DEPLOY_STATUS = "AVAILABLE"
	// 部分 Pod 不可用(副本未达到预期,或 Pod 崩溃)
	DEPLOY_STATUS_DEGRADED DEPLOY_STATUS = "DEGRADED"
	// 更新失败(如镜像拉取错误、资源不足等)
	DEPLOY_STATUS_FAILED DEPLOY_STATUS = "FAILED"
	// 人为主动停止服务,无 Pod 运行
	DEPLOY_STATUS_STOPPED DEPLOY_STATUS = "STOPPED"
	// 滚动更新完成(所有 Pod 已更新至最新版本)
	DEPLOY_STATUS_COMPLETE DEPLOY_STATUS = "COMPLETE"
	// 无滚动更新,且所有 Pod 正常运行
	DEPLOY_STATUS_STABLE DEPLOY_STATUS = "STABLE"
)

func ComputeK8sDeploymentStatus

func ComputeK8sDeploymentStatus(deploy *appsv1.Deployment) (DEPLOY_STATUS, string)

type DESCRIBE_BY

type DESCRIBE_BY string
const (
	DESCRIBE_BY_ID DESCRIBE_BY = "id"
)

type DeleteClusterRequest

type DeleteClusterRequest struct {
	// 应用集群Id
	Id string `json:"id"`
}

type DeployConfigStatus

type DeployConfigStatus struct {
	// 是否已经生效, 如果未生效需要等到下次部署生效
	IsActive bool `json:"is_active" bson:"is_active" gorm:"column:is_active"`
	// 最近一次生效时间
	LastActive *time.Time `json:"last_active" bson:"last_active" gorm:"column:last_active"`
}

func (*DeployConfigStatus) SetLastActive

func (d *DeployConfigStatus) SetLastActive(t time.Time) *DeployConfigStatus

func (DeployConfigStatus) TableName

func (d DeployConfigStatus) TableName() string

type DeployStatus

type DeployStatus struct {
	// 同步时间
	SyncAt *time.Time `json:"sync_at" bson:"deploy_sync_at" gorm:"column:deploy_sync_at"`
	// 状态更新时间
	UpdateAt *time.Time `json:"update_at" bson:"deploy_update_at" gorm:"column:deploy_update_at"`
	// 部署状态详情, k8s deployment yaml
	Detail string `json:"detail" bson:"deploy_detail" gorm:"column:deploy_detail"`

	// 副本数量
	Replicas int32 `json:"replicas" bson:"deploy_replicas" gorm:"column:deploy_replicas"`
	// 部署状态
	Status DEPLOY_STATUS `json:"status" bson:"deploy_status" gorm:"column:deploy_status;type:varchar(60)"`
	// 状态解释
	Message string `json:"message" bson:"message" gorm:"column:message"`
}

同步回来的Deployment信息

func (*DeployStatus) SetMessage

func (d *DeployStatus) SetMessage(m string) *DeployStatus

func (*DeployStatus) SetReplicas

func (d *DeployStatus) SetReplicas(r int32) *DeployStatus

func (*DeployStatus) SetStatus

func (d *DeployStatus) SetStatus(s DEPLOY_STATUS) *DeployStatus

func (*DeployStatus) SetSyncAt

func (d *DeployStatus) SetSyncAt(t time.Time) *DeployStatus

func (*DeployStatus) SetUpdateAt

func (d *DeployStatus) SetUpdateAt(t time.Time) *DeployStatus

func (*DeployStatus) TableName

func (d *DeployStatus) TableName() string

type DescribeClusterRequest

type DescribeClusterRequest struct {
	// 应用集群Id
	Id string `json:"id"`
	// 是否关联查询集群实例信息
	WithInstance bool `json:"with_instance"`
	// 是否关联查询集群服务信息
	WithService bool `json:"with_service"`
}

func NewDescribeClusterRequest

func NewDescribeClusterRequest(clusterId string) *DescribeClusterRequest

type K8sDeployConfig

type K8sDeployConfig struct {
	// K8s集群Id
	K8sId string `json:"k8s_id" form:"k8s_id" bson:"k8s_id" gorm:"column:k8s_id;type:varchar(120)"`
	// 空间
	Namespace string `json:"k8s_namespace" form:"k8s_namespace" bson:"k8s_namespace" gorm:"column:k8s_namespace;type:varchar(120)"`
	// 工作负载类型
	WorkloadKind workload.WORKLOAD_KIND `json:"k8s_workload_kind" form:"k8s_workload_kind" bson:"k8s_workload_kind" gorm:"column:k8s_workload_kind"`
	// 部署配置
	WorkloadYaml string `json:"k8s_workload_yaml" form:"k8s_workload_yaml" bson:"k8s_workload_yaml" gorm:"column:k8s_workload_yaml"`
	// 部署配置状态
	DeployConfigStatus
}

type PURPOSE

type PURPOSE string
const (
	// 功能开发
	PURPOSE_DEV_FEATURE PURPOSE = "dev-featrue"
	// 集成开发, 开发联合调
	PURPOSE_DEV_CI PURPOSE = "dev-ci"
	// 功能测试
	PURPOSE_TEST_FEATURE PURPOSE = "test-feature"
	// 性能测试
	PURPOSE_TEST_PERFORMANCE PURPOSE = "test-performance"
	// 提测
	PURPOSE_TEST_RELEASE PURPOSE = "test-release"
	// 预发验证(内部测试)
	PURPOSE_RELEASE_PRE PURPOSE = "release-pre"
	// 灰度验证(用户流量)
	PURPOSE_RELEASE_GRAY PURPOSE = "release-gray"
	// 线上: 蓝绿部署
	PURPOSE_ONLINE_BLUE_GREEN PURPOSE = "online-blue-green"
	// 线上: 滚动部署
	PURPOSE_ONLINE_ROLL_UPGRADE PURPOSE = "online-roll-upgrade"
)

type QueryClusterRequest

type QueryClusterRequest struct {
	policy.ResourceScope
	QueryClusterSpec
}

func NewQueryClusterRequest

func NewQueryClusterRequest() *QueryClusterRequest

type QueryClusterSpec

type QueryClusterSpec struct {
	// 分页参数
	request.PageRequest
	// 应用Id
	AppId string `json:"app_id"`
	// k8s集群Id
	K8sId string `json:"k8s_id"`
	// k8s namespace
	K8sNamespace string `json:"k8s_namespace"`
	// 集群名称
	Name string `json:"name"`
	// 集群标签
	Label map[string]string `json:"label"`
}

type RPC

type RPC interface {
	// 更新应用集群部署状态
	RPCUpdateDeployStatus(context.Context, *UpdateDeployStatusRequest) (*Cluster, error)
}

type Service

type Service interface {
	// 创建应用集群
	CreateCluster(context.Context, *ClusterSpec) (*Cluster, error)
	// 查询应用集群
	QueryCluster(context.Context, *QueryClusterRequest) (*types.Set[*Cluster], error)
	// 查询应用集群详情
	DescribeCluster(context.Context, *DescribeClusterRequest) (*Cluster, error)
	// 更新应用集群
	UpdateCluster(context.Context, *UpdateClusterRequest) (*Cluster, error)
	// 删除应用集群
	DeleteCluster(context.Context, *DeleteClusterRequest) (*Cluster, error)

	// 标记部署配置是否已经完成部署
	ActiveDeployConfig(context.Context, *ActiveDeployConfigRequest) (*Cluster, error)

	RPC
}

func GetService

func GetService() Service

type TYPE

type TYPE string
const (
	// 容器部署集群
	TYPE_K8S TYPE = "k8s"
	// 虚拟机部署集群
	TYPE_VM TYPE = "vm"
)

func (TYPE) String

func (t TYPE) String() string

type UpdateClusterRequest

type UpdateClusterRequest struct {
	DescribeClusterRequest
	ClusterUpdateSpec
}

type UpdateDeployConfigRequest

type UpdateDeployConfigRequest struct {
	DescribeClusterRequest
}

type UpdateDeployStatusRequest

type UpdateDeployStatusRequest struct {
	DescribeClusterRequest
	DeployStatus
}

func NewUpdateDeployStatusRequest

func NewUpdateDeployStatusRequest(clusterId string) *UpdateDeployStatusRequest

type VmDeployConfig

type VmDeployConfig struct {
}

虚拟机资源, 保存在 cmdb

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL