k8sutils

package
v0.15.10 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RedisFinalizer            string = "redisFinalizer"
	RedisClusterFinalizer     string = "redisClusterFinalizer"
	RedisReplicationFinalizer string = "redisReplicationFinalizer"
	RedisSentinelFinalizer    string = "redisSentinelFinalizer"
)
View Source
const (
	AnnotationKeyRecreateStatefulset = "redis.opstreelabs.in/recreate-statefulset"
)

Variables

This section is empty.

Functions

func AddLabelToPod added in v0.15.7

func AddLabelToPod(client kubernetes.Interface, namespace, podName, key, value string) error

AddLabelToPod adds a new label to the specified Pod.

func AddOwnerRefToObject

func AddOwnerRefToObject(obj metav1.Object, ownerRef metav1.OwnerReference)

AddOwnerRefToObject adds the owner references to object

func AddRedisClusterFinalizer

func AddRedisClusterFinalizer(cr *redisv1beta2.RedisCluster, cl client.Client) error

AddRedisClusterFinalizer add finalizer for graceful deletion

func AddRedisFinalizer

func AddRedisFinalizer(cr *redisv1beta2.Redis, cl client.Client) error

AddRedisFinalizer add finalizer for graceful deletion

func AddRedisNodeToCluster

func AddRedisNodeToCluster(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisCluster)

Add redis cluster node would add a node to the existing redis cluster using redis-cli

func AddRedisReplicationFinalizer

func AddRedisReplicationFinalizer(cr *redisv1beta2.RedisReplication, cl client.Client) error

AddRedisReplicationFinalizer add finalizer for graceful deletion

func AddRedisSentinelFinalizer

func AddRedisSentinelFinalizer(cr *redisv1beta2.RedisSentinel, cl client.Client) error

AddRedisSentinelFinalizer add finalizer for graceful deletion

func CheckIfEmptyMasters

func CheckIfEmptyMasters(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisCluster)

func CheckRedisClusterState

func CheckRedisClusterState(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisCluster) int

CheckRedisClusterState will check the redis cluster state

func CheckRedisNodeCount

func CheckRedisNodeCount(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisCluster, nodeType string) int32

CheckRedisNodeCount will check the count of redis nodes

func CheckRedisReplicationReady added in v0.15.6

func CheckRedisReplicationReady(cr *redisv1beta2.RedisReplication) bool

func CheckRedisSentinelReady added in v0.15.6

func CheckRedisSentinelReady(cr *redisv1beta2.RedisSentinel) bool

func CheckRedisStandaloneReady added in v0.15.6

func CheckRedisStandaloneReady(cr *redisv1beta2.Redis) bool

func ClusterFailover

func ClusterFailover(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisCluster)

func CreateMasterSlaveReplication

func CreateMasterSlaveReplication(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisReplication, masterPods []string, slavePods []string) error

func CreateMultipleLeaderRedisCommand

func CreateMultipleLeaderRedisCommand(client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisCluster) []string

CreateMultipleLeaderRedisCommand will create command for single leader cluster creation

func CreateOrUpdatePodDisruptionBudget

func CreateOrUpdatePodDisruptionBudget(pdbDef *policyv1.PodDisruptionBudget) error

CreateOrUpdateService method will create or update Redis service

func CreateOrUpdateService

func CreateOrUpdateService(namespace string, serviceMeta metav1.ObjectMeta, ownerDef metav1.OwnerReference, enableMetrics, headless bool, serviceType string) error

CreateOrUpdateService method will create or update Redis service

func CreateOrUpdateStateFul

func CreateOrUpdateStateFul(namespace string, stsMeta metav1.ObjectMeta, params statefulSetParameters, ownerDef metav1.OwnerReference, initcontainerParams initContainerParameters, containerParams containerParameters, sidecars *[]redisv1beta2.Sidecar) error

CreateOrUpdateStateFul method will create or update Redis service

func CreateRedisFollower

func CreateRedisFollower(cr *redisv1beta2.RedisCluster) error

CreateRedisFollower will create a follower redis setup

func CreateRedisFollowerService

func CreateRedisFollowerService(cr *redisv1beta2.RedisCluster) error

CreateRedisFollowerService method will create service for Redis Follower

func CreateRedisLeader

func CreateRedisLeader(cr *redisv1beta2.RedisCluster) error

CreateRedisLeader will create a leader redis setup

func CreateRedisLeaderService

func CreateRedisLeaderService(cr *redisv1beta2.RedisCluster) error

CreateRedisLeaderService method will create service for Redis Leader

func CreateRedisSentinel

func CreateRedisSentinel(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisSentinel) error

Redis Sentinel Create the Redis Sentinel Setup

func CreateRedisSentinelService

func CreateRedisSentinelService(cr *redisv1beta2.RedisSentinel) error

Create RedisSentinel Service

func CreateReplicationRedis

func CreateReplicationRedis(cr *redisv1beta2.RedisReplication) error

CreateReplicationRedis will create a replication redis setup

func CreateReplicationService

func CreateReplicationService(cr *redisv1beta2.RedisReplication) error

CreateReplicationService method will create replication service for Redis

func CreateSingleLeaderRedisCommand

func CreateSingleLeaderRedisCommand(logger logr.Logger, cr *redisv1beta2.RedisCluster) []string

CreateSingleLeaderRedisCommand will create command for single leader cluster creation

func CreateStandaloneRedis

func CreateStandaloneRedis(cr *redisv1beta2.Redis) error

CreateStandaloneRedis will create a standalone redis setup

func CreateStandaloneService

func CreateStandaloneService(cr *redisv1beta2.Redis) error

CreateStandaloneService method will create standalone service for Redis

func ExecuteFailoverOperation

func ExecuteFailoverOperation(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisCluster) error

ExecuteFailoverOperation will execute redis failover operations

func ExecuteRedisClusterCommand

func ExecuteRedisClusterCommand(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisCluster)

ExecuteRedisClusterCommand will execute redis cluster creation command

func ExecuteRedisReplicationCommand

func ExecuteRedisReplicationCommand(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisCluster)

ExecuteRedisReplicationCommand will execute the replication command

func GenerateK8sClient

func GenerateK8sClient(configProvider K8sConfigProvider) (kubernetes.Interface, error)

GenerateK8sClient create client for kubernetes

func GenerateK8sConfig

func GenerateK8sConfig() (*rest.Config, error)

GenerateK8sConfig will load the kube config file

func GenerateK8sDynamicClient

func GenerateK8sDynamicClient(configProvider K8sConfigProvider) (dynamic.Interface, error)

GenerateK8sClient create Dynamic client for kubernetes

func GenerateTLSEnvironmentVariables

func GenerateTLSEnvironmentVariables(tlsconfig *redisv1beta2.TLSConfig) []corev1.EnvVar

func GetPodDisruptionBudget

func GetPodDisruptionBudget(namespace string, pdb string) (*policyv1.PodDisruptionBudget, error)

GetPodDisruptionBudget is a method to get PodDisruptionBudgets in Kubernetes

func GetPodsByLabels added in v0.15.7

func GetPodsByLabels(client kubernetes.Interface, labels map[string]string, namespace string) (*v1.PodList, error)

GetPodsByLabels retrieves a list of Pods that match the specified labels.

func GetRedisNodesByRole

func GetRedisNodesByRole(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisReplication, redisRole string) []string

Get Redis nodes by it's role i.e. master, slave and sentinel

func GetStatefulSet

func GetStatefulSet(namespace string, stateful string) (*appsv1.StatefulSet, error)

GetStateFulSet is a method to get statefulset in Kubernetes

func HandleRedisClusterFinalizer

func HandleRedisClusterFinalizer(ctrlclient client.Client, k8sClient kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisCluster) error

HandleRedisClusterFinalizer finalize resource if instance is marked to be deleted

func HandleRedisFinalizer

func HandleRedisFinalizer(ctrlclient client.Client, k8sClient kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.Redis) error

HandleRedisFinalizer finalize resource if instance is marked to be deleted

func HandleRedisReplicationFinalizer

func HandleRedisReplicationFinalizer(ctrlclient client.Client, k8sClient kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisReplication) error

Handle RedisReplicationFinalizer finalize resource if instance is marked to be deleted

func HandleRedisSentinelFinalizer

func HandleRedisSentinelFinalizer(cr *redisv1beta2.RedisSentinel, cl client.Client) error

HandleRedisSentinelFinalizer finalize resource if instance is marked to be deleted

func LabelSelectors

func LabelSelectors(labels map[string]string) *metav1.LabelSelector

LabelSelectors generates object for label selection

func RebalanceRedisCluster

func RebalanceRedisCluster(client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisCluster)

Rebalance Redis Cluster Would Rebalance the Redis Cluster without using the empty masters

func RebalanceRedisClusterEmptyMasters

func RebalanceRedisClusterEmptyMasters(client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisCluster)

Rebalance the Redis CLuster using the Empty Master Nodes

func ReconcileRedisPodDisruptionBudget

func ReconcileRedisPodDisruptionBudget(cr *redisv1beta2.RedisCluster, role string, pdbParams *commonapi.RedisPodDisruptionBudget) error

CreateRedisLeaderPodDisruptionBudget check and create a PodDisruptionBudget for Leaders

func ReconcileSentinelPodDisruptionBudget

func ReconcileSentinelPodDisruptionBudget(cr *redisv1beta2.RedisSentinel, pdbParams *commonapi.RedisPodDisruptionBudget) error

func RemoveRedisFollowerNodesFromCluster

func RemoveRedisFollowerNodesFromCluster(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisCluster)

Remove redis follower node would remove all follower nodes of last leader node using redis-cli

func RemoveRedisNodeFromCluster

func RemoveRedisNodeFromCluster(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisCluster, removePod RedisDetails)

Remove redis cluster node would remove last node to the existing redis cluster using redis-cli

func ReshardRedisCluster

func ReshardRedisCluster(client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisCluster, remove bool)

ReshardRedisCluster transfer the slots from the last node to the first node.

NOTE: when all slot been transferred, the node become slave of the first master node.

func UpdateRedisClusterStatus

func UpdateRedisClusterStatus(cr *redisv1beta2.RedisCluster, status status.RedisClusterState, resaon string, readyLeaderReplicas, readyFollowerReplicas int32) error

UpdateRedisClusterStatus will update the status of the RedisCluster

func UpdateRedisReplicationStatus added in v0.15.6

func UpdateRedisReplicationStatus(cr *redisv1beta2.RedisReplication, status status.RedisReplicationState, resaon string) error

func UpdateRedisSentinelStatus added in v0.15.6

func UpdateRedisSentinelStatus(cr *redisv1beta2.RedisSentinel, status status.RedisSentinelState, resaon string) error

func UpdateRedisStandaloneStatus added in v0.15.6

func UpdateRedisStandaloneStatus(cr *redisv1beta2.Redis, status status.RedisStandaloneState, resaon string) error

func VerifyLeaderPod

func VerifyLeaderPod(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisCluster) bool

verifyLeaderPod return true if the pod is leader/master

Types

type K8sConfigProvider

type K8sConfigProvider = func() (*rest.Config, error)

type RedisClusterSTS

type RedisClusterSTS struct {
	RedisStateFulType             string
	ExternalConfig                *string
	SecurityContext               *corev1.SecurityContext
	Affinity                      *corev1.Affinity `json:"affinity,omitempty"`
	TerminationGracePeriodSeconds *int64           `json:"terminationGracePeriodSeconds,omitempty" protobuf:"varint,4,opt,name=terminationGracePeriodSeconds"`
	ReadinessProbe                *commonapi.Probe
	LivenessProbe                 *commonapi.Probe
	NodeSelector                  map[string]string
	Tolerations                   *[]corev1.Toleration
}

RedisClusterSTS is a interface to call Redis Statefulset function

func (RedisClusterSTS) CreateRedisClusterSetup

func (service RedisClusterSTS) CreateRedisClusterSetup(cr *redisv1beta2.RedisCluster) error

CreateRedisClusterSetup will create Redis Setup for leader and follower

type RedisClusterService

type RedisClusterService struct {
	RedisServiceRole string
}

RedisClusterService is a interface to call Redis Service function

func (RedisClusterService) CreateRedisClusterService

func (service RedisClusterService) CreateRedisClusterService(cr *redisv1beta2.RedisCluster) error

CreateRedisClusterService method will create service for Redis

type RedisDetails

type RedisDetails struct {
	PodName   string
	Namespace string
}

RedisDetails will hold the information for Redis Pod

type RedisReplicationInfo added in v0.15.9

type RedisReplicationInfo struct {
	MasterIP     string
	MasterSecret commonapi.ExistingPasswordSecret
}

type RedisReplicationObject

type RedisReplicationObject struct {
	RedisReplication *redisv1beta2.RedisReplication
}

type RedisSentinelSTS

type RedisSentinelSTS struct {
	RedisStateFulType             string
	ExternalConfig                *string
	Affinity                      *corev1.Affinity `json:"affinity,omitempty"`
	TerminationGracePeriodSeconds *int64           `json:"terminationGracePeriodSeconds,omitempty" protobuf:"varint,4,opt,name=terminationGracePeriodSeconds"`
	ReadinessProbe                *commonapi.Probe
	LivenessProbe                 *commonapi.Probe
}

RedisSentinelSTS is a interface to call Redis Statefulset function

func (RedisSentinelSTS) CreateRedisSentinelSetup

func (service RedisSentinelSTS) CreateRedisSentinelSetup(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisSentinel) error

Create Redis Sentinel Cluster Setup

type RedisSentinelService

type RedisSentinelService struct {
	RedisServiceRole string
}

RedisSentinelService is a interface to call Redis Service function

func (RedisSentinelService) CreateRedisSentinelService

func (service RedisSentinelService) CreateRedisSentinelService(cr *redisv1beta2.RedisSentinel) error

Create the Service for redis sentinel

Jump to

Keyboard shortcuts

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