component

package
v0.8.0-beta.28 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: AGPL-3.0 Imports: 42 Imported by: 3

Documentation

Index

Constants

View Source
const (
	KBJobTTLSecondsAfterFinished = 5
)

Variables

View Source
var (
	ErrClassNotFound   = fmt.Errorf("class not found")
	ErrInvalidResource = fmt.Errorf("resource is not conform to the constraints, please check the ComponentResourceConstraint API")
)
View Source
var (
	Any = v1alpha1.ClassDefRef{}
)

Functions

func BuildAffinity

func BuildAffinity(cluster *appsv1alpha1.Cluster, compSpec *appsv1alpha1.ClusterComponentSpec) *appsv1alpha1.Affinity

BuildAffinity builds affinities for components from cluster and comp spec.

func BuildComponent

func BuildComponent(cluster *appsv1alpha1.Cluster, clusterCompSpec *appsv1alpha1.ClusterComponentSpec) (*appsv1alpha1.Component, error)

BuildComponent builds a new Component object from cluster component spec and definition.

func BuildComponentDefinition added in v0.8.0

func BuildComponentDefinition(clusterDef *appsv1alpha1.ClusterDefinition,
	clusterVer *appsv1alpha1.ClusterVersion,
	clusterCompSpec *appsv1alpha1.ClusterComponentSpec) (*appsv1alpha1.ComponentDefinition, error)

func BuildPodAffinity

func BuildPodAffinity(clusterName string, compName string, compAffinity *appsv1alpha1.Affinity) (*corev1.Affinity, error)

func BuildPodTopologySpreadConstraints

func BuildPodTopologySpreadConstraints(clusterName, compName string, compAffinity *appsv1alpha1.Affinity) []corev1.TopologySpreadConstraint

func BuildRSMFrom added in v0.8.0

BuildRSMFrom builds a new Component object based on Cluster, SynthesizedComponent.

func BuildTolerations

func BuildTolerations(cluster *appsv1alpha1.Cluster, compSpec *appsv1alpha1.ClusterComponentSpec) ([]corev1.Toleration, error)

BuildTolerations builds tolerations for components from cluster and comp spec.

func CheckAndGetClusterComponents added in v0.8.0

func CheckAndGetClusterComponents(ctx context.Context, cli client.Client, cluster *appsv1alpha1.Cluster) ([]client.Object, error)

CheckAndGetClusterComponents checks if all components have created and gets the created components.

func CheckJobSucceed added in v0.7.1

func CheckJobSucceed(ctx context.Context,
	cli client.Client,
	cluster *appsv1alpha1.Cluster,
	jobName string) error

CheckJobSucceed checks the result of job execution. Returns: - bool: whether job exist, true exist - error: any error that occurred during the handling

func CleanJobByName added in v0.7.1

func CleanJobByName(ctx context.Context,
	cli client.Client,
	cluster *appsv1alpha1.Cluster,
	jobName string) error

CleanJobByName cleans up the job task by name.

func CleanJobWithLabels added in v0.7.1

func CleanJobWithLabels(ctx context.Context,
	cli client.Client,
	cluster *appsv1alpha1.Cluster,
	matchLabels client.MatchingLabels) error

CleanJobWithLabels cleans up the job tasks with label.

func ConvertSynthesizeCompRoleToRSMRole added in v0.8.0

func ConvertSynthesizeCompRoleToRSMRole(synthesizedComp *SynthesizedComponent) []workloads.ReplicaRole

ConvertSynthesizeCompRoleToRSMRole converts the component.SynthesizedComponent.Roles to workloads.ReplicaRole.

func FullName added in v0.8.0

func FullName(clusterName, compName string) string

func GenServiceReferences added in v0.8.0

func GenServiceReferences(reqCtx intctrlutil.RequestCtx,
	cli roclient.ReadonlyClient,
	namespace, clusterName string,
	compDef *appsv1alpha1.ComponentDefinition,
	comp *appsv1alpha1.Component) (map[string]*appsv1alpha1.ServiceDescriptor, error)

func GenServiceReferencesLegacy added in v0.8.0

func GetClusterName added in v0.8.0

func GetClusterName(comp *appsv1alpha1.Component) (string, error)

func GetClusterUID added in v0.8.0

func GetClusterUID(comp *appsv1alpha1.Component) (string, error)

func GetCompDefinition added in v0.8.0

