common

package
v0.9.3-beta.11 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: AGPL-3.0 Imports: 26 Imported by: 1

Documentation

Overview

Package common provides types and utils shared by all KubeBlocks components: KubeBlocks Core, KBCLI, Lorry etc. will promote to pkg/common when stable.

Index

Constants

View Source
const (
	PrometheusScrapeAnnotationPath    = "monitor.kubeblocks.io/path"
	PrometheusScrapeAnnotationPort    = "monitor.kubeblocks.io/port"
	PrometheusScrapeAnnotationScheme  = "monitor.kubeblocks.io/scheme"
	PrometheusScrapeAnnotationEnabled = "monitor.kubeblocks.io/scrape"
)
View Source
const (
	MaxGeneratedNameLength = maxNameLength - randomLength
)
View Source
const (
	// Symbols is the list of symbols.
	Symbols = "!@#&*"
)

Variables

This section is empty.

Functions

func CoverStringToInterfaceBySchemaType added in v0.8.0

func CoverStringToInterfaceBySchemaType(openAPIV3Schema *apiextensionsv1.JSONSchemaProps, input map[string]string) (map[string]interface{}, error)

func CutString added in v0.8.3

func CutString(str string, length int) string

CutString cuts the string with specified length.

func Expand

func Expand(input string, mapping func(string) string) string

Expand replaces variable references in the input string according to the expansion spec using the given mapping function to resolve the values of variables.

func FromContainerPort added in v0.9.0

func FromContainerPort(exporter Exporter, container *corev1.Container) string

func FromScheme added in v0.9.0

func FromScheme(exporter appsv1alpha1.Exporter) string

func FromScrapePath added in v0.9.0

func FromScrapePath(exporter appsv1alpha1.Exporter) string

func GeneratePassword added in v0.8.2

func GeneratePassword(length, numDigits, numSymbols int, noUpper bool, seed string) (string, error)

GeneratePassword generates a password with the given requirements and seed.

func GetFieldRef added in v0.8.0

func GetFieldRef(pod *corev1.Pod, from *corev1.EnvVarSource) (string, error)

GetFieldRef returns the value of the supplied path in the given object

func GetScrapeAnnotations added in v0.9.0

func GetScrapeAnnotations(exporter Exporter, container *corev1.Container) map[string]string

func IsCompactMode added in v0.8.0

func IsCompactMode(annotations map[string]string) bool

IsCompactMode tells whether there is a reconciliation compact mode key in the 'annotations'.

func MappingFuncFor

func MappingFuncFor(context ...map[string]string) func(string) string

MappingFuncFor returns a mapping function for use with Expand that implements the expansion semantics defined in the expansion spec; it returns the input string wrapped in the expansion syntax if no mapping for the input is found.

func SafeAddInt added in v0.8.0

func SafeAddInt(a, b int) int

func ToCamelCase added in v0.8.0

func ToCamelCase(input string) string

ToCamelCase transforms k8s resource Name with camel case, for examples: - make-food to MakeFood - make.food to MakeFood

func ValidateDataWithSchema added in v0.8.0

func ValidateDataWithSchema(openAPIV3Schema *apiextensionsv1.JSONSchemaProps, data interface{}) error

ValidateDataWithSchema validates if the data is valid with the jsonSchema.

Types

type BuiltinHandler

type BuiltinHandler string

BuiltinHandler defines builtin role probe handler name.

const (
	MySQLHandler    BuiltinHandler = "mysql"
	PostgresHandler BuiltinHandler = "postgres"
	MongoDBHandler  BuiltinHandler = "mongodb"
	RedisHandler    BuiltinHandler = "redis"
	ETCDHandler     BuiltinHandler = "etcd"
	KafkaHandler    BuiltinHandler = "kafka"
	WeSQLHandler    BuiltinHandler = "wesql"
)

type Exporter added in v0.9.0

type Exporter struct {
	appsv1alpha1.Exporter `json:",inline"`
	TargetPort            *intstr.IntOrString `json:"targetPort,omitempty"`
}

Exporter defines the built-in metrics exporter.

type GlobalRoleSnapshot

type GlobalRoleSnapshot struct {
	Version          string            `json:"term,omitempty"`
	PodRoleNamePairs []PodRoleNamePair `json:"PodRoleNamePairs,omitempty"`
}

GlobalRoleSnapshot defines a global(leader) perspective of all pods role. KB provides two role probe methods: per-pod level role probe and retrieving all node roles from the leader node. The latter is referred to as the global role snapshot. This data structure is used to represent a snapshot of global role information. The snapshot contains two types of information: the mapping relationship between all node names and role names, and the version of the snapshot. The purpose of the snapshot version is to ensure that only role information that is more up-to-date than the current role information on the Pod Label will be updated. This resolves the issue of role information disorder in scenarios such as KB upgrades or exceptions causing restarts, network partitioning leading to split-brain situations, node crashes, and similar occurrences.

type NameGenerator added in v0.8.2

type NameGenerator interface {
	// GenerateName generates a valid name from the base name, adding a random suffix to the
	// the base. If base is valid, the returned name must also be valid. The generator is
	// responsible for knowing the maximum valid name length.
	GenerateName(base string) string
}

NameGenerator generates names for objects. Some backends may have more information available to guide selection of new names and this interface hides those details.

var SimpleNameGenerator NameGenerator = simpleNameGenerator{}

SimpleNameGenerator is a generator that returns the name plus a random suffix of five alphanumerics when a name is requested. The string is guaranteed to not exceed the length of a standard Kubernetes name (63 characters)

type PasswordReader added in v0.8.2

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

func (*PasswordReader) Read added in v0.8.2

func (r *PasswordReader) Read(data []byte) (int, error)

func (*PasswordReader) Seed added in v0.8.2

func (r *PasswordReader) Seed(seed int64)

type PodRoleNamePair

type PodRoleNamePair struct {
	PodName  string `json:"podName,omitempty"`
	RoleName string `json:"roleName,omitempty"`
	PodUID   string `json:"podUid,omitempty"`
}

PodRoleNamePair defines a pod name and role name pair.

Jump to

Keyboard shortcuts

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