k8s

package
v1.3.0-rc.0...-12c9840 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 103 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"

	LabelKeyPrefix          = "annotations/"
	ECIPodSidecarConfigPath = "/etc/sidecarconf"

	// ECI Pod fluent-bit sidecar contianer configuration
	// Env Name
	ECIPodFluentbitSidecarImageEnvName      = "COLLECTOR_SIDECAR_IMAGE"
	ECIPodFluentbitSidecarConfigFileEnvName = "CONFIG_FILE"

	// Env Default Value
	ECIPodFluentbitSidecarImage              = "registry.erda.cloud/erda/erda-fluent-bit:2.1-alpha-20220329155354-3fcba88"
	ECIPodFluentbitSidecarConfigFileEnvValue = "/fluent-bit/etc/eci/fluent-bit.conf"
)
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

	// MIN_MEM_SIZE Minimum application mem value
	MIN_MEM_SIZE = 10

	// ProjectNamespace Env
	LabelServiceGroupID = "servicegroup-id"
)
View Source
const (
	Error   = '1'
	Ping    = '2'
	Pong    = '3'
	Input   = '4'
	Output  = '5'
	GetSize = '6'
	Size    = '7'
	SetSize = '8'
)
View Source
const (
	DefaultProdTerminationGracePeriodSeconds = 45
)
View Source
const LabelValueMaxLength int = 63

Variables

View Source
var (
	DefaultProdLifecyclePreStopHandler = &corev1.LifecycleHandler{
		Exec: &corev1.ExecAction{
			Command: []string{"sh", "-c", "sleep 10"},
		},
	}
)
View Source
var ECIPodSidecarENVFromScheduler = []string{
	"ECI_POD_FLUENTBIT_COLLECTOR_ADDR",
	"COLLECTOR_SIDECAR_IMAGE",
	"ECI_POD_FLUENTBIT_CONFIG_FILE",
}

Functions

func ConvertEventStatus

func ConvertEventStatus(reason string) string

ConvertEventStatus convert k8s status

func ConvertToHostAlias

func ConvertToHostAlias(hosts []string) []corev1.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 DereferenceEnvs

func DereferenceEnvs(podTempate *corev1.PodTemplateSpec) error

DereferenceEnvs dereferences envs if the placeholder ${env.PLACEHOLDER} in the env.

func FillHealthCheckProbe

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

FillHealthCheckProbe Fill out k8s probe based on service

func GenTolerations

func GenTolerations() []apiv1.Toleration

func GenerateECIPodSidecarContainers

func GenerateECIPodSidecarContainers(inEdge bool) (corev1.Container, error)

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 IsQuotaError

func IsQuotaError(err error) bool

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 NewQuotaError

func NewQuotaError(msg string) error

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 SetPodAnnotationsBaseContainerEnvs

func SetPodAnnotationsBaseContainerEnvs(container corev1.Container, podAnnotations map[string]string)

SetPodAnnotationsBaseContainerEnvs Add container environment variables

func SetPodContainerLifecycleAndSharedVolumes

func SetPodContainerLifecycleAndSharedVolumes(podSpec *corev1.PodSpec)

func UseECI

func UseECI(controllerLabels, PodLabels map[string]string) bool

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 []corev1.Container, service *apistructs.Service, sg *apistructs.ServiceGroup) error

AddContainersEnv Add container environment variables

func (*Kubernetes) AddLifeCycle

func (k *Kubernetes) AddLifeCycle(service *apistructs.Service, podSpec *corev1.PodSpec)

func (*Kubernetes) AddPodMountVolume

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

AddPodMountVolume Add pod volume configuration

func (*Kubernetes) AddSpotEmptyDir

func (k *Kubernetes) AddSpotEmptyDir(podSpec *corev1.PodSpec, emptySize int)

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) CheckQuota

func (k *Kubernetes) CheckQuota(ctx context.Context, projectID, workspace, runtimeID string, requestsCPU, requestsMem int64, kind, serviceName string) (bool, string, error)

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) CreateOrPutService

func (k *Kubernetes) CreateOrPutService(service *apistructs.Service, selectors map[string]string) error

CreateOrPutService if service doesn't exist, create, else update.

func (*Kubernetes) CreateService

func (k *Kubernetes) CreateService(service *apistructs.Service, selectors map[string]string) error

CreateService create k8s service

func (*Kubernetes) CreateStatefulGroup

func (k *Kubernetes) CreateStatefulGroup(ctx context.Context, 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) DeployInEdgeCluster

func (k *Kubernetes) DeployInEdgeCluster() bool

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)

GetStatefulStatus TODO: State need more precise

func (*Kubernetes) GetWorkspaceLeftQuota

func (k *Kubernetes) GetWorkspaceLeftQuota(ctx context.Context, projectID, workspace string) (cpu, mem int64, err error)

func (*Kubernetes) IPToHostname

func (k *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 events.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) ListService

func (k *Kubernetes) ListService(namespace string, selectors map[string]string) (apiv1.ServiceList, error)

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) Scale

func (k *Kubernetes) Scale(ctx context.Context, spec interface{}) (interface{}, error)

Scale implements update the replica and resources for one service

func (*Kubernetes) SecretVolume

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

SecretVolume

func (*Kubernetes) SetCpuQuota

func (k *Kubernetes) SetCpuQuota(quota float64)

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 (k *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, auditor executortypes.TerminalCommandAuditor)

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) UpdateContainerResourceEnv

func (k *Kubernetes) UpdateContainerResourceEnv(originResource apistructs.Resources, container *corev1.Container)

func (*Kubernetes) UpdateImageSecret

func (k *Kubernetes) UpdateImageSecret(namespace string, infos []apistructs.RegistryInfo) error

func (*Kubernetes) UpdateK8sService

func (k *Kubernetes) UpdateK8sService(k8sService *apiv1.Service, service *apistructs.Service, selectors map[string]string) error

func (*Kubernetes) UpdateNamespace

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

UpdateNamespace

type QuotaError

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

func (QuotaError) Error

func (e QuotaError) Error() string

type RuntimeServiceOperator

type RuntimeServiceOperator string
const (
	RuntimeServiceRetain RuntimeServiceOperator = "Retain"
	RuntimeServiceDelete RuntimeServiceOperator = "Delete"
)

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
canal/v1
Package v1 contains API Schema definitions for the database v1 API group +kubebuilder:object:generate=true +groupName=database.erda.cloud
Package v1 contains API Schema definitions for the database v1 API group +kubebuilder:object:generate=true +groupName=database.erda.cloud
mysql/v1
Package v1 contains API Schema definitions for the database v1 API group +kubebuilder:object:generate=true +groupName=database.erda.cloud
Package v1 contains API Schema definitions for the database v1 API group +kubebuilder:object:generate=true +groupName=database.erda.cloud
sourcecov/mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
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 deployment manipulates the k8s api of deployment object
Package deployment manipulates the k8s api of deployment 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 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