kuberes

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AppKindDaemonSet     = "daemonset"
	AppKindDeployment    = "deployment"
	AppKindStatefulSet   = "statefulset"
	LABLE_APPNAME_KEY    = "app"
	LABLE_APPVERSION_KEY = "version"

	ServiceKind              = "service"
	ConfigMapKind            = "configmap"
	SecretKind               = "secret"
	DescriptionAnnotationKey = "description"
	OwnerNameAnnotationKey   = "owner_name"
	DEFAULT_PROJECT_ID       = 0
	YamlSeparator            = "---\n"
	IngApiVersion            = "extensions/v1beta1"
)
View Source
const (
	RESTART_LABLE       = "caas_restart"
	RESTART_LABLE_VALUE = "true"
)
View Source
const (
	INIT_APPNAME = ""

	DefaultVersion = "latest"

	APP_PROTOCOL_HTTP = "http"
)
View Source
const (
	PodStatusRunning  = "Running"
	PodStatusNotReady = "NotReady"
)
View Source
const TemplateMaxSize = 1024000 //1000KB

Variables

This section is empty.

Functions

func AppTemplateToYamlString

func AppTemplateToYamlString(tpl AppTemplate, cluster, namespace, podVersion string) (string, error)

func CreateK8sNamespace

func CreateK8sNamespace(cluster, namespace string) error

func CreateRegistrySecret

func CreateRegistrySecret(cluster, namespace string, envID int64) error

func DeployAppTemplates

func DeployAppTemplates(appTplList []AppTemplate, projectid, envID int64, cluster, namespace, tname string, eparam *ExtensionParam) error

func GenDefaultIngressObject

func GenDefaultIngressObject(svc *apiv1.Service, ingObjMeta metav1.ObjectMeta, defPort int32, domainName, domainSuffix string) *extensions.Ingress

func GenerateDeployName

func GenerateDeployName(appname string) string

func GetImageVersion

func GetImageVersion(image string) string

func GetResourceVersion

func GetResourceVersion(res interface{}, resType ResType, exparam string) string

func TriggerApplicationCreate

func TriggerApplicationCreate(clusterName, namespace, templateStr string, projectID, envID int64, force bool) error

TriggerApplicationCreate ..

Types

type AppDetail

type AppDetail struct {
	AppItem
	Services []*ServiceDetail `json:"services,omitempty"`
	Pods     []*AppPod        `json:"pods,omitempty"`
}

type AppEvent

type AppEvent struct {
	EventLevel   string `json:"event_level"`
	EventObject  string `json:"event_object"`
	EventType    string `json:"event_type"`
	EventMessage string `json:"event_message"`
	EventTime    string `json:"event_time"`
}

type AppItem

type AppItem struct {
	models.CaasApplication
	ReplicasConstrast string `json:"replicas_constrast,omitempty"`
	Status            string `json:"status,omitempty"`
	Pods              string `json:"pods,omitempty"`
	CreateAt          string `json:"create_at,omitempty"`
	UpdateAt          string `json:"update_at,omitempty"`
}

type AppParam

type AppParam struct {
	Name       string              `json:"name"` //appname
	Containers []ContainerParam    `json:"containers,omitempty"`
	Replicas   *intstr.IntOrString `json:"replicas,omitempty"`
}

type AppPod

type AppPod struct {
	Pod    `json:",inline"`
	Weight int `json:"weight"`
}

type AppPodBasicParam

type AppPodBasicParam struct {
	Namespace string `json:"namespace"`
	Name      string `json:"name"`
	PodName   string `json:"pod_name"`
}

type AppPodDetail

type AppPodDetail struct {
	models.CaasApplication `json:",inline"`
	Pod                    AppPod `json:"pod"`
}

type AppRes

type AppRes struct {
	Cluster   string
	EnvID     int64
	ProjectID int64
	Client    kubernetes.Interface
	Appmodel  *dao.AppModel
}

func NewAppRes

func NewAppRes(cluster string, envID, projectID int64) (*AppRes, error)

func (*AppRes) DeleteApp

func (ar *AppRes) DeleteApp(namespace, appname string) error

func (*AppRes) GetAppDetail

func (ar *AppRes) GetAppDetail(namespace, name string) (*AppDetail, error)

func (*AppRes) GetAppEvent

func (ar *AppRes) GetAppEvent(namespace, appName string) ([]AppEvent, error)

func (*AppRes) GetAppListByPagination