func GetCompDefinition(reqCtx intctrlutil.RequestCtx,
	cli client.Client,
	cluster *appsv1alpha1.Cluster,
	compName string) (*appsv1alpha1.ComponentDefinition, error)

GetCompDefinition gets the component definition by component name.

func GetComponentDefName added in v0.8.0

func GetComponentDefName(cluster *appsv1alpha1.Cluster, componentName string) string

GetComponentDefName gets the name of referenced component definition.

func GetComponentDeployMinReadySeconds added in v0.8.0

func GetComponentDeployMinReadySeconds(ctx context.Context,
	cli client.Client,
	cluster appsv1alpha1.Cluster,
	componentName string) (minReadySeconds int32, err error)

GetComponentDeployMinReadySeconds gets the deployment minReadySeconds of the component.

func GetComponentPodList added in v0.8.0

func GetComponentPodList(ctx context.Context, cli client.Reader, cluster appsv1alpha1.Cluster, componentName string) (*corev1.PodList, error)

GetComponentPodList gets the pod list by cluster and componentName

func GetComponentPodListWithRole added in v0.8.0

func GetComponentPodListWithRole(ctx context.Context, cli client.Reader, cluster appsv1alpha1.Cluster, compSpecName, role string) (*corev1.PodList, error)

GetComponentPodListWithRole gets the pod list with target role by cluster and componentName

func GetComponentStsMinReadySeconds added in v0.8.0

func GetComponentStsMinReadySeconds(ctx context.Context,
	cli client.Client,
	cluster appsv1alpha1.Cluster,
	componentName string) (minReadySeconds int32, err error)

GetComponentStsMinReadySeconds gets the statefulSet minReadySeconds of the component.

func GetComponentWorkloadMinReadySeconds added in v0.8.0

func GetComponentWorkloadMinReadySeconds(ctx context.Context,
	cli client.Client,
	cluster appsv1alpha1.Cluster,
	workloadType appsv1alpha1.WorkloadType,
	componentName string) (minReadySeconds int32, err error)

GetComponentWorkloadMinReadySeconds gets the workload minReadySeconds of the component.

func GetConfigSpecByName

func GetConfigSpecByName(synthesizedComp *SynthesizedComponent, configSpec string) *appsv1alpha1.ComponentConfigSpec

func GetEnvReplacementMapForConnCredential

func GetEnvReplacementMapForConnCredential(clusterName string) map[string]string

GetEnvReplacementMapForConnCredential gets the replacement map for connect credential TODO: deprecated, will be removed later.

func GetJobWithLabels added in v0.7.1

func GetJobWithLabels(ctx context.Context,
	cli client.Client,
	cluster *appsv1alpha1.Cluster,
	matchLabels client.MatchingLabels) ([]batchv1.Job, error)

GetJobWithLabels gets the job list with the specified labels.

func GetObjectListByComponentName added in v0.8.0

func GetObjectListByComponentName(ctx context.Context, cli client2.ReadonlyClient, cluster appsv1alpha1.Cluster,
	objectList client.ObjectList, componentName string) error

GetObjectListByComponentName gets k8s workload list with component

func GetReplacementMapForBuiltInEnv

func GetReplacementMapForBuiltInEnv(clusterName, clusterUID, componentName string) map[string]string

GetReplacementMapForBuiltInEnv gets the replacement map for KubeBlocks built-in environment variables.

func IsComponentPodsWithLatestRevision added in v0.8.0

func IsComponentPodsWithLatestRevision(ctx context.Context, cli client.Reader,
	cluster *appsv1alpha1.Cluster, rsm *workloads.ReplicatedStateMachine) (bool, error)

IsComponentPodsWithLatestRevision checks whether the underlying pod spec matches the one declared in the Cluster/Component.

func ListObjWithLabelsInNamespace added in v0.8.0

func ListObjWithLabelsInNamespace[T generics.Object, PT generics.PObject[T], L generics.ObjList[T], PL generics.PObjList[T, L]](
	ctx context.Context, cli client.Reader, _ func(T, PT, L, PL), namespace string, labels client.MatchingLabels) ([]PT, error)

func ListPodOwnedByComponent added in v0.8.0

func ListPodOwnedByComponent(ctx context.Context, cli client.Reader, namespace string, labels client.MatchingLabels) ([]*corev1.Pod, error)

func ListRSMOwnedByComponent added in v0.8.0

func ListRSMOwnedByComponent(ctx context.Context, cli client.Client, namespace string, labels client.MatchingLabels) ([]*workloads.ReplicatedStateMachine, error)

