From 99f232d341a5ee19fe3e9f4a6477ca84418973aa Mon Sep 17 00:00:00 2001 From: Seyed Soroush Hashemi Date: Thu, 22 Jun 2023 20:08:21 +0330 Subject: [PATCH] Add ensurers for master and slave services --- operator/redisfailover/ensurer.go | 8 ++++++++ operator/redisfailover/service/client.go | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/operator/redisfailover/ensurer.go b/operator/redisfailover/ensurer.go index 23b609417..388e25f58 100644 --- a/operator/redisfailover/ensurer.go +++ b/operator/redisfailover/ensurer.go @@ -29,6 +29,14 @@ func (w *RedisFailoverHandler) Ensure(rf *redisfailoverv1.RedisFailover, labels } } + if err := w.rfService.EnsureRedisMasterService(rf, labels, or); err != nil { + return err + } + + if err := w.rfService.EnsureRedisSlaveService(rf, labels, or); err != nil { + return err + } + if err := w.rfService.EnsureRedisShutdownConfigMap(rf, labels, or); err != nil { return err } diff --git a/operator/redisfailover/service/client.go b/operator/redisfailover/service/client.go index 22c8d60ea..d97e964a1 100644 --- a/operator/redisfailover/service/client.go +++ b/operator/redisfailover/service/client.go @@ -19,6 +19,8 @@ type RedisFailoverClient interface { EnsureSentinelDeployment(rFailover *redisfailoverv1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error EnsureRedisStatefulset(rFailover *redisfailoverv1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error EnsureRedisService(rFailover *redisfailoverv1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error + EnsureRedisMasterService(rFailover *redisfailoverv1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error + EnsureRedisSlaveService(rFailover *redisfailoverv1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error EnsureRedisShutdownConfigMap(rFailover *redisfailoverv1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error EnsureRedisReadinessConfigMap(rFailover *redisfailoverv1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error EnsureRedisConfigMap(rFailover *redisfailoverv1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error @@ -163,6 +165,24 @@ func (r *RedisFailoverKubeClient) EnsureNotPresentRedisService(rf *redisfailover return nil } +// EnsureRedisMasterService makes sure the redis master service exists +func (r *RedisFailoverKubeClient) EnsureRedisMasterService(rf *redisfailoverv1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error { + svc := generateRedisMasterService(rf, labels, ownerRefs) + err := r.K8SService.CreateOrUpdateService(rf.Namespace, svc) + + r.setEnsureOperationMetrics(svc.Namespace, svc.Name, "Service", rf.Name, err) + return err +} + +// EnsureRedisSlaveService makes sure the redis slave service exists +func (r *RedisFailoverKubeClient) EnsureRedisSlaveService(rf *redisfailoverv1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error { + svc := generateRedisSlaveService(rf, labels, ownerRefs) + err := r.K8SService.CreateOrUpdateService(rf.Namespace, svc) + + r.setEnsureOperationMetrics(svc.Namespace, svc.Name, "Service", rf.Name, err) + return err +} + // EnsureRedisStatefulset makes sure the pdb exists in the desired state func (r *RedisFailoverKubeClient) ensurePodDisruptionBudget(rf *redisfailoverv1.RedisFailover, name string, component string, labels map[string]string, ownerRefs []metav1.OwnerReference) error { name = generateName(name, rf.Name)