func (ar *AppRes) GetAppListByPagination(filterQuery *query.FilterQuery, projectID int64, cluster string) (*query.QueryResult, error)

GetAppListByPagination ..

func (*AppRes) GetAppPodLog

func (ar *AppRes) GetAppPodLog(namespace, appName, podName, containerName string) (string, error)

func (*AppRes) GetAppPodStatus

func (ar *AppRes) GetAppPodStatus(namespace, appName, podName string) (interface{}, error)

func (*AppRes) GetAppServiceDetail

func (ar *AppRes) GetAppServiceDetail(namespace, appDeploymentName, nodeIP string) ([]*ServiceDetail, error)

func (*AppRes) GetDeployRuntime

func (ar *AppRes) GetDeployRuntime(app models.CaasApplication, deploymentName string) (string, string, error)

func (*AppRes) InstallApp

func (ar *AppRes) InstallApp(
	namespace, tname string,
	template Template,
	eparam *ExtensionParam) error

func (*AppRes) ReconfigureApp

func (ar *AppRes) ReconfigureApp(app models.CaasApplication, template AppTemplate) (*AppDetail, error)

func (*AppRes) Restart

func (ar *AppRes) Restart(namespace, appname string) error

func (*AppRes) RollingUpdateApp

func (ar *AppRes) RollingUpdateApp(namespace, appname string, param []ContainerParam) error

func (*AppRes) ScaleApp

func (ar *AppRes) ScaleApp(namespace, appname string, replicas int) error

func (*AppRes) SetDeployStatus

func (ar *AppRes) SetDeployStatus(namespace, appname, status string) error

func (*AppRes) SetLabels

func (ar *AppRes) SetLabels(namespace, name string, labels map[string]string) error

func (*AppRes) UninstallApp

func (ar *AppRes) UninstallApp(app models.CaasApplication) error

type AppResourceItem

type AppResourceItem struct {
	Kind string `json:"kind,omitempty"`
	Name string `json:"name,omitempty"`
}

type AppStatus

type AppStatus struct {
	ReadyReplicas     int32
	UpdatedReplicas   int32
	AvailableReplicas int32
	AvailableStatus   string
	Message           string
}

type AppTemplate

type AppTemplate interface {
	GenerateAppObject(cluster, namespace, tplname string, projectID int64) (*models.CaasApplication, error)
	UpdateAppObject(app *models.CaasApplication) error
	GenerateKubeObject(cluster, namespace string) (map[string]interface{}, error)
	GetAppName() string
	GetAppKind() string
	String() (string, error)
	Image(param []ContainerParam) AppTemplate
	DefaultLabel() AppTemplate
	Replicas(replicas int) AppTemplate
}

single app template interface simpleapp and nativeapp template support this interface

func CreateAppTemplateByApp

func CreateAppTemplateByApp(app models.CaasApplication) (AppTemplate, error)

func CreateNativeAppTemplate

func CreateNativeAppTemplate(app models.CaasApplication) (AppTemplate, error)

context is file context of native template,

type ContainerItem

type ContainerItem struct {
	Name  string `json:"name,omitempty"`
	Image string `json:"image,omitempty"`
}

type ContainerParam

type ContainerParam struct {
	Name  string `json:"name"`
	Image string `json:"image"`
}

type DeployConfig

type DeployConfig struct {
	DefaultPort     int32  `json:"default_port"` //默认服务端口
	DeployStrategy  string `json:"deploy_strategy"`
	ImagePullSecret string `json:"image_pull_secret"`
	RegistryAddr    string `json:"registry_addr"`
	Description     string `json:"description"`
}

type DeployWorker

type DeployWorker struct {
	Name string
	// contains filtered or unexported fields
}

func NewDeployWorker

func NewDeployWorker(name, namespace, kind string, ar *AppRes, eparam *ExtensionParam, tpl AppTemplate) *DeployWorker

func (*DeployWorker) Start

func (wk *DeployWorker) Start(templateName string, param AppParam) error

type DeploymentRes

type DeploymentRes struct {
	Namespace string
	// contains filtered or unexported fields
}

func (*DeploymentRes) AppIsExisted

func (kr *DeploymentRes) AppIsExisted(appname string) (bool, error)

AppIsExisted ..

func (*DeploymentRes) Create

func (kr *DeploymentRes) Create(obj interface{}) error

func (*DeploymentRes) Delete

func (kr *DeploymentRes) Delete(appname string) error

func (*DeploymentRes) DeletePods

func (kr *DeploymentRes) DeletePods(options *metav1.ListOptions, appname string) error

DeletePods ..

func (*DeploymentRes) GetOwnerForPod

func (kr *DeploymentRes) GetOwnerForPod(pod apiv1.Pod, ref *metav1.OwnerReference) interface{}

func (*DeploymentRes) Restart

func (kr *DeploymentRes) Restart(appname string) error

func (*DeploymentRes) Scale

func (kr *DeploymentRes) Scale(appname string, replicas int) error

func (*DeploymentRes) Status

func (kr *DeploymentRes) Status(appname string) (*AppStatus, error)

Status ..

func (*DeploymentRes) Update

func (kr *DeploymentRes) Update(app models.CaasApplication, obj interface{}) (int, error)

type EventItem

type EventItem struct {
	EventUid        string    `orm:"column(event_uid);size(36)" json:"event_uid"`
	ActionType      string    `orm:"column(action_type);size(10)" json:"action_type"`
	EventType       string    `orm:"column(event_type);size(10)" json:"event_type"`
	Cluster         string    `orm:"column(cluster);size(20)" json:"cluster"`
	Namespace       string    `orm:"column(namespace);size(100)" json:"namespace"`
	SourceComponent string    `orm:"column(source_component);size(50)" json:"source_component"`
	SourceHost      string    `orm:"column(source_host);size(60)" json:"source_host"`
	ObjectKind      string    `orm:"column(object_kind);size(64)" json:"object_kind"`
	ObjectName      string    `orm:"column(object_name);size(100)" json:"object_name"`
	ObjectUid       string    `orm:"column(object_uid);size(36)" json:"object_uid"`
	FieldPath       string    `orm:"column(field_path);size(200)" json:"field_path"`
	Reason          string    `orm:"column(reason);size(100)" json:"reason"`
	Message         string    `orm:"column(message);type(text)" json:"message"`
	FirstTimestamp  time.Time `orm:"column(first_time)" json:"first_time"`
	LastTimestamp   time.Time `orm:"column(last_time);index" json:"last_time"`
}

func GetEventList

func GetEventList(client kubernetes.Interface, cluster, namespace, appName string) ([]*EventItem, error)

type ExtensionParam

type ExtensionParam struct {
	Force   bool //when user deploy its app and the app is existed in other namespace, the old app will be deleted
	Patcher PatcherFunction
}

type KubeAppInterface

type KubeAppInterface interface {
	Create(obj interface{}) error
	Update(app models.CaasApplication, obj interface{}) (int, error)
	Status(appname string) (*AppStatus, error)
	Delete(appname string) error
	DeletePods(selector *metav1.ListOptions, appname string) error
	AppIsExisted(appname string) (bool, error)
	Scale(appname string, replicas int) error
	Restart(appname string) error
	GetOwnerForPod(pod apiv1.Pod, ref *metav1.OwnerReference) interface{}
}

func NewDeploymentRes

func NewDeploymentRes(client kubernetes.Interface, namespace string) KubeAppInterface

func NewStatefulRes

func NewStatefulRes(client kubernetes.Interface, namespace string) KubeAppInterface

type KubeAppRes

type KubeAppRes struct {
	DomainSuffix string
	Namespace    string
	// contains filtered or unexported fields
}

func NewKubeAppRes

func NewKubeAppRes(client kubernetes.Interface, cluster, namespace, kind string) *KubeAppRes

func (*KubeAppRes) CheckAppIsExisted

func (kr *KubeAppRes) CheckAppIsExisted(appname string) (bool, error)

func (*KubeAppRes) CreateAppResource

func (kr *KubeAppRes) CreateAppResource(template AppTemplate) error

func (*KubeAppRes) CreateService

func (kr *KubeAppRes) CreateService(svcList []*apiv1.Service) error

func (*KubeAppRes) DeleteAppResource

func (kr *KubeAppRes) DeleteAppResource(template AppTemplate) error

func (*KubeAppRes) DeleteApplication

func (kr *KubeAppRes) DeleteApplication(appname string) error

func (*KubeAppRes) Restart

func (kr *KubeAppRes) Restart(appname string) error

func (*KubeAppRes) Scale

func (kr *KubeAppRes) Scale(appname string, replicas int) error

func (*KubeAppRes) SetAppStatus

func (kr *KubeAppRes) SetAppStatus(app *models.CaasApplication)

func (*KubeAppRes) UpdateAppResource

func (kr *KubeAppRes) UpdateAppResource(app *models.CaasApplication, new, old AppTemplate, all bool) error

type KubeAppValidator

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

func NewKubeAppValidator

func NewKubeAppValidator(client kubernetes.Interface, namespace string) *KubeAppValidator

func (*KubeAppValidator) Validator

func (validator *KubeAppValidator) Validator(obj interface{}) error

type KubeSvcValidator

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

func NewKubeSvcValidator

func NewKubeSvcValidator(cluster, namespace, appname string) *KubeSvcValidator

func (*KubeSvcValidator) Validator

func (validator *KubeSvcValidator) Validator(obj interface{}) error

type NamespaceListFunction

type NamespaceListFunction func() []string

type NativeAppTemplate

type NativeAppTemplate struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Deployment        *appsv1.Deployment    `json:"deployment,omitempty"`
	Services          []*apiv1.Service      `json:"services,omitempty"`
	Ingresses         []*extensions.Ingress `json:"ingresses,omitempty"`
	Config            DeployConfig          `json:"config"`
}

native app template and api

func (*NativeAppTemplate) DefaultLabel

func (tp *NativeAppTemplate) DefaultLabel() AppTemplate

func (*NativeAppTemplate) GenerateAppObject

func (tp *NativeAppTemplate) GenerateAppObject(cluster, namespace, tplname string, projectID int64) (*models.CaasApplication, error)

TODO: refactor

func (*NativeAppTemplate) GenerateKubeObject

func (tp *NativeAppTemplate) GenerateKubeObject(cluster, namespace string) (map[string]interface{}, error)

func (*NativeAppTemplate) GetAppKind

func (tp *NativeAppTemplate) GetAppKind() string

func (*NativeAppTemplate) GetAppName

func (tp *NativeAppTemplate) GetAppName() string

func (*NativeAppTemplate) Image

func (tp *NativeAppTemplate) Image(param []ContainerParam) AppTemplate

func (*NativeAppTemplate) Replicas

func (tp *NativeAppTemplate) Replicas(replicas int) AppTemplate

func (*NativeAppTemplate) String

func (tp *NativeAppTemplate) String() (string, error)

func (*NativeAppTemplate) UpdateAppObject

func (tp *NativeAppTemplate) UpdateAppObject(app *models.CaasApplication) error

type NativeTemplate

type NativeTemplate struct {
	Template string       `json:"template"`
	Config   DeployConfig `json:"config"`
}

native template and api

func NewNativeTemplate

func NewNativeTemplate() *NativeTemplate

func (*NativeTemplate) CreateNoAppResource

func (t *NativeTemplate) CreateNoAppResource(client kubernetes.Interface, cluster, namespace string, objs []ResObject)

func (*NativeTemplate) Default

func (t *NativeTemplate) Default(envID int64) Template

set default value for template config

func (*NativeTemplate) Deploy

func (t *NativeTemplate) Deploy(projectID, envID int64, cluster, namespace, tname string, eparam *ExtensionParam) error

func (*NativeTemplate) GenNativeAppTemplate

func (t *NativeTemplate) GenNativeAppTemplate(namespace, appname string) ([]*NativeAppTemplate, []ResObject, error)

func (*NativeTemplate) GetAppResourceNames

func (t *NativeTemplate) GetAppResourceNames() ([]AppResourceItem, error)

GetAppResourceNames .. TODO: current support deployment/statefulset daemonset parse

func (*NativeTemplate) GetContainerImages

func (t *NativeTemplate) GetContainerImages() ([]*ContainerItem, error)

func (*NativeTemplate) GetExample

func (t *NativeTemplate) GetExample() []byte

func (*NativeTemplate) Validate

func (t *NativeTemplate) Validate() error

type ObjectValidator

type ObjectValidator interface {
	Validator(obj interface{}) error
}

type PatcherFunction

type PatcherFunction func(app models.CaasApplication)

type Pod

type Pod struct {
	Name         string            `json:"name"`
	Namespace    string            `json:"namespace"`
	Version      string            `json:"version"`
	NodeIP       string            `json:"node_ip"`
	PodIP        string            `json:"pod_ip"`
	Status       string            `json:"status"`
	Message      string            `json:"message"`
	RestartCount int32             `json:"restart_count"`
	StartTime    string            `json:"start_time"`
	Labels       map[string]string `json:"labels"`
	Containers   []*PodContainer   `json:"containers"`
}

func GetPods

func GetPods(client kubernetes.Interface, cluster, namespace, appName string, replicas int) ([]*Pod, error)

type PodContainer

type PodContainer struct {
	Name           string `json:"name"`
	Image          string `json:"image"`
	CpuRequests    int64  `json:"cpu_requests"`
	CpuLimits      int64  `json:"cpu_limits"`
	MemoryRequests int64  `json:"memory_requests"`
	MemoryLimits   int64  `json:"memory_limits"`
}

type ResObject

type ResObject struct {
	Namespace string
	Name      string

	Object  runtime.Object
	RawData []byte
}

type ResType

type ResType string
const (
	ResTypeApp      ResType = "app"
	ResTypePod      ResType = "pod"
	ResTypeDeploy   ResType = "deploy"
	ResTypeTemplate ResType = "template"
	ResTypeImage    ResType = "image"
)

type RollBackFunc

type RollBackFunc func() error

type RollingUpdateApp

type RollingUpdateApp struct {
	Name  string `json:"name"`
	Image string `json:"image"`
}

type ServiceDetail

type ServiceDetail struct {
	Name           string           `json:"name"`
	Type           string           `json:"type"`
	ClusterIP      string           `json:"cluster_ip"`
	AddressList    []serviceAddress `json:"address_list"`
	PodsvcAddrList []podSvcAddress  `json:"podsvc_addr_list"`
}

func GetAppServices

func GetAppServices(client kubernetes.Interface, cluster, namespace, appDeploymentName, nodeIP string) ([]*ServiceDetail, error)

type StatefulRes

type StatefulRes struct {
	Namespace string
	// contains filtered or unexported fields
}

func (*StatefulRes) AppIsExisted

func (kr *StatefulRes) AppIsExisted(appname string) (bool, error)

AppIsExisted ..

func (*StatefulRes) Create

func (kr *StatefulRes) Create(obj interface{}) error

func (*StatefulRes) Delete

func (kr *StatefulRes) Delete(appname string) error

func (*StatefulRes) DeletePods

func (kr *StatefulRes) DeletePods(options *metav1.ListOptions, appname string) error

func (*StatefulRes) GetOwnerForPod

func (kr *StatefulRes) GetOwnerForPod(pod apiv1.Pod, ref *metav1.OwnerReference) interface{}

func (*StatefulRes) Restart

func (kr *StatefulRes) Restart(appname string) error

func (*StatefulRes) Scale

func (kr *StatefulRes) Scale(appname string, replicas int) error

func (*StatefulRes) Status

func (kr *StatefulRes) Status(appname string) (*AppStatus, error)

func (*StatefulRes) Update

func (kr *StatefulRes) Update(app models.CaasApplication, obj interface{}) (int, error)

type Template

type Template interface {
	Default(envID int64) Template
	Validate() error
	GetExample() []byte
	Deploy(projectid, envID int64, cluster, namespace, tname string, eparam *ExtensionParam) error
}

template interface, nativetemplate support this interface

func NewTemplate

func NewTemplate() Template

type TemplateInfo

type TemplateInfo struct {
	models.CaasTemplate
	CreateAt string `json:"create_at"`
	UpdateAt string `json:"update_at"`
	DeleteAt string `json:"delete_at"`
}

type TemplateRes

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

func NewTemplateRes

func NewTemplateRes(get NamespaceListFunction) *TemplateRes

func (*TemplateRes) CreateTemplate

func (tr *TemplateRes) CreateTemplate(template models.CaasTemplate) (*models.CaasTemplate, error)

func (*TemplateRes) DeleteTemplate

func (tr *TemplateRes) DeleteTemplate(namespace, name string) error

func (*TemplateRes) GetTemplateByID

func (tr *TemplateRes) GetTemplateByID(id int64) (*models.CaasTemplate, int, error)

func (*TemplateRes) GetTemplateByName

func (tr *TemplateRes) GetTemplateByName(namespace, name string) (*models.CaasTemplate, int, error)

func (*TemplateRes) UpdateTemplate

func (tr *TemplateRes) UpdateTemplate(template models.CaasTemplate) (*models.CaasTemplate, error)

type VersionWeight

type VersionWeight struct {
	Stage   string             `json:"stage"`
	Version string             `json:"version"`
	Weight  intstr.IntOrString `json:"weight"`
}

type WorkerResult

type WorkerResult struct {
	AppName string
	AppKind string
	Result  error
}

Jump to

Keyboard shortcuts

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