func ParseComponentClasses added in v0.8.0

func ParseComponentClasses(classDefinition v1alpha1.ComponentClassDefinition) (map[v1alpha1.ClassDefRef]*v1alpha1.ComponentClass, error)

ParseComponentClasses parses ComponentClassDefinition to component classes

func ReconcileCompPostProvision added in v0.8.0

func ReconcileCompPostProvision(ctx context.Context,
	cli client.Client,
	cluster *appsv1alpha1.Cluster,
	comp *appsv1alpha1.Component,
	synthesizeComp *SynthesizedComponent,
	dag *graph.DAG) error

ReconcileCompPostProvision reconciles the component-level postProvision command.

func ReplaceNamedVars

func ReplaceNamedVars(namedValuesMap map[string]string, targetVar string, limits int, matchAll bool) string

ReplaceNamedVars replaces the placeholder in targetVar if it is match and returns the replaced result

func ReplaceSecretEnvVars

func ReplaceSecretEnvVars(namedValuesMap map[string]string, envs []corev1.EnvVar) []corev1.EnvVar

ReplaceSecretEnvVars replaces the env secret value with namedValues and returns new envs

func ResolveEnvNTemplateVars

func ResolveEnvNTemplateVars(ctx context.Context, cli client.Reader, synthesizedComp *SynthesizedComponent,
	annotations map[string]string, definedVars []appsv1alpha1.EnvVar) error

func ShortName added in v0.8.0

func ShortName(clusterName, compName string) (string, error)

Types

type ByClassResource added in v0.8.0

type ByClassResource []*ComponentClassWithRef

func (ByClassResource) Len added in v0.8.0

func (b ByClassResource) Len() int

func (ByClassResource) Less added in v0.8.0

func (b ByClassResource) Less(i, j int) bool

func (ByClassResource) Swap added in v0.8.0

func (b ByClassResource) Swap(i, j int)

type ByResourceList added in v0.8.0

type ByResourceList []corev1.ResourceList

func (ByResourceList) Len added in v0.8.0

func (b ByResourceList) Len() int

func (ByResourceList) Less added in v0.8.0

func (b ByResourceList) Less(i, j int) bool

func (ByResourceList) Swap added in v0.8.0

func (b ByResourceList) Swap(i, j int)

type ByRuleList added in v0.8.0

func (ByRuleList) Len added in v0.8.0

func (m ByRuleList) Len() int

func (ByRuleList) Less added in v0.8.0

func (m ByRuleList) Less(i, j int) bool

func (ByRuleList) Swap added in v0.8.0

func (m ByRuleList) Swap(i, j int)

type ComponentClassWithRef added in v0.8.0

type ComponentClassWithRef struct {
	appsv1alpha1.ComponentClass

	ClassDefRef appsv1alpha1.ClassDefRef
}

type Manager added in v0.8.0

type Manager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewManager added in v0.8.0

func NewManager(classDefinitionList v1alpha1.ComponentClassDefinitionList, constraintList v1alpha1.ComponentResourceConstraintList) (*Manager, error)

func (*Manager) ChooseClass added in v0.8.0

func (r *Manager) ChooseClass(synthesizedComp *SynthesizedComponent, comp *v1alpha1.Component) (*ComponentClassWithRef, error)

ChooseClass chooses the classes to be used for a given component with constraints TODO(xingran): remove the dependency of SynthesizedComponent.ClusterDefName and SynthesizedComponent.ClusterCompDefName in the future

func (*Manager) GetClasses added in v0.8.0

func (r *Manager) GetClasses() map[string][]*ComponentClassWithRef

func (*Manager) GetResources added in v0.8.0

func (r *Manager) GetResources(synthesizedComp *SynthesizedComponent, comp *v1alpha1.Component) (corev1.ResourceList, error)

GetResources returns the resource list of the component TODO(xingran): remove the dependency of SynthesizedComponent.ClusterDefName and SynthesizedComponent.ClusterCompDefName in the future

func (*Manager) HasClass added in v0.8.0

func (r *Manager) HasClass(compType string, classDefRef v1alpha1.ClassDefRef) bool

HasClass returns true if the component has the specified class

func (*Manager) ValidateResources added in v0.8.0

func (r *Manager) ValidateResources(synthesizedComp *SynthesizedComponent, comp *v1alpha1.Component) error

