reflect code review

This commit is contained in:
Felix Kunde 2022-03-24 10:35:40 +01:00
parent af4e8e71ae
commit 80d4eb3c0d
1 changed files with 6 additions and 15 deletions

View File

@ -723,16 +723,14 @@ func (c *Cluster) enforceMinResourceLimits(spec *acidv1.PostgresSpec) error {
} }
func (c *Cluster) compareAnnotations(old, new map[string]string) (bool, string) { func (c *Cluster) compareAnnotations(old, new map[string]string) (bool, string) {
ignored := make(map[string]bool) reason := ""
ignoredAnnotations := make(map[string]bool)
for _, ignore := range c.OpConfig.IgnoredAnnotations { for _, ignore := range c.OpConfig.IgnoredAnnotations {
ignored[ignore] = true ignoredAnnotations[ignore] = true
} }
// changed := false
reason := ""
for key := range old { for key := range old {
if _, ok := ignored[key]; ok { if _, ok := ignoredAnnotations[key]; ok {
continue continue
} }
if _, ok := new[key]; !ok { if _, ok := new[key]; !ok {
@ -741,10 +739,9 @@ func (c *Cluster) compareAnnotations(old, new map[string]string) (bool, string)
} }
for key := range new { for key := range new {
if _, ok := ignored[key]; ok { if _, ok := ignoredAnnotations[key]; ok {
continue continue
} }
v, ok := old[key] v, ok := old[key]
if !ok { if !ok {
reason += fmt.Sprintf(" Added '%s' with value '%s'.", key, new[key]) reason += fmt.Sprintf(" Added '%s' with value '%s'.", key, new[key])
@ -753,16 +750,11 @@ func (c *Cluster) compareAnnotations(old, new map[string]string) (bool, string)
} }
} }
if reason != "" { return reason != "", reason
return true, reason
}
return false, ""
} }
// SameService compares the Services
func (c *Cluster) compareServices(old, new *v1.Service) (bool, string) { func (c *Cluster) compareServices(old, new *v1.Service) (bool, string) {
//TODO: improve comparison
if old.Spec.Type != new.Spec.Type { if old.Spec.Type != new.Spec.Type {
return false, fmt.Sprintf("new service's type %q does not match the current one %q", return false, fmt.Sprintf("new service's type %q does not match the current one %q",
new.Spec.Type, old.Spec.Type) new.Spec.Type, old.Spec.Type)
@ -783,7 +775,6 @@ func (c *Cluster) compareServices(old, new *v1.Service) (bool, string) {
} }
return true, "" return true, ""
} }
// Update changes Kubernetes objects according to the new specification. Unlike the sync case, the missing object // Update changes Kubernetes objects according to the new specification. Unlike the sync case, the missing object