Skip to content

Commit afbe602

Browse files
committed
code optimizations
1 parent 4590560 commit afbe602

4 files changed

Lines changed: 6 additions & 6 deletions

File tree

pkg/cluster/cluster.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2071,7 +2071,9 @@ func (c *Cluster) getPasswordForUser(username string) (string, error) {
20712071
}
20722072
c.multisiteClient = client
20732073
}
2074-
reqTimeoutCtx, _ := context.WithTimeout(context.TODO(), time.Duration(2)*time.Second)
2074+
reqTimeoutCtx, cancel := context.WithTimeout(context.TODO(), time.Duration(2)*time.Second)
2075+
defer cancel()
2076+
20752077
credentialsKey := fmt.Sprintf("/multisite/%s/%s/credentials/%s", c.Namespace, c.Name, username)
20762078
response, err := c.multisiteClient.Get(reqTimeoutCtx, credentialsKey)
20772079
if err != nil {

pkg/cluster/k8sres.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2132,7 +2132,7 @@ func (c *Cluster) generatePodAnnotations(spec *cpov1.PostgresSpec) map[string]st
21322132
for k, v := range c.OpConfig.CustomPodAnnotations {
21332133
annotations[k] = v
21342134
}
2135-
if spec != nil || spec.PodAnnotations != nil {
2135+
if spec != nil && spec.PodAnnotations != nil {
21362136
for k, v := range spec.PodAnnotations {
21372137
annotations[k] = v
21382138
}

pkg/cluster/sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ func (c *Cluster) updateSecret(
11081108
}
11091109

11101110
if updateSecret {
1111-
c.logger.Debugln("%s", updateSecretMsg)
1111+
c.logger.Debugf("%s", updateSecretMsg)
11121112
if _, err = c.KubeClient.Secrets(secret.Namespace).Update(context.TODO(), secret, metav1.UpdateOptions{}); err != nil {
11131113
return fmt.Errorf("could not update secret %s: %v", secretName, err)
11141114
}

pkg/cluster/util.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func logNiceDiff(log *logrus.Entry, old, new interface{}) {
205205
nice := nicediff.Diff(string(o), string(n), true)
206206
for _, s := range strings.Split(nice, "\n") {
207207
// " is not needed in the value to understand
208-
log.Debugf(strings.ReplaceAll(s, "\"", ""))
208+
log.Debugf("%s", strings.ReplaceAll(s, "\"", ""))
209209
}
210210
}
211211

@@ -512,8 +512,6 @@ func (c *Cluster) waitForPrimaryLoadBalancerIp() error {
512512
}
513513
return len(svc.Status.LoadBalancer.Ingress) > 0, nil
514514
})
515-
516-
return nil
517515
}
518516

519517
func (c *Cluster) getPrimaryLoadBalancerIp() (string, error) {

0 commit comments

Comments
 (0)