util

package
v1.6.0-alpha.5 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2023 License: Apache-2.0 Imports: 25 Imported by: 18

Documentation

Index

Constants

View Source
const (
	// LastAppliedConfigAnnotation is annotation key of last applied configuration
	LastAppliedConfigAnnotation = "pingcap.com/last-applied-configuration"
)

Variables

View Source
var (
	ClusterClientTLSPath   = "/var/lib/cluster-client-tls"
	ClusterAssetsTLSPath   = "/var/lib/cluster-assets-tls"
	TiDBClientTLSPath      = "/var/lib/tidb-client-tls"
	BRBinPath              = "/var/lib/br-bin"
	DumplingBinPath        = "/var/lib/dumpling-bin"
	LightningBinPath       = "/var/lib/lightning-bin"
	ClusterClientVolName   = "cluster-client-tls"
	DMClusterClientVolName = "dm-cluster-client-tls"
)

Functions

func AppendEnv added in v1.1.0

func AppendEnv(a []corev1.EnvVar, b []corev1.EnvVar) []corev1.EnvVar

AppendEnv appends envs `b` into `a` ignoring envs whose names already exist in `b`. Note that this will not change relative order of envs.

func AppendEnvIfPresent added in v1.1.4

func AppendEnvIfPresent(envs []corev1.EnvVar, name string) []corev1.EnvVar

AppendEnvIfPresent appends the given environment if present

func AppendOverwriteEnv added in v1.1.4

func AppendOverwriteEnv(a []corev1.EnvVar, b []corev1.EnvVar) []corev1.EnvVar

AppendOverwriteEnv appends envs b into a and overwrites the envs whose names already exist in b. Note that this will not change relative order of envs.

func BuildStorageVolumeAndVolumeMount added in v1.1.8

func BuildStorageVolumeAndVolumeMount(storageVolumes []v1alpha1.StorageVolume, defaultStorageClassName *string, memberType v1alpha1.MemberType) ([]corev1.VolumeMount, []corev1.PersistentVolumeClaim)

BuildStorageVolumeAndVolumeMount builds VolumeMounts and PVCs for volumes declaired in spec.storageVolumes of ComponentSpec

func ClusterClientTLSSecretName added in v1.1.0

func ClusterClientTLSSecretName(tcName string) string

func ClusterTLSSecretName added in v1.1.0

func ClusterTLSSecretName(tcName, component string) string

func CombineStringMap added in v1.2.0

func CombineStringMap(maps ...map[string]string) map[string]string

CombineStringMap merges maps into a new map. NOTE: if the same key exists in multiple source maps, the value of the first one will be kept. so we suggest to :

  • pass the map generated by TiDB-Operator as the first argument.
  • pass components' map (labels or annotations) before cluster's.

func CopyStringMap added in v1.2.0

func CopyStringMap(src map[string]string) map[string]string

CopyStringMap copy annotations to a new string map

func DMClientTLSSecretName added in v1.2.0

func DMClientTLSSecretName(dcName string) string

func Encode added in v1.1.0

func Encode(obj interface{}) (string, error)

func FixedLengthRandomPasswordBytes added in v1.3.0

func FixedLengthRandomPasswordBytes() []byte

FixedLengthRandomPasswordBytes generates a random password

func GetDSN added in v1.3.0

func GetDSN(tc *v1alpha1.TidbCluster, password string) string

GetDSN get tidb dsn

func GetDeleteSlotsNumber added in v1.1.10

func GetDeleteSlotsNumber(annotations map[string]string) (int32, error)

func GetOrdinalFromPodName added in v0.4.0

func GetOrdinalFromPodName(podName string) (int32, error)

func GetPodName added in v1.1.0

func GetPodName(tc *v1alpha1.TidbCluster, memberType v1alpha1.MemberType, ordinal int32) string

func GetPodOrdinals added in v1.1.0

func GetPodOrdinals(tc *v1alpha1.TidbCluster, memberType v1alpha1.MemberType) (sets.Int32, error)

GetPodOrdinals gets desired ordials of member in given TidbCluster.

func GetStatefulSetName added in v1.1.0

func GetStatefulSetName(tc *v1alpha1.TidbCluster, memberType v1alpha1.MemberType) string

func IsOwnedByTidbCluster added in v1.1.0

func IsOwnedByTidbCluster(obj metav1.Object) (bool, *metav1.OwnerReference)

IsOwnedByTidbCluster checks if the given object is owned by TidbCluster. Schema Kind and Group are checked, Version is ignored.

func IsPodOrdinalNotExceedReplicas added in v1.1.0

func IsPodOrdinalNotExceedReplicas(pod *corev1.Pod, sts *appsv1.StatefulSet) (bool, error)

func IsStatefulSetScaling added in v1.1.0

func IsStatefulSetScaling(set *appsv1.StatefulSet) bool

func IsStatefulSetUpgrading added in v1.1.0

func IsStatefulSetUpgrading(set *appsv1.StatefulSet) bool

func IsSubMapOf added in v1.1.0

func IsSubMapOf(first map[string]string, second map[string]string) bool

IsSubMapOf returns whether the first map is a sub map of the second map

func MatchLabelFromStoreLabels added in v1.1.8

func MatchLabelFromStoreLabels(storeLabels []*metapb.StoreLabel, componentLabel string) bool

func MustNewRequirement added in v1.1.4

func MustNewRequirement(key string, op selection.Operator, vals []string) *labels.Requirement

MustNewRequirement calls NewRequirement and panics on failure.

func OpenDB added in v1.3.0

func OpenDB(ctx context.Context, dsn string) (*sql.DB, error)

OpenDB opens db

func OrdinalPVCName added in v1.1.0

func OrdinalPVCName(memberType v1alpha1.MemberType, setName string, ordinal int32) string

func RandomBytes added in v1.3.0

func RandomBytes(length int) []byte

RandomBytes generates some random bytes that can be used as a token or as a key

func ResolvePVCFromPod added in v1.1.12

func ResolvePVCFromPod(pod *corev1.Pod, pvcLister corelisterv1.PersistentVolumeClaimLister) ([]*corev1.PersistentVolumeClaim, error)

ResolvePVCFromPod parses pod volumes definition, and returns all PVCs mounted by this pod

If the Pod don't have any PVC, return error 'NotFound'.

func RetainManagedFields added in v1.1.0

func RetainManagedFields(desiredSvc, existedSvc *corev1.Service)

RetainManagedFields retains the fields in the old object that are managed by kube-controller-manager, such as node ports

func SetPassword added in v1.3.0

func SetPassword(ctx context.Context, db *sql.DB, password string) error

SetPassword set tidb password

func StatefulSetEqual added in v1.2.0

func StatefulSetEqual(new apps.StatefulSet, old apps.StatefulSet) bool

statefulSetEqual compares the new Statefulset's spec with old Statefulset's last applied config

func TiDBAuthTokenJWKSSecretName added in v1.4.0

func TiDBAuthTokenJWKSSecretName(tcName string) string

func TiDBClientTLSSecretName added in v1.1.0

func TiDBClientTLSSecretName(tcName string, secretName *string) string

func TiDBServerTLSSecretName added in v1.2.0

func TiDBServerTLSSecretName(tcName string) string

func VolumeClaimTemplate added in v1.1.7

func VolumeClaimTemplate(r corev1.ResourceRequirements, metaName string, storageClassName *string) corev1.PersistentVolumeClaim

Types

type SortEnvByName added in v1.1.0

type SortEnvByName []corev1.EnvVar

SortEnvByName implements sort.Interface to sort env list by name.

func (SortEnvByName) Len added in v1.1.0

func (e SortEnvByName) Len() int

func (SortEnvByName) Less added in v1.1.0

func (e SortEnvByName) Less(i, j int) bool

func (SortEnvByName) Swap added in v1.1.0

func (e SortEnvByName) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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