Skip to content

Commit

Permalink
Add ensurers for master and slave services
Browse files Browse the repository at this point in the history
  • Loading branch information
hashemi-soroush committed Jun 22, 2023
1 parent 93e9507 commit 99f232d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions operator/redisfailover/ensurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
20 changes: 20 additions & 0 deletions operator/redisfailover/service/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 99f232d

Please sign in to comment.