Skip to content

Commit

Permalink
remove duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffoo committed Oct 2, 2019
1 parent 7651cfc commit b16c133
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions operator/redisfailover/service/client.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package service

import (
"fmt"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"

Expand Down Expand Up @@ -57,7 +54,7 @@ func (r *RedisFailoverKubeClient) EnsureSentinelService(rf *redisfailoverv1.Redi
// EnsureSentinelConfigMap makes sure the sentinel configmap exists
func (r *RedisFailoverKubeClient) EnsureSentinelConfigMap(rf *redisfailoverv1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error {

password, err := r.getRedisAuth(rf)
password, err := k8s.GetRedisPassword(r.K8SService, rf)
if err != nil {
return err
}
Expand Down Expand Up @@ -87,7 +84,7 @@ func (r *RedisFailoverKubeClient) EnsureRedisStatefulset(rf *redisfailoverv1.Red
// EnsureRedisConfigMap makes sure the sentinel configmap exists
func (r *RedisFailoverKubeClient) EnsureRedisConfigMap(rf *redisfailoverv1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) error {

password, err := r.getRedisAuth(rf)
password, err := k8s.GetRedisPassword(r.K8SService, rf)
if err != nil {
return err
}
Expand Down Expand Up @@ -126,26 +123,6 @@ func (r *RedisFailoverKubeClient) EnsureNotPresentRedisService(rf *redisfailover
return nil
}

// getRedisAuth returns the password as a string, if specified in the Spec
func (r *RedisFailoverKubeClient) getRedisAuth(rf *redisfailoverv1.RedisFailover) (password string, err error) {

if rf.Spec.Auth.SecretPath != "" {
var s *corev1.Secret
s, err = r.K8SService.GetSecret(rf.Namespace, rf.Spec.Auth.SecretPath)
if err != nil {
return
}

if p, ok := s.Data["password"]; ok {
password = string(p)
} else {
err = fmt.Errorf("secret \"%s\" does not have a password field", rf.Spec.Auth.SecretPath)
}
}

return
}

// 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 b16c133

Please sign in to comment.