k8sutils

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 43 Imported by: 2

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"
)
View Source
const (
	EnvOperatorSTSPVCTemplateName = "OPERATOR_STS_PVC_TEMPLATE_NAME"
)

Variables

This section is empty.

Functions

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 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, cl kubernetes.Interface) error

CreateOrUpdateService method will create or update Redis service

func CreateOrUpdateService

func CreateOrUpdateService(namespace string, serviceMeta metav1.ObjectMeta, ownerDef metav1.OwnerReference, epp exporterPortProvider, headless bool, serviceType string, port int, cl kubernetes.Interface, extra ...corev1.ServicePort) 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, cl kubernetes.Interface) error

CreateOrUpdateStateFul method will create or update Redis service

func CreateRedisFollower

func CreateRedisFollower(cr *redisv1beta2.RedisCluster, cl kubernetes.Interface) error

CreateRedisFollower will create a follower redis setup

func CreateRedisFollowerService

func CreateRedisFollowerService(cr *redisv1beta2.RedisCluster, cl kubernetes.Interface) error

CreateRedisFollowerService method will create service for Redis Follower

func CreateRedisLeader

func CreateRedisLeader(cr *redisv1beta2.RedisCluster, cl kubernetes.Interface) error

CreateRedisLeader will create a leader redis setup

func CreateRedisLeaderService

func CreateRedisLeaderService(cr *redisv1beta2.RedisCluster, cl kubernetes.Interface) 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, cl kubernetes.Interface, dcl dynamic.Interface) error

Redis Sentinel Create the Redis Sentinel Setup

func CreateRedisSentinelService

func CreateRedisSentinelService(cr *redisv1beta2.RedisSentinel, cl kubernetes.Interface) error

Create RedisSentinel Service

func CreateReplicationRedis

func CreateReplicationRedis(cr *redisv1beta2.RedisReplication, cl kubernetes.Interface) error

CreateReplicationRedis will create a replication redis setup

func CreateReplicationService

func CreateReplicationService(cr *redisv1beta2.RedisReplication, cl kubernetes.Interface) 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, cl kubernetes.Interface) error

CreateStandaloneRedis will create a standalone redis setup

func CreateStandaloneService

func CreateStandaloneService(cr *redisv1beta2.Redis, cl kubernetes.Interface) 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 added in v0.16.0

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

GenerateK8sClient create client for kubernetes

func GenerateK8sDynamicClient added in v0.16.0

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, cl kubernetes.Interface) (*policyv1.PodDisruptionBudget, error)

GetPodDisruptionBudget is a method to get PodDisruptionBudgets in Kubernetes

func GetRedisNodesByRole

func GetRedisNodesByRole(ctx context.Context, cl 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, cl kubernetes.Interface) (*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(ctrlclient client.Client, logger logr.Logger, cr *redisv1beta2.RedisSentinel) error

HandleRedisSentinelFinalizer finalize resource if instance is marked to be deleted

func IsRedisReplicationReady added in v0.16.0

func IsRedisReplicationReady(ctx context.Context, logger logr.Logger, ki kubernetes.Interface, di dynamic.Interface, rs *redisv1beta2.RedisSentinel) bool

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, cl kubernetes.Interface) error

CreateRedisLeaderPodDisruptionBudget check and create a PodDisruptionBudget for Leaders

func ReconcileSentinelPodDisruptionBudget added in v0.15.1

func ReconcileSentinelPodDisruptionBudget(cr *redisv1beta2.RedisSentinel, pdbParams *commonapi.RedisPodDisruptionBudget, cl kubernetes.Interface) 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 added in v0.15.1

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

UpdateRedisClusterStatus will update the status of the RedisCluster

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 added in v0.16.0

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

func GenerateK8sConfig added in v0.16.0

func GenerateK8sConfig() K8sConfigProvider

GenerateK8sConfig will load the kube config file

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, cl kubernetes.Interface) 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, cl kubernetes.Interface) 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 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, cl kubernetes.Interface, dcl dynamic.Interface) 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, cl kubernetes.Interface) error

Create the Service for redis sentinel

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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