Documentation ¶
Overview ¶
Package k8s implements managing the servicegroup by k8s cluster
Index ¶
- Constants
- Variables
- func ConvertEventStatus(reason string) string
- func ConvertToHostAlias(hosts []string) []corev1.HostAlias
- func DefaultHealthCheck(service *apistructs.Service) *apiv1.Probe
- func DereferenceEnvs(podTempate *corev1.PodTemplateSpec) error
- func FillHealthCheckProbe(service *apistructs.Service) *apiv1.Probe
- func GenTolerations() []apiv1.Toleration
- func GenerateECIPodSidecarContainers(inEdge bool) (corev1.Container, error)
- func GenerateEvent(sg *apistructs.ServiceGroup) events.RuntimeEvent
- func IsGroupStateful(sg *apistructs.ServiceGroup) bool
- func IsQuotaError(err error) bool
- func MakeNamespace(sg *apistructs.ServiceGroup) string
- func NewCheckProbe() *apiv1.Probe
- func NewHealthCheck(hc *apistructs.NewHealthCheck) *apiv1.Probe
- func NewQuotaError(msg string) error
- func OldHealthCheck(hc *apistructs.HealthCheck) *apiv1.Probe
- func ParseJobHostBindTemplate(hostPath string, clusterInfo map[string]string) (string, error)
- func SetHealthCheck(container *apiv1.Container, service *apistructs.Service)
- func SetPodAnnotationsBaseContainerEnvs(container corev1.Container, podAnnotations map[string]string)
- func SetPodContainerLifecycleAndSharedVolumes(podSpec *corev1.PodSpec)
- func UseECI(controllerLabels, PodLabels map[string]string) bool
- func ValidateRuntime(specObj interface{}, action string) (*apistructs.ServiceGroup, error)
- type Event
- type Kubernetes
- func (k *Kubernetes) AddContainersEnv(containers []corev1.Container, service *apistructs.Service, ...) error
- func (k *Kubernetes) AddLifeCycle(service *apistructs.Service, podSpec *corev1.PodSpec)
- func (k *Kubernetes) AddPodMountVolume(service *apistructs.Service, podSpec *corev1.PodSpec, ...) error
- func (k *Kubernetes) AddSpotEmptyDir(podSpec *corev1.PodSpec, emptySize int)
- func (k *Kubernetes) Addr() string
- func (k *Kubernetes) CPUOvercommit(limit float64) float64
- func (k *Kubernetes) Cancel(ctx context.Context, specObj interface{}) (interface{}, error)
- func (k *Kubernetes) CapacityInfo() apistructs.CapacityInfoData
- func (k *Kubernetes) CheckQuota(ctx context.Context, projectID, workspace, runtimeID string, ...) (bool, string, error)
- func (k *Kubernetes) CleanUpBeforeDelete()
- func (k *Kubernetes) CopyErdaSecrets(originns, dstns string) ([]apiv1.Secret, error)
- func (k *Kubernetes) Create(ctx context.Context, specObj interface{}) (interface{}, error)
- func (k *Kubernetes) CreateNamespace(ns string, sg *apistructs.ServiceGroup) error
- func (k *Kubernetes) CreateOrPutService(service *apistructs.Service, selectors map[string]string) error
- func (k *Kubernetes) CreateService(service *apistructs.Service, selectors map[string]string) error
- func (k *Kubernetes) CreateStatefulGroup(ctx context.Context, sg *apistructs.ServiceGroup, ...) error
- func (k *Kubernetes) DeleteNamespace(ns string) error
- func (k *Kubernetes) DeletePV(sg *apistructs.ServiceGroup) error
- func (k *Kubernetes) DeleteService(namespace, name string) error
- func (k *Kubernetes) DeployInEdgeCluster() bool
- func (k *Kubernetes) Destroy(ctx context.Context, specObj interface{}) error
- func (k *Kubernetes) GetK8SAddr() string
- func (k *Kubernetes) GetService(namespace, name string) (*apiv1.Service, error)
- func (k *Kubernetes) GetStatefulStatus(sg *apistructs.ServiceGroup) (apistructs.StatusDesc, error)
- func (k *Kubernetes) GetWorkspaceLeftQuota(ctx context.Context, projectID, workspace string) (cpu, mem int64, err error)
- func (k *Kubernetes) IPToHostname(ip string) string
- func (k *Kubernetes) Inspect(ctx context.Context, specObj interface{}) (interface{}, error)
- func (k *Kubernetes) InspectStateful(sg *apistructs.ServiceGroup) (*apistructs.ServiceGroup, error)
- func (k *Kubernetes) InstanceEvent(event Event, runtimeName string, notifier events.Notifier)
- func (*Kubernetes) JobVolumeCreate(ctx context.Context, spec interface{}) (string, error)
- func (k *Kubernetes) KillPod(podname string) error
- func (k *Kubernetes) Kind() executortypes.Kind
- func (k *Kubernetes) ListService(namespace string, selectors map[string]string) (apiv1.ServiceList, error)
- func (k *Kubernetes) MemoryOvercommit(limit int) int
- func (k *Kubernetes) Name() executortypes.Name
- func (k *Kubernetes) NewHealthcheckProbe(service *apistructs.Service) *apiv1.Probe
- func (k *Kubernetes) NewImageSecret(namespace string) error
- func (k *Kubernetes) NewRuntimeImageSecret(namespace string, sg *apistructs.ServiceGroup) error
- func (k *Kubernetes) NotfoundNamespace(ns string) (bool, error)
- func (k *Kubernetes) Precheck(ctx context.Context, specObj interface{}) (apistructs.ServiceGroupPrecheckData, error)
- func (k *Kubernetes) PutService(svc *apiv1.Service) error
- func (k *Kubernetes) Remove(ctx context.Context, specObj interface{}) error
- func (k *Kubernetes) ResourceInfo(brief bool) (apistructs.ClusterResourceInfoData, error)
- func (k *Kubernetes) Scale(ctx context.Context, spec interface{}) (interface{}, error)
- func (k *Kubernetes) SecretVolume(secret *apiv1.Secret) (apiv1.Volume, apiv1.VolumeMount)
- func (k *Kubernetes) SetCpuQuota(quota float64)
- func (k *Kubernetes) SetFineGrainedCPU(container *apiv1.Container, extra map[string]string, cpuSubscribeRatio float64) error
- func (k *Kubernetes) SetNodeLabels(_ executortypes.NodeLabelSetting, hosts []string, labels map[string]string) error
- func (k *Kubernetes) SetOverCommitMem(container *apiv1.Container, memSubscribeRatio float64) error
- func (k *Kubernetes) Status(ctx context.Context, specObj interface{}) (apistructs.StatusDesc, error)
- func (k *Kubernetes) Terminal(namespace, podname, containername string, upperConn *websocket.Conn, ...)
- func (k *Kubernetes) Update(ctx context.Context, specObj interface{}) (interface{}, error)
- func (k *Kubernetes) UpdateContainerResourceEnv(originResource apistructs.Resources, container *corev1.Container)
- func (k *Kubernetes) UpdateImageSecret(namespace string, infos []apistructs.RegistryInfo) error
- func (k *Kubernetes) UpdateK8sService(k8sService *apiv1.Service, service *apistructs.Service, ...) error
- func (k *Kubernetes) UpdateNamespace(ns string, sg *apistructs.ServiceGroup) error
- type QuotaError
- type RuntimeServiceOperator
- type Winsize
Constants ¶
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" )
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" )
const ( Error = '1' Ping = '2' Pong = '3' Input = '4' Output = '5' GetSize = '6' Size = '7' SetSize = '8' )
const (
DefaultProdTerminationGracePeriodSeconds = 45
)
const LabelValueMaxLength int = 63
Variables ¶
var ( DefaultProdLifecyclePreStopHandler = &corev1.LifecycleHandler{ Exec: &corev1.ExecAction{ Command: []string{"sh", "-c", "sleep 10"}, }, } )
var ECIPodSidecarENVFromScheduler = []string{
"ECI_POD_FLUENTBIT_COLLECTOR_ADDR",
"COLLECTOR_SIDECAR_IMAGE",
"ECI_POD_FLUENTBIT_CONFIG_FILE",
}
Functions ¶
func ConvertEventStatus ¶
ConvertEventStatus convert k8s status
func ConvertToHostAlias ¶
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 GenerateEvent ¶
func GenerateEvent(sg *apistructs.ServiceGroup) events.RuntimeEvent
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 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 ¶
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 OldHealthCheck ¶
func OldHealthCheck(hc *apistructs.HealthCheck) *apiv1.Probe
OldHealthCheck Compatible with Dice old version health detection
func ParseJobHostBindTemplate ¶
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 ValidateRuntime ¶
func ValidateRuntime(specObj interface{}, action string) (*apistructs.ServiceGroup, error)
ValidateRuntime check runtime validity
Types ¶
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) 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 (*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 (*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" )
Source Files ¶
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 |