ValidateResources validates if the resources of the component is invalid TODO(xingran): remove the dependency of SynthesizedComponent.ClusterDefName and SynthesizedComponent.ClusterCompDefName in the future

type MonitorConfig

type MonitorConfig struct {
	Enable     bool   `json:"enable"`
	BuiltIn    bool   `json:"builtIn"`
	ScrapePort int32  `json:"scrapePort,omitempty"`
	ScrapePath string `json:"scrapePath,omitempty"`
}

type SynthesizedComponent

type SynthesizedComponent struct {
	Namespace            string                                 `json:"namespace,omitempty"`
	ClusterName          string                                 `json:"clusterName,omitempty"`
	ClusterUID           string                                 `json:"clusterUID,omitempty"`
	Comp2CompDefs        map[string]string                      `json:"comp2CompDefs,omitempty"` // {compName: compDefName}
	Name                 string                                 `json:"name,omitempty"`          // the name of the component without clusterName prefix
	FullCompName         string                                 `json:"fullCompName,omitempty"`  // the full name of the component with clusterName prefix
	CompDefName          string                                 `json:"compDefName,omitempty"`   // the name of the componentDefinition
	Replicas             int32                                  `json:"replicas"`
	PodSpec              *corev1.PodSpec                        `json:"podSpec,omitempty"`
	VolumeClaimTemplates []corev1.PersistentVolumeClaimTemplate `json:"volumeClaimTemplates,omitempty"`
	Monitor              *MonitorConfig                         `json:"monitor,omitempty"`
	EnabledLogs          []string                               `json:"enabledLogs,omitempty"`
	LogConfigs           []v1alpha1.LogConfig                   `json:"logConfigs,omitempty"`
	ConfigTemplates      []v1alpha1.ComponentConfigSpec         `json:"configTemplates,omitempty"`
	ScriptTemplates      []v1alpha1.ComponentTemplateSpec       `json:"scriptTemplates,omitempty"`
	TLSConfig            *v1alpha1.TLSConfig                    `json:"tlsConfig"`
	ServiceAccountName   string                                 `json:"serviceAccountName,omitempty"`
	// TODO: remove this later
	ComponentRefEnvs  []corev1.EnvVar                        `json:"componentRefEnvs,omitempty"`
	ServiceReferences map[string]*v1alpha1.ServiceDescriptor `json:"serviceReferences,omitempty"`
	TemplateVars      map[string]any                         `json:"templateVars,omitempty"`

	RsmTransformPolicy workloads.RsmTransformPolicy `json:"rsmTransformPolicy,omitempty"`
	Nodes              []types.NodeName             `json:"nodes,omitempty"`
	Instances          []string                     `json:"instances,omitempty"`

	NodesAssignment []workloads.NodeAssignment `json:"nodesAssignment,omitempty"`

	// The following fields were introduced with the ComponentDefinition and Component API in KubeBlocks version 0.8.0
	Roles             []v1alpha1.ReplicaRole              `json:"roles,omitempty"`
	Labels            map[string]string                   `json:"labels,omitempty"`
	UpdateStrategy    *v1alpha1.UpdateStrategy            `json:"updateStrategy,omitempty"`
	PolicyRules       []rbacv1.PolicyRule                 `json:"policyRules,omitempty"`
	LifecycleActions  *v1alpha1.ComponentLifecycleActions `json:"lifecycleActions,omitempty"`
	SystemAccounts    []v1alpha1.SystemAccount            `json:"systemAccounts,omitempty"`
	RoleArbitrator    *v1alpha1.RoleArbitrator            `json:"roleArbitrator,omitempty"`
	Volumes           []v1alpha1.ComponentVolume          `json:"volumes,omitempty"`
	ComponentServices []v1alpha1.Service                  `json:"componentServices,omitempty"`

	// TODO(xingran): The following fields will be deprecated after version 0.8.0 and will be replaced with a new data structure.
	CustomLabelSpecs    []v1alpha1.CustomLabelSpec        `json:"customLabelSpecs,omitempty"`    // The CustomLabelSpecs will be replaced with Labels in the future.
	Probes              *v1alpha1.ClusterDefinitionProbes `json:"probes,omitempty"`              // The Probes will be replaced with LifecycleActions.RoleProbe in the future.
	VolumeTypes         []v1alpha1.VolumeTypeSpec         `json:"volumeTypes,omitempty"`         // The VolumeTypes will be replaced with Volumes in the future.
	VolumeProtection    *v1alpha1.VolumeProtectionSpec    `json:"volumeProtection,omitempty"`    // The VolumeProtection will be replaced with Volumes in the future.
	Services            []corev1.Service                  `json:"services,omitempty"`            // The Services will be replaced with ComponentServices in the future.
	StatefulSetWorkload v1alpha1.StatefulSetWorkload      `json:"statefulSetWorkload,omitempty"` // The StatefulSetWorkload will be replaced with UpdateStrategy in the future.
	TLS                 bool                              `json:"tls"`                           // The TLS will be replaced with TLSConfig in the future.

	// TODO(xingran): The following fields will be deprecated after KubeBlocks version 0.8.0
	ClusterDefName        string                          `json:"clusterDefName,omitempty"`     // the name of the clusterDefinition
	ClusterCompDefName    string                          `json:"clusterCompDefName,omitempty"` // the name of the clusterDefinition.Spec.ComponentDefs[*].Name or cluster.Spec.ComponentSpecs[*].ComponentDefRef
	CharacterType         string                          `json:"characterType,omitempty"`
	WorkloadType          v1alpha1.WorkloadType           `json:"workloadType,omitempty"`
	StatelessSpec         *v1alpha1.StatelessSetSpec      `json:"statelessSpec,omitempty"`
	StatefulSpec          *v1alpha1.StatefulSetSpec       `json:"statefulSpec,omitempty"`
	ConsensusSpec         *v1alpha1.ConsensusSetSpec      `json:"consensusSpec,omitempty"`
	ReplicationSpec       *v1alpha1.ReplicationSetSpec    `json:"replicationSpec,omitempty"`
	RSMSpec               *v1alpha1.RSMSpec               `json:"rsmSpec,omitempty"`
	HorizontalScalePolicy *v1alpha1.HorizontalScalePolicy `json:"horizontalScalePolicy,omitempty"`
	// MinAvailable is used to determine whether to create a PDB (Pod Disruption Budget) object.
	// However, the functionality of PDB should be implemented within the RSM. Therefore, PDB objects are no longer needed in the new API, and the MinAvailable field should be deprecated.
	// The old MinAvailable field, which is determined based on the deprecated "workloadType" field, is also no longer applicable in the new API.
	MinAvailable *intstr.IntOrString `json:"minAvailable,omitempty"`
}

func BuildSynthesizedComponent added in v0.8.0

func BuildSynthesizedComponent(reqCtx intctrlutil.RequestCtx,
	cli client.Reader,
	cluster *appsv1alpha1.Cluster,
	compDef *appsv1alpha1.ComponentDefinition,
	comp *appsv1alpha1.Component) (*SynthesizedComponent, error)

BuildSynthesizedComponent builds a new SynthesizedComponent object, which is a mixture of component-related configs from ComponentDefinition and Component.

func BuildSynthesizedComponent4Generated added in v0.8.0

func BuildSynthesizedComponent4Generated(reqCtx intctrlutil.RequestCtx,
	cli client.Reader,
	cluster *appsv1alpha1.Cluster,
	comp *appsv1alpha1.Component) (*appsv1alpha1.ComponentDefinition, *SynthesizedComponent, error)

BuildSynthesizedComponent4Generated builds SynthesizedComponent for generated Component which w/o ComponentDefinition.

func BuildSynthesizedComponentWrapper added in v0.8.0

func BuildSynthesizedComponentWrapper(reqCtx intctrlutil.RequestCtx,
	cli client.Reader,
	cluster *appsv1alpha1.Cluster,
	clusterCompSpec *appsv1alpha1.ClusterComponentSpec) (*SynthesizedComponent, error)

BuildSynthesizedComponentWrapper builds a new SynthesizedComponent object with a given ClusterComponentSpec. TODO: remove this

func BuildSynthesizedComponentWrapper4Test added in v0.8.0

func BuildSynthesizedComponentWrapper4Test(reqCtx intctrlutil.RequestCtx,
	cli client.Reader,
	clusterDef *appsv1alpha1.ClusterDefinition,
	clusterVer *appsv1alpha1.ClusterVersion,
	cluster *appsv1alpha1.Cluster,
	clusterCompSpec *appsv1alpha1.ClusterComponentSpec) (*SynthesizedComponent, error)

BuildSynthesizedComponentWrapper4Test builds a new SynthesizedComponent object with a given ClusterComponentSpec.

Jump to

Keyboard shortcuts

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