k8s

package
v1.0.0-rc Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: AGPL-3.0 Imports: 72 Imported by: 0

Documentation

Overview

Package k8s implements managing the servicegroup by k8s cluster

Index

Constants

View Source
const (
	// DefaultServiceDNSSuffix k8s service dns fixed suffix
	DefaultServiceDNSSuffix = "svc.cluster.local"

	EnableServiceLinks = "ENABLE_SERVICE_LINKS"
)
View Source
const (

	// SUBSCRIBE_RATIO_SUFFIX the key suffix of the super ratio
	SUBSCRIBE_RATIO_SUFFIX = "_SUBSCRIBE_RATIO"

	// CPU_NUM_QUOTA cpu limit key
	CPU_NUM_QUOTA = "CPU_NUM_QUOTA"
	// CPU_CFS_PERIOD_US 100000  /sys/fs/cgroup/cpu/cpu.cfs_period_us default value
	CPU_CFS_PERIOD_US int = 100000
	// MIN_CPU_SIZE Minimum application cpu value
	MIN_CPU_SIZE = 0.1

	// ProjectNamespace Env
	LabelServiceGroupID                = "servicegroup-id"
	KeyServiceGroupID                  = "SERVICE_GROUP_ID"
	KeyOriginServiceName               = "ORIGIN_SERVICE_NAME"
	ProjectNamespaceServiceNameNameKey = "PROJECT_NAMESPACE_SERVICE_NAME"
	ProjectNamespace                   = "PROJECT_NAMESPACE"
)
View Source
const (
	Error   = '1'
	Ping    = '2'
	Pong    = '3'
	Input   = '4'
	Output  = '5'
	GetSize = '6'
	Size    = '7'
	SetSize = '8'
)
View Source
const (

	// aliyun registry
	AliyunRegistry = "aliyun-registry"
	CustomRegistry = "custom-registry"
)
View Source
const (
	ServiceType        = "SERVICE_TYPE"
	StatelessService   = "STATELESS_SERVICE"
	IsStatelessService = "true"
	ServiceAddon       = "ADDONS"
	ServicePerNode     = "per_node"
)

Variables

This section is empty.

Functions

func ConvertEventStatus

func ConvertEventStatus(reason string) string

ConvertEventStatus convert k8s status

func ConvertToHostAlias

func ConvertToHostAlias(hosts []string) []apiv1.HostAlias

func DefaultHealthCheck

func DefaultHealthCheck(service *apistructs.Service) *apiv1.Probe

DefaultHealthCheck The user has not configured any health check, and the first port is checked by layer 4 tcp by default

func FillHealthCheckProbe

func FillHealthCheckProbe(service *apistructs.Service) *apiv1.Probe

FillHealthCheckProbe Fill out k8s probe based on service

func GenTolerations

func GenTolerations() []apiv1.Toleration

func IsGroupStateful

func IsGroupStateful(sg *apistructs.ServiceGroup) bool

IsGroupStateful Determine whether it is a stateful service the caller have to make sure sg is not nil Generally speaking, those with "SERVICE_TYPE" set to "ADDONS" are stateful applications, However, some of the ADDONS types still want to be deployed in a stateless manner, adding STATELESS_SERVICE To distinguish whether the ADDONS type is stateful or stateless, the default is to execute according to state

func MakeNamespace

func MakeNamespace(sg *apistructs.ServiceGroup) string

MakeNamespace Generate a Namespace name Each runtime corresponds to a k8s namespace on k8s, format is ${runtimeNamespace}--${runtimeName}

func NewCheckProbe

func NewCheckProbe() *apiv1.Probe

NewCheckProbe Create k8s probe default object

func NewHealthCheck

func NewHealthCheck(hc *apistructs.NewHealthCheck) *apiv1.Probe

NewHealthCheck Configure the new version of Dice health check

func OldHealthCheck

func OldHealthCheck(hc *apistructs.HealthCheck) *apiv1.Probe

OldHealthCheck Compatible with Dice old version health detection

func ParseJobHostBindTemplate

func ParseJobHostBindTemplate(hostPath string, clusterInfo map[string]string) (string, error)

ParseJobHostBindTemplate Analyze the hostPath template and convert it to the cluster info value

func SetHealthCheck

func SetHealthCheck(container *apiv1.Container, service *apistructs.Service)

func ValidateRuntime

func ValidateRuntime(specObj interface{}, action string) (*apistructs.ServiceGroup, error)

ValidateRuntime check runtime validity

Types

type Event

type Event struct {
	Type   watch.EventType `json:"type"`
	Object apiv1.Event     `json:"object"`
}

type Kubernetes

type Kubernetes struct {
	ClusterInfo *clusterinfo.ClusterInfo
	// contains filtered or unexported fields
}

Kubernetes is the Executor struct for k8s cluster

func New

func New(name executortypes.Name, clusterName string, options map[string]string) (*Kubernetes, error)

New new kubernetes executor struct

func (*Kubernetes) AddContainersEnv

func (k *Kubernetes) AddContainersEnv(containers []apiv1.Container, service *apistructs.Service, sg *apistructs.ServiceGroup) error

AddContainersEnv Add container environment variables

func (*Kubernetes) AddPodMountVolume

func (k *Kubernetes) AddPodMountVolume(service *apistructs.Service, podSpec *apiv1.PodSpec,
	secretvolmounts []apiv1.VolumeMount, secretvolumes []apiv1.Volume) error

AddPodMountVolume Add pod volume configuration

func (*Kubernetes) AddSpotEmptyDir

func (k *Kubernetes) AddSpotEmptyDir(podSpec *apiv1.PodSpec)

func (*Kubernetes) Addr

func (k *Kubernetes) Addr() string

Addr return kubernetes addr

func (*Kubernetes) CPUOvercommit

func (k *Kubernetes) CPUOvercommit(limit float64) float64

func (*Kubernetes) Cancel

func (k *Kubernetes) Cancel(ctx context.Context, specObj interface{}) (interface{}, error)

Cancel implements canceling manipulating servicegroup

func (*Kubernetes) CapacityInfo

func (k *Kubernetes) CapacityInfo() apistructs.CapacityInfoData

func (*Kubernetes) CleanUpBeforeDelete

func (k *Kubernetes) CleanUpBeforeDelete()

func (*Kubernetes) CopyErdaSecrets

func (k *Kubernetes) CopyErdaSecrets(originns, dstns string) ([]apiv1.Secret, error)

CopyErdaSecrets Copy the secret under orignns namespace to dstns

func (*Kubernetes) Create

func (k *Kubernetes) Create(ctx context.Context, specObj interface{}) (interface{}, error)

Create implements creating servicegroup based on k8s api

func (*Kubernetes) CreateNamespace

func (k *Kubernetes) CreateNamespace(ns string, sg *apistructs.ServiceGroup) error

CreateNamespace create namespace

func (*Kubernetes) CreateService

func (k *Kubernetes) CreateService(service *apistructs.Service) error

CreateService create k8s service

func (*Kubernetes) CreateStatefulGroup

func (k *Kubernetes) CreateStatefulGroup(sg *apistructs.ServiceGroup, layers [][]*apistructs.Service) error

CreateStatefulGroup create statefull group

func (*Kubernetes) DeleteNamespace

func (k *Kubernetes) DeleteNamespace(ns string) error

DeleteNamespace delete namepsace

func (*Kubernetes) DeletePV

func (k *Kubernetes) DeletePV(sg *apistructs.ServiceGroup) error

func (*Kubernetes) DeleteService

func (k *Kubernetes) DeleteService(namespace, name string) error

DeleteService delete k8s service

func (*Kubernetes) Destroy

func (k *Kubernetes) Destroy(ctx context.Context, specObj interface{}) error

Destroy implements deleting servicegroup based on k8s api

func (*Kubernetes) GetK8SAddr

func (k *Kubernetes) GetK8SAddr() string

func (*Kubernetes) GetService

func (k *Kubernetes) GetService(namespace, name string) (*apiv1.Service, error)

GetService get k8s service

func (*Kubernetes) GetStatefulStatus

func (k *Kubernetes) GetStatefulStatus(sg *apistructs.ServiceGroup) (apistructs.StatusDesc, error)

TODO: State need more precise

func (*Kubernetes) IPToHostname

func (m *Kubernetes) IPToHostname(ip string) string

func (*Kubernetes) Inspect

func (k *Kubernetes) Inspect(ctx context.Context, specObj interface{}) (interface{}, error)

Inspect implements getting servicegroup info

func (*Kubernetes) InspectStateful

func (k *Kubernetes) InspectStateful(sg *apistructs.ServiceGroup) (*apistructs.ServiceGroup, error)

func (*Kubernetes) InstanceEvent

func (k *Kubernetes) InstanceEvent(event Event, runtimeName string, notifier eventboxapi.Notifier)

func (*Kubernetes) JobVolumeCreate

func (*Kubernetes) JobVolumeCreate(ctx context.Context, spec interface{}) (string, error)

func (*Kubernetes) KillPod

func (k *Kubernetes) KillPod(podname string) error

func (*Kubernetes) Kind

func (k *Kubernetes) Kind() executortypes.Kind

Kind implements executortypes.Executor interface

func (*Kubernetes) MemoryOvercommit

func (k *Kubernetes) MemoryOvercommit(limit int) int

func (*Kubernetes) Name

func (k *Kubernetes) Name() executortypes.Name

Name implements executortypes.Executor interface

func (*Kubernetes) NewHealthcheckProbe

func (k *Kubernetes) NewHealthcheckProbe(service *apistructs.Service) *apiv1.Probe

func (*Kubernetes) NewImageSecret

func (k *Kubernetes) NewImageSecret(namespace string) error

NewImageSecret create new image pull secret 1, create imagePullSecret of this namespace 2, put this secret into serviceaccount of the namespace

func (*Kubernetes) NewRuntimeImageSecret

func (k *Kubernetes) NewRuntimeImageSecret(namespace string, sg *apistructs.ServiceGroup) error

NewImageSecret create mew image pull secret 1, create imagePullSecret of this namespace 2, Add the secret of the image that needs to be authenticated to the secret of the namespace 3, put this secret into serviceaccount of the namespace

func (*Kubernetes) NotfoundNamespace

func (k *Kubernetes) NotfoundNamespace(ns string) (bool, error)

NotfoundNamespace not found namespace

func (*Kubernetes) Precheck

func (k *Kubernetes) Precheck(ctx context.Context, specObj interface{}) (apistructs.ServiceGroupPrecheckData, error)

func (*Kubernetes) PutService

func (k *Kubernetes) PutService(svc *apiv1.Service) error

PutService update k8s service

func (*Kubernetes) Remove

func (k *Kubernetes) Remove(ctx context.Context, specObj interface{}) error

Remove implements removing servicegroup based on k8s api

func (*Kubernetes) ResourceInfo

func (k *Kubernetes) ResourceInfo(brief bool) (apistructs.ClusterResourceInfoData, error)

func (*Kubernetes) SecretVolume

func (k *Kubernetes) SecretVolume(secret *apiv1.Secret) (apiv1.Volume, apiv1.VolumeMount)

SecretVolume

func (*Kubernetes) SetFineGrainedCPU

func (k *Kubernetes) SetFineGrainedCPU(container *apiv1.Container, extra map[string]string, cpuSubscribeRatio float64) error

SetFineGrainedCPU Set proper cpu ratio & quota

func (*Kubernetes) SetNodeLabels

func (m *Kubernetes) SetNodeLabels(_ executortypes.NodeLabelSetting, hosts []string, labels map[string]string) error

SetNodeLabels set the labels of k8s node

func (*Kubernetes) SetOverCommitMem

func (k *Kubernetes) SetOverCommitMem(container *apiv1.Container, memSubscribeRatio float64) error

func (*Kubernetes) Status

func (k *Kubernetes) Status(ctx context.Context, specObj interface{}) (apistructs.StatusDesc, error)

Status implements getting servicegroup status based on k8s api

func (*Kubernetes) Terminal

func (k *Kubernetes) Terminal(namespace, podname, containername string, upperConn *websocket.Conn)

func (*Kubernetes) Update

func (k *Kubernetes) Update(ctx context.Context, specObj interface{}) (interface{}, error)

Update implements updating servicegroup based on k8s api Does not support updating cloud disk (pvc)

func (*Kubernetes) UpdateNamespace

func (k *Kubernetes) UpdateNamespace(ns string, sg *apistructs.ServiceGroup) error

UpdateNamespace

type OneGroupInfo

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

OneGroupInfo Returns information about the statefulset corresponding to the group

type StatefulsetInfo

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

type Winsize

type Winsize struct {
	Rows uint16 // ws_row: Number of rows (in cells)
	Cols uint16 // ws_col: Number of columns (in cells)
	X    uint16 // ws_xpixel: Width in pixels
	Y    uint16 // ws_ypixel: Height in pixels
}

Directories

Path Synopsis
Package configmap manipulates the k8s api of configmap object
Package configmap manipulates the k8s api of configmap object
Package deployment manipulates the k8s api of deployment object
Package deployment manipulates the k8s api of deployment object
Package event manipulates the k8s api of event object Package event manipulates the k8s api of event object Package event manipulates the k8s api of event object
Package event manipulates the k8s api of event object Package event manipulates the k8s api of event object Package event manipulates the k8s api of event object
Package ingress manipulates the k8s api of ingress object
Package ingress manipulates the k8s api of ingress object
Package k8sapi contains necessary k8s types and objects
Package k8sapi contains necessary k8s types and objects
Package k8serror encapsulates error of k8s object
Package k8serror encapsulates error of k8s object
Package k8sservice manipulates the k8s api of service object
Package k8sservice manipulates the k8s api of service object
Package namespace manipulates the k8s api of namespace object
Package namespace manipulates the k8s api of namespace object
Package persistentvolume manipulates the k8s api of persistentvolume object
Package persistentvolume manipulates the k8s api of persistentvolume object
Package persistentvolumeclaim manipulates the k8s api of persistentvolumeclaim object
Package persistentvolumeclaim manipulates the k8s api of persistentvolumeclaim object
Package pod manipulates the k8s api of pod object
Package pod manipulates the k8s api of pod object
Package role manipulates the k8s api of role object
Package role manipulates the k8s api of role object
Package rolebinding manipulates the k8s api of rolebinding object
Package rolebinding manipulates the k8s api of rolebinding object
Package secret manipulates the k8s api of secret object
Package secret manipulates the k8s api of secret object
Package serviceaccount manipulates the k8s api of serviceaccount object
Package serviceaccount manipulates the k8s api of serviceaccount object
Package statefulset manipulates the k8s api of statefulset object
Package statefulset manipulates the k8s api of statefulset object

Jump to

Keyboard shortcuts

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