diff --git a/operator/redisfailover/service/heal.go b/operator/redisfailover/service/heal.go index 934915d9db7cb365e87bc4d3334a0bab0534fdc0..22a3ffd9f38bd6ea05b6ab75585d7993b2371c37 100644 --- a/operator/redisfailover/service/heal.go +++ b/operator/redisfailover/service/heal.go @@ -35,6 +35,7 @@ type RedisFailoverHealer struct { // NewRedisFailoverHealer creates an object of the RedisFailoverChecker struct func NewRedisFailoverHealer(k8sService k8s.Services, redisClient redis.Client, logger log.Logger) *RedisFailoverHealer { + logger = logger.With("service", "redis.healer") return &RedisFailoverHealer{ k8sService: k8sService, redisClient: redisClient, @@ -109,9 +110,9 @@ func (r *RedisFailoverHealer) SetOldestAsMaster(rf *redisfailoverv1.RedisFailove for _, pod := range ssp.Items { if newMasterIP == "" { newMasterIP = pod.Status.PodIP - r.logger.Debugf("New master is %s with ip %s", pod.Name, newMasterIP) + r.logger.WithField("redisfailover", rf.ObjectMeta.Name).WithField("namespace", rf.ObjectMeta.Namespace).Infof("New master is %s with ip %s", pod.Name, newMasterIP) if err := r.redisClient.MakeMaster(newMasterIP, port, password); err != nil { - r.logger.Errorf("Make new master failed, master ip: %s, error: %v", pod.Status.PodIP, err) + r.logger.WithField("redisfailover", rf.ObjectMeta.Name).WithField("namespace", rf.ObjectMeta.Namespace).Errorf("Make new master failed, master ip: %s, error: %v", pod.Status.PodIP, err) continue } @@ -122,9 +123,9 @@ func (r *RedisFailoverHealer) SetOldestAsMaster(rf *redisfailoverv1.RedisFailove newMasterIP = pod.Status.PodIP } else { - r.logger.Debugf("Making pod %s slave of %s", pod.Name, newMasterIP) + r.logger.Infof("Making pod %s slave of %s", pod.Name, newMasterIP) if err := r.redisClient.MakeSlaveOfWithPort(pod.Status.PodIP, newMasterIP, port, password); err != nil { - r.logger.Errorf("Make slave failed, slave pod ip: %s, master ip: %s, error: %v", pod.Status.PodIP, newMasterIP, err) + r.logger.WithField("redisfailover", rf.ObjectMeta.Name).WithField("namespace", rf.ObjectMeta.Namespace).Errorf("Make slave failed, slave pod ip: %s, master ip: %s, error: %v", pod.Status.PodIP, newMasterIP, err) } err = r.setSlaveLabelIfNecessary(rf.Namespace, pod) @@ -151,9 +152,9 @@ func (r *RedisFailoverHealer) SetMasterOnAll(masterIP string, rf *redisfailoverv port := getRedisPort(rf.Spec.Redis.Port) for _, pod := range ssp.Items { if pod.Status.PodIP == masterIP { - r.logger.Debugf("Ensure pod %s is master", pod.Name) + r.logger.WithField("redisfailover", rf.ObjectMeta.Name).WithField("namespace", rf.ObjectMeta.Namespace).Infof("Ensure pod %s is master", pod.Name) if err := r.redisClient.MakeMaster(masterIP, port, password); err != nil { - r.logger.Errorf("Make master failed, master ip: %s, error: %v", masterIP, err) + r.logger.WithField("redisfailover", rf.ObjectMeta.Name).WithField("namespace", rf.ObjectMeta.Namespace).Errorf("Make master failed, master ip: %s, error: %v", masterIP, err) return err } @@ -162,9 +163,9 @@ func (r *RedisFailoverHealer) SetMasterOnAll(masterIP string, rf *redisfailoverv return err } } else { - r.logger.Debugf("Making pod %s slave of %s", pod.Name, masterIP) + r.logger.WithField("redisfailover", rf.ObjectMeta.Name).WithField("namespace", rf.ObjectMeta.Namespace).Infof("Making pod %s slave of %s", pod.Name, masterIP) if err := r.redisClient.MakeSlaveOfWithPort(pod.Status.PodIP, masterIP, port, password); err != nil { - r.logger.Errorf("Make slave failed, slave ip: %s, master ip: %s, error: %v", pod.Status.PodIP, masterIP, err) + r.logger.WithField("redisfailover", rf.ObjectMeta.Name).WithField("namespace", rf.ObjectMeta.Namespace).Errorf("Make slave failed, slave ip: %s, master ip: %s, error: %v", pod.Status.PodIP, masterIP, err) return err } @@ -191,7 +192,7 @@ func (r *RedisFailoverHealer) SetExternalMasterOnAll(masterIP, masterPort string } for _, pod := range ssp.Items { - r.logger.Debugf("Making pod %s slave of %s:%s", pod.Name, masterIP, masterPort) + r.logger.WithField("redisfailover", rf.ObjectMeta.Name).WithField("namespace", rf.ObjectMeta.Namespace).Infof("Making pod %s slave of %s:%s", pod.Name, masterIP, masterPort) if err := r.redisClient.MakeSlaveOfWithPort(pod.Status.PodIP, masterIP, masterPort, password); err != nil { return err } @@ -202,7 +203,7 @@ func (r *RedisFailoverHealer) SetExternalMasterOnAll(masterIP, masterPort string // NewSentinelMonitor changes the master that Sentinel has to monitor func (r *RedisFailoverHealer) NewSentinelMonitor(ip string, monitor string, rf *redisfailoverv1.RedisFailover) error { - r.logger.Debug("Sentinel is not monitoring the correct master, changing...") + r.logger.WithField("redisfailover", rf.ObjectMeta.Name).WithField("namespace", rf.ObjectMeta.Namespace).Infof("Sentinel is not monitoring the correct master, changing...") quorum := strconv.Itoa(int(getQuorum(rf))) password, err := k8s.GetRedisPassword(r.k8sService, rf) @@ -216,7 +217,7 @@ func (r *RedisFailoverHealer) NewSentinelMonitor(ip string, monitor string, rf * // NewSentinelMonitorWithPort changes the master that Sentinel has to monitor by the provided IP and Port func (r *RedisFailoverHealer) NewSentinelMonitorWithPort(ip string, monitor string, monitorPort string, rf *redisfailoverv1.RedisFailover) error { - r.logger.Debug("Sentinel is not monitoring the correct master, changing...") + r.logger.WithField("redisfailover", rf.ObjectMeta.Name).WithField("namespace", rf.ObjectMeta.Namespace).Infof("Sentinel is not monitoring the correct master, changing...") quorum := strconv.Itoa(int(getQuorum(rf))) password, err := k8s.GetRedisPassword(r.k8sService, rf) @@ -229,19 +230,19 @@ func (r *RedisFailoverHealer) NewSentinelMonitorWithPort(ip string, monitor stri // RestoreSentinel clear the number of sentinels on memory func (r *RedisFailoverHealer) RestoreSentinel(ip string) error { - r.logger.Debugf("Restoring sentinel %s...", ip) + r.logger.Infof("Restoring sentinel %s...", ip) return r.redisClient.ResetSentinel(ip) } // SetSentinelCustomConfig will call sentinel to set the configuration given in config func (r *RedisFailoverHealer) SetSentinelCustomConfig(ip string, rf *redisfailoverv1.RedisFailover) error { - r.logger.Debugf("Setting the custom config on sentinel %s...", ip) + r.logger.WithField("redisfailover", rf.ObjectMeta.Name).WithField("namespace", rf.ObjectMeta.Namespace).Infof("Setting the custom config on sentinel %s...", ip) return r.redisClient.SetCustomSentinelConfig(ip, rf.Spec.Sentinel.CustomConfig) } // SetRedisCustomConfig will call redis to set the configuration given in config func (r *RedisFailoverHealer) SetRedisCustomConfig(ip string, rf *redisfailoverv1.RedisFailover) error { - r.logger.Debugf("Setting the custom config on redis %s...", ip) + r.logger.WithField("redisfailover", rf.ObjectMeta.Name).WithField("namespace", rf.ObjectMeta.Namespace).Debugf("Setting the custom config on redis %s...", ip) password, err := k8s.GetRedisPassword(r.k8sService, rf) if err != nil { @@ -252,8 +253,8 @@ func (r *RedisFailoverHealer) SetRedisCustomConfig(ip string, rf *redisfailoverv return r.redisClient.SetCustomRedisConfig(ip, port, rf.Spec.Redis.CustomConfig, password) } -//DeletePod delete a failing pod so kubernetes relaunch it again +// DeletePod delete a failing pod so kubernetes relaunch it again func (r *RedisFailoverHealer) DeletePod(podName string, rFailover *redisfailoverv1.RedisFailover) error { - r.logger.Debugf("Deleting pods %s...", podName) + r.logger.WithField("redisfailover", rFailover.ObjectMeta.Name).WithField("namespace", rFailover.ObjectMeta.Namespace).Infof("Deleting pods %s...", podName) return r.k8sService.DeletePod(rFailover.Namespace, podName) } diff --git a/service/k8s/configmap.go b/service/k8s/configmap.go index 3b9d77a8f4bfb29fb037c83e70a117285122fe45..1b6fc1424a78bb5590e2a37ba17433bb4f40839e 100644 --- a/service/k8s/configmap.go +++ b/service/k8s/configmap.go @@ -54,7 +54,7 @@ func (p *ConfigMapService) CreateConfigMap(namespace string, configMap *corev1.C if err != nil { return err } - p.logger.WithField("namespace", namespace).WithField("configMap", configMap.Name).Infof("configMap created") + p.logger.WithField("namespace", namespace).WithField("configMap", configMap.Name).Debugf("configMap created") return nil } func (p *ConfigMapService) UpdateConfigMap(namespace string, configMap *corev1.ConfigMap) error { @@ -63,7 +63,7 @@ func (p *ConfigMapService) UpdateConfigMap(namespace string, configMap *corev1.C if err != nil { return err } - p.logger.WithField("namespace", namespace).WithField("configMap", configMap.Name).Infof("configMap updated") + p.logger.WithField("namespace", namespace).WithField("configMap", configMap.Name).Debugf("configMap updated") return nil } func (p *ConfigMapService) CreateOrUpdateConfigMap(namespace string, configMap *corev1.ConfigMap) error { diff --git a/service/k8s/deployment.go b/service/k8s/deployment.go index b73cc984f61720795675adfffd07de5727d1648e..46d63bb93c115f80dfeb1bcc013d07f2b84edfd9 100644 --- a/service/k8s/deployment.go +++ b/service/k8s/deployment.go @@ -75,7 +75,7 @@ func (d *DeploymentService) CreateDeployment(namespace string, deployment *appsv if err != nil { return err } - d.logger.WithField("namespace", namespace).WithField("deployment", deployment.ObjectMeta.Name).Infof("deployment created") + d.logger.WithField("namespace", namespace).WithField("deployment", deployment.ObjectMeta.Name).Debugf("deployment created") return err } @@ -86,7 +86,7 @@ func (d *DeploymentService) UpdateDeployment(namespace string, deployment *appsv if err != nil { return err } - d.logger.WithField("namespace", namespace).WithField("deployment", deployment.ObjectMeta.Name).Infof("deployment updated") + d.logger.WithField("namespace", namespace).WithField("deployment", deployment.ObjectMeta.Name).Debugf("deployment updated") return err } diff --git a/service/k8s/pod.go b/service/k8s/pod.go index 5a6f9c8e24741edf8d8f34ab333b5e1d2ec6a797..0583302ce3192f68edd6e0051ff4443f8e3a6faf 100644 --- a/service/k8s/pod.go +++ b/service/k8s/pod.go @@ -58,7 +58,7 @@ func (p *PodService) CreatePod(namespace string, pod *corev1.Pod) error { if err != nil { return err } - p.logger.WithField("namespace", namespace).WithField("pod", pod.Name).Infof("pod created") + p.logger.WithField("namespace", namespace).WithField("pod", pod.Name).Debugf("pod created") return nil } func (p *PodService) UpdatePod(namespace string, pod *corev1.Pod) error { @@ -67,7 +67,7 @@ func (p *PodService) UpdatePod(namespace string, pod *corev1.Pod) error { if err != nil { return err } - p.logger.WithField("namespace", namespace).WithField("pod", pod.Name).Infof("pod updated") + p.logger.WithField("namespace", namespace).WithField("pod", pod.Name).Debugf("pod updated") return nil } func (p *PodService) CreateOrUpdatePod(namespace string, pod *corev1.Pod) error { diff --git a/service/k8s/poddisruptionbudget.go b/service/k8s/poddisruptionbudget.go index df24685dfa9e7f2ed2490cb6848baadf8c226a45..48350bc43ec85395ee62bac6a1f22d2079b5a5a7 100644 --- a/service/k8s/poddisruptionbudget.go +++ b/service/k8s/poddisruptionbudget.go @@ -53,7 +53,7 @@ func (p *PodDisruptionBudgetService) CreatePodDisruptionBudget(namespace string, if err != nil { return err } - p.logger.WithField("namespace", namespace).WithField("podDisruptionBudget", podDisruptionBudget.Name).Infof("podDisruptionBudget created") + p.logger.WithField("namespace", namespace).WithField("podDisruptionBudget", podDisruptionBudget.Name).Debugf("podDisruptionBudget created") return nil } @@ -63,7 +63,7 @@ func (p *PodDisruptionBudgetService) UpdatePodDisruptionBudget(namespace string, if err != nil { return err } - p.logger.WithField("namespace", namespace).WithField("podDisruptionBudget", podDisruptionBudget.Name).Infof("podDisruptionBudget updated") + p.logger.WithField("namespace", namespace).WithField("podDisruptionBudget", podDisruptionBudget.Name).Debugf("podDisruptionBudget updated") return nil } diff --git a/service/k8s/rbac.go b/service/k8s/rbac.go index 2ca90bb7e5f4bcd68706fc0516f5c73da8439fbd..a5534b445c92aca70a832b4bfe58747b8ce8592c 100644 --- a/service/k8s/rbac.go +++ b/service/k8s/rbac.go @@ -66,7 +66,7 @@ func (r *RBACService) DeleteRole(namespace, name string) error { if err != nil { return err } - r.logger.WithField("namespace", namespace).WithField("role", name).Infof("role deleted") + r.logger.WithField("namespace", namespace).WithField("role", name).Debugf("role deleted") return nil } @@ -76,7 +76,7 @@ func (r *RBACService) CreateRole(namespace string, role *rbacv1.Role) error { if err != nil { return err } - r.logger.WithField("namespace", namespace).WithField("role", role.Name).Infof("role created") + r.logger.WithField("namespace", namespace).WithField("role", role.Name).Debugf("role created") return nil } @@ -86,7 +86,7 @@ func (s *RBACService) UpdateRole(namespace string, role *rbacv1.Role) error { if err != nil { return err } - s.logger.WithField("namespace", namespace).WithField("role", role.ObjectMeta.Name).Infof("role updated") + s.logger.WithField("namespace", namespace).WithField("role", role.ObjectMeta.Name).Debugf("role updated") return err } @@ -114,7 +114,7 @@ func (r *RBACService) DeleteRoleBinding(namespace, name string) error { if err != nil { return err } - r.logger.WithField("namespace", namespace).WithField("binding", name).Infof("role binding deleted") + r.logger.WithField("namespace", namespace).WithField("binding", name).Debugf("role binding deleted") return nil } @@ -124,7 +124,7 @@ func (r *RBACService) CreateRoleBinding(namespace string, binding *rbacv1.RoleBi if err != nil { return err } - r.logger.WithField("namespace", namespace).WithField("binding", binding.Name).Infof("role binding created") + r.logger.WithField("namespace", namespace).WithField("binding", binding.Name).Debugf("role binding created") return nil } @@ -134,7 +134,7 @@ func (r *RBACService) UpdateRoleBinding(namespace string, binding *rbacv1.RoleBi if err != nil { return err } - r.logger.WithField("namespace", namespace).WithField("binding", binding.Name).Infof("role binding updated") + r.logger.WithField("namespace", namespace).WithField("binding", binding.Name).Debugf("role binding updated") return nil } diff --git a/service/k8s/service.go b/service/k8s/service.go index d907b9f85dd39a79aa16b31d06a12799c0c878db..8cd49ed47d4f3d4936e255b1df008dabaad3cb6f 100644 --- a/service/k8s/service.go +++ b/service/k8s/service.go @@ -56,7 +56,7 @@ func (s *ServiceService) CreateService(namespace string, service *corev1.Service if err != nil { return err } - s.logger.WithField("namespace", namespace).WithField("serviceName", service.Name).Infof("service created") + s.logger.WithField("namespace", namespace).WithField("serviceName", service.Name).Debugf("service created") return nil } @@ -77,7 +77,7 @@ func (s *ServiceService) UpdateService(namespace string, service *corev1.Service if err != nil { return err } - s.logger.WithField("namespace", namespace).WithField("serviceName", service.Name).Infof("service updated") + s.logger.WithField("namespace", namespace).WithField("serviceName", service.Name).Debugf("service updated") return nil } func (s *ServiceService) CreateOrUpdateService(namespace string, service *corev1.Service) error { diff --git a/service/k8s/statefulset.go b/service/k8s/statefulset.go index 8de666ba4a42bf40a624aaafc262219296765893..2eebc52c81a58ff8ebad085c52b62c13a9290ed9 100644 --- a/service/k8s/statefulset.go +++ b/service/k8s/statefulset.go @@ -76,7 +76,7 @@ func (s *StatefulSetService) CreateStatefulSet(namespace string, statefulSet *ap if err != nil { return err } - s.logger.WithField("namespace", namespace).WithField("statefulSet", statefulSet.ObjectMeta.Name).Infof("statefulSet created") + s.logger.WithField("namespace", namespace).WithField("statefulSet", statefulSet.ObjectMeta.Name).Debugf("statefulSet created") return err } @@ -87,7 +87,7 @@ func (s *StatefulSetService) UpdateStatefulSet(namespace string, statefulSet *ap if err != nil { return err } - s.logger.WithField("namespace", namespace).WithField("statefulSet", statefulSet.ObjectMeta.Name).Infof("statefulSet updated") + s.logger.WithField("namespace", namespace).WithField("statefulSet", statefulSet.ObjectMeta.Name).Debugf("statefulSet updated") return err }