k8s

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: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APP_NAME   = "k8s"
	SECRET_KEY = "23gs6gxHrz1kNEvshRmunkXbwIiaEcYfh+EMu+e9ewA="
)
View Source
const (
	ASSET_LABEL_KEY = "k8s_id"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cluster

type Cluster struct {
	Id string `json:"id" bson:"_id" gorm:"column:id"`
	// 录入时间
	CreateAt time.Time `json:"create_at" bson:"create_at" gorm:"column:create_at"`
	// 更新时间
	UpdateAt time.Time `json:"update_at" bson:"update_at" gorm:"column:update_at"`
	// 更新人
	UpdateBy string `json:"update_by" bson:"update_by" gorm:"column:update_by"`
	// 集群相关信息
	ServerInfo ServerInfo `json:"server_info" bson:",inline" gorm:"embedded"`

	// 集群定义信息
	CreateClusterRequest `bson:",inline" gorm:"embedded"`

	// 集群状态
	Status Status `json:"status" bson:",inline" gorm:"embedded"`
	// contains filtered or unexported fields
}

func NewCluster

func NewCluster(req *CreateClusterRequest) (*Cluster, error)

func (*Cluster) DecryptedKubeConf

func (r *Cluster) DecryptedKubeConf() error

func (*Cluster) EncryptedKubeConf

func (r *Cluster) EncryptedKubeConf() error

func (*Cluster) GetK8sClient

func (c *Cluster) GetK8sClient() (*k8s.Client, error)

func (*Cluster) IsAlive

func (i *Cluster) IsAlive() error

func (*Cluster) SetIsEncrypted

func (r *Cluster) SetIsEncrypted(v bool)

func (*Cluster) String

func (r *Cluster) String() string

func (*Cluster) TableName

func (r *Cluster) TableName() string

type CreateClusterRequest

type CreateClusterRequest struct {
	// 是否启用
	Enabled *bool `json:"enabled" form:"enabled" bson:"enabled" gorm:"column:enabled"`
	// 集群同步相关配置
	SyncConfig
	// 集群所属域
	Domain string `json:"domain" form:"domain" bson:"domain" gorm:"column:domain"`
	// 集群所属空间
	Namespace string `json:"namespace" form:"namespace" bson:"namespace" gorm:"column:namespace"`
	// 创建人
	CreateBy string `json:"create_by" form:"create_by" bson:"create_by" gorm:"column:create_by"`
	// 集群提供商
	Provider string `json:"provider" bson:"provider" form:"provider" validate:"required" gorm:"column:provider"`
	// 集群所处地域
	Region string `json:"region" bson:"region" form:"region" validate:"required" gorm:"column:region"`
	// 名称
	Name string `json:"name" bson:"name" form:"name" validate:"required" gorm:"column:name"`
	// 集群客户端访问凭证
	KubeConfig string `json:"kube_config" bson:"kube_config" form:"kube_config" validate:"required" mask:",10,10" gorm:"column:kube_config"`
	// 集群描述
	Description string `json:"description" form:"description" bson:"description" gorm:"column:description"`
	// 集群标签, 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;"`
}

func NewCreateClusterRequest

func NewCreateClusterRequest() *CreateClusterRequest

func (*CreateClusterRequest) GetAppClusterSync

func (r *CreateClusterRequest) GetAppClusterSync() bool

func (*CreateClusterRequest) GetEnabled

func (r *CreateClusterRequest) GetEnabled() bool

func (*CreateClusterRequest) SetAppClusterSync

func (r *CreateClusterRequest) SetAppClusterSync(v bool) *CreateClusterRequest

func (*CreateClusterRequest) SetEnabled

func (CreateClusterRequest) Validate

func (req CreateClusterRequest) Validate() error

type DeleteClusterRequest

type DeleteClusterRequest struct {
	DescribeClusterRequest
}

type DescribeClusterRequest

type DescribeClusterRequest struct {
	// Cluster id
	Id string `json:"id"`
}

func NewDescribeClusterRequest

func NewDescribeClusterRequest(k8sClusterId string) *DescribeClusterRequest

type QueryClusterRequest

type QueryClusterRequest struct {
	// 分页参数
	request.PageRequest
	// 标签过滤
	Label map[string]string `json:"label"`
	// 关键字参数
	Keywords string `json:"keywords"`
	// 供应商
	Provider string `json:"provider"`
	// 集群所属地域
	Region string `json:"region"`
	// 是否启用
	Enabled *bool `json:"enabled"`
	// 是否同步部署
	AppClusterSync *bool `json:"app_cluster_sync"`
	// 集群Id列表
	ClusterIds []string `json:"cluster_ids"`
}

func NewQueryClusterRequest

func NewQueryClusterRequest() *QueryClusterRequest

type ServerInfo

type ServerInfo struct {
	// k8s的地址
	Server string `json:"server" bson:"server" gorm:"column:server"`
	// k8s版本
	Version string `json:"version" bson:"version" gorm:"column:version"`
	// 连接用户
	AuthUser string `json:"auth_user" bson:"auth_user" gorm:"column:auth_user"`
}

type Service

type Service interface {
	// 查询K8s集群列表
	QueryCluster(context.Context, *QueryClusterRequest) (*types.Set[*Cluster], error)
	// 查询K8s集群详情
	DescribeCluster(context.Context, *DescribeClusterRequest) (*Cluster, error)
	// 添加K8s集群
	CreateCluster(context.Context, *CreateClusterRequest) (*Cluster, error)
	// 更新K8s集群
	UpdateCluster(context.Context, *UpdateClusterRequest) (*Cluster, error)
	// 删除K8s集群
	DeleteCluster(context.Context, *DeleteClusterRequest) (*Cluster, error)

	// 更新Kubeconfig
	UpdateKubeConfig(context.Context, *UpdateKubeConfigRequest) (*Cluster, error)
}

func GetService

func GetService() Service

type Status

type Status struct {
	// 检查时间
	CheckAt time.Time `json:"check_at" bson:"check_at"  gorm:"column:check_at"`
	// API Server是否正常
	IsAlive bool `json:"is_alive" bson:"is_alive"  gorm:"column:is_alive"`
	// 异常消息
	Message string `json:"message" bson:"message"  gorm:"column:message"`
}

type SyncConfig

type SyncConfig struct {
	// 应用集群同步
	AppClusterSync *bool `json:"app_cluster_sync" form:"app_cluster_sync" bson:"app_cluster_sync" gorm:"column:app_cluster_sync"`
	// 需要同步的空间
	SyncedNamespace []string `json:"synced_namespace" form:"synced_namespace" bson:"synced_namespace" gorm:"column:synced_namespace;serializer:json"`
	// 需要同步的资源
	SyncedResource []k8s.RESOURCE `json:"synced_resource" form:"synced_resource" bson:"synced_resource" gorm:"column:synced_resource;serializer:json"`
}

type UpdateClusterRequest

type UpdateClusterRequest struct {
	DescribeClusterRequest
	// 更新人
	UpdateBy string `json:"update_by"`
	// 更新时间
	UpdateAt int64 `json:"update_at"`
	// 更新的书本信息
	Spec *CreateClusterRequest `json:"spec"`
}

type UpdateKubeConfigRequest

type UpdateKubeConfigRequest struct {
	DescribeClusterRequest

	// 更新人
	UpdateBy string `json:"update_by"`
	UpdateKubeConfigSpec
}

type UpdateKubeConfigSpec

type UpdateKubeConfigSpec struct {
	// 集群客户端访问凭证
	KubeConfig string `json:"kube_config"  validate:"required"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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