Skip to content

Commit

Permalink
proper names for constants; some clean up for log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mkabilov committed Jul 24, 2017
1 parent 2161a08 commit d7e9142
Show file tree
Hide file tree
Showing 22 changed files with 122 additions and 122 deletions.
6 changes: 3 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ func init() {
func ControllerConfig() *controller.Config {
restConfig, err := k8sutil.RestConfig(KubeConfigFile, OutOfCluster)
if err != nil {
log.Fatalf("Can't get REST config: %s", err)
log.Fatalf("Can't get REST config: %v", err)
}

client, err := k8sutil.KubernetesClient(restConfig)
if err != nil {
log.Fatalf("Can't create client: %s", err)
log.Fatalf("Can't create client: %v", err)
}

restClient, err := k8sutil.KubernetesRestClient(restConfig)
if err != nil {
log.Fatalf("Can't create rest client: %s", err)
log.Fatalf("Can't create rest client: %v", err)
}

return &controller.Config{
Expand Down
32 changes: 16 additions & 16 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (c *Cluster) setStatus(status spec.PostgresStatus) {
}

if err != nil {
c.logger.Warningf("could not set status for cluster '%s': %s", c.clusterName(), err)
c.logger.Warningf("could not set status for cluster %q: %v", c.clusterName(), err)
}
}

Expand Down Expand Up @@ -180,7 +180,7 @@ func (c *Cluster) Create() error {
if err != nil {
return fmt.Errorf("could not create endpoint: %v", err)
}
c.logger.Infof("endpoint '%s' has been successfully created", util.NameFromMeta(ep.ObjectMeta))
c.logger.Infof("endpoint %q has been successfully created", util.NameFromMeta(ep.ObjectMeta))

for _, role := range []PostgresRole{Master, Replica} {
if role == Replica && !c.Spec.ReplicaLoadBalancer {
Expand All @@ -190,7 +190,7 @@ func (c *Cluster) Create() error {
if err != nil {
return fmt.Errorf("could not create %s service: %v", role, err)
}
c.logger.Infof("%s service '%s' has been successfully created", role, util.NameFromMeta(service.ObjectMeta))
c.logger.Infof("%s service %q has been successfully created", role, util.NameFromMeta(service.ObjectMeta))
}

if err = c.initUsers(); err != nil {
Expand All @@ -207,12 +207,12 @@ func (c *Cluster) Create() error {
if err != nil {
return fmt.Errorf("could not create statefulset: %v", err)
}
c.logger.Infof("statefulset '%s' has been successfully created", util.NameFromMeta(ss.ObjectMeta))
c.logger.Infof("statefulset %q has been successfully created", util.NameFromMeta(ss.ObjectMeta))

c.logger.Info("Waiting for cluster being ready")

if err = c.waitStatefulsetPodsReady(); err != nil {
c.logger.Errorf("Failed to create cluster: %s", err)
c.logger.Errorf("Failed to create cluster: %v", err)
return err
}
c.logger.Infof("pods are ready")
Expand All @@ -233,7 +233,7 @@ func (c *Cluster) Create() error {

err = c.listResources()
if err != nil {
c.logger.Errorf("could not list resources: %s", err)
c.logger.Errorf("could not list resources: %v", err)
}

return nil
Expand All @@ -243,7 +243,7 @@ func (c *Cluster) sameServiceWith(role PostgresRole, service *v1.Service) (match
//TODO: improve comparison
match = true
if c.Service[role].Spec.Type != service.Spec.Type {
return false, fmt.Sprintf("new %s service's type %s doesn't match the current one %s",
return false, fmt.Sprintf("new %s service's type %q doesn't match the current one %q",
role, service.Spec.Type, c.Service[role].Spec.Type)
}
oldSourceRanges := c.Service[role].Spec.LoadBalancerSourceRanges
Expand All @@ -259,7 +259,7 @@ func (c *Cluster) sameServiceWith(role PostgresRole, service *v1.Service) (match
oldDNSAnnotation := c.Service[role].Annotations[constants.ZalandoDNSNameAnnotation]
newDNSAnnotation := service.Annotations[constants.ZalandoDNSNameAnnotation]
if oldDNSAnnotation != newDNSAnnotation {
return false, fmt.Sprintf("new %s service's '%s' annotation doesn't match the current one", role, constants.ZalandoDNSNameAnnotation)
return false, fmt.Sprintf("new %s service's %q annotation doesn't match the current one", role, constants.ZalandoDNSNameAnnotation)
}

return true, ""
Expand Down Expand Up @@ -290,7 +290,7 @@ func (c *Cluster) compareStatefulSetWith(statefulSet *v1beta1.StatefulSet) *comp
}
if len(c.Statefulset.Spec.Template.Spec.Containers) == 0 {

c.logger.Warnf("statefulset '%s' has no container", util.NameFromMeta(c.Statefulset.ObjectMeta))
c.logger.Warnf("statefulset %q has no container", util.NameFromMeta(c.Statefulset.ObjectMeta))
return &compareStatefulsetResult{}
}
// In the comparisons below, the needsReplace and needsRollUpdate flags are never reset, since checks fall through
Expand Down Expand Up @@ -333,12 +333,12 @@ func (c *Cluster) compareStatefulSetWith(statefulSet *v1beta1.StatefulSet) *comp
}
if !reflect.DeepEqual(c.Statefulset.Spec.VolumeClaimTemplates[i].Annotations, statefulSet.Spec.VolumeClaimTemplates[i].Annotations) {
needsReplace = true
reasons = append(reasons, fmt.Sprintf("new statefulset's annotations for volume %s doesn't match the current one", name))
reasons = append(reasons, fmt.Sprintf("new statefulset's annotations for volume %q doesn't match the current one", name))
}
if !reflect.DeepEqual(c.Statefulset.Spec.VolumeClaimTemplates[i].Spec, statefulSet.Spec.VolumeClaimTemplates[i].Spec) {
name := c.Statefulset.Spec.VolumeClaimTemplates[i].Name
needsReplace = true
reasons = append(reasons, fmt.Sprintf("new statefulset's volumeClaimTemplates specification for volume %s doesn't match the current one", name))
reasons = append(reasons, fmt.Sprintf("new statefulset's volumeClaimTemplates specification for volume %q doesn't match the current one", name))
}
}

Expand Down Expand Up @@ -405,7 +405,7 @@ func (c *Cluster) Update(newSpec *spec.Postgresql) error {
defer c.mu.Unlock()

c.setStatus(spec.ClusterStatusUpdating)
c.logger.Debugf("Cluster update from version %s to %s",
c.logger.Debugf("Cluster update from version %q to %q",
c.Metadata.ResourceVersion, newSpec.Metadata.ResourceVersion)

/* Make sure we update when this function exists */
Expand All @@ -431,7 +431,7 @@ func (c *Cluster) Update(newSpec *spec.Postgresql) error {
if err != nil {
return fmt.Errorf("could not create new %s service: %v", role, err)
}
c.logger.Infof("%s service '%s' has been created", role, util.NameFromMeta(service.ObjectMeta))
c.logger.Infof("%s service %q has been created", role, util.NameFromMeta(service.ObjectMeta))
}
}
// only proceed further if both old and new load balancer were present
Expand All @@ -446,7 +446,7 @@ func (c *Cluster) Update(newSpec *spec.Postgresql) error {
c.setStatus(spec.ClusterStatusUpdateFailed)
return fmt.Errorf("could not update %s service: %v", role, err)
}
c.logger.Infof("%s service '%s' has been updated", role, util.NameFromMeta(c.Service[role].ObjectMeta))
c.logger.Infof("%s service %q has been updated", role, util.NameFromMeta(c.Service[role].ObjectMeta))
}
}

Expand All @@ -471,11 +471,11 @@ func (c *Cluster) Update(newSpec *spec.Postgresql) error {
}
}
//TODO: if there is a change in numberOfInstances, make sure Pods have been created/deleted
c.logger.Infof("statefulset '%s' has been updated", util.NameFromMeta(c.Statefulset.ObjectMeta))
c.logger.Infof("statefulset %q has been updated", util.NameFromMeta(c.Statefulset.ObjectMeta))
}

if c.Spec.PgVersion != newSpec.Spec.PgVersion { // PG versions comparison
c.logger.Warnf("Postgresql version change(%s -> %s) is not allowed",
c.logger.Warnf("Postgresql version change(%q -> %q) is not allowed",
c.Spec.PgVersion, newSpec.Spec.PgVersion)
//TODO: rewrite pg version in tpr spec
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/filesystems.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ func (c *Cluster) resizePostgresFilesystem(podName *spec.NamespacedName, resizer

return err
}
return fmt.Errorf("could not resize filesystem: no compatible resizers for the filesystem of type %s", fsType)
return fmt.Errorf("could not resize filesystem: no compatible resizers for the filesystem of type %q", fsType)
}
2 changes: 1 addition & 1 deletion pkg/cluster/k8sres.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ PATRONI_INITDB_PARAMS:
}
result, err := json.Marshal(config)
if err != nil {
c.logger.Errorf("Cannot convert spilo configuration into JSON: %s", err)
c.logger.Errorf("Cannot convert spilo configuration into JSON: %v", err)
return ""
}
return string(result)
Expand Down
14 changes: 7 additions & 7 deletions pkg/cluster/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ func (c *Cluster) deletePods() error {
for _, obj := range pods {
podName := util.NameFromMeta(obj.ObjectMeta)

c.logger.Debugf("Deleting pod '%s'", podName)
c.logger.Debugf("Deleting pod %q", podName)
if err := c.deletePod(podName); err != nil {
c.logger.Errorf("could not delete pod '%s': %s", podName, err)
c.logger.Errorf("could not delete pod %q: %v", podName, err)
} else {
c.logger.Infof("pod '%s' has been deleted", podName)
c.logger.Infof("pod %q has been deleted", podName)
}
}
if len(pods) > 0 {
Expand Down Expand Up @@ -107,7 +107,7 @@ func (c *Cluster) recreatePod(pod v1.Pod) error {
if err := c.waitForPodLabel(ch); err != nil {
return err
}
c.logger.Infof("pod '%s' is ready", podName)
c.logger.Infof("pod %q is ready", podName)

return nil
}
Expand Down Expand Up @@ -136,18 +136,18 @@ func (c *Cluster) recreatePods() error {
}

if err := c.recreatePod(pod); err != nil {
return fmt.Errorf("could not recreate replica pod '%s': %v", util.NameFromMeta(pod.ObjectMeta), err)
return fmt.Errorf("could not recreate replica pod %q: %v", util.NameFromMeta(pod.ObjectMeta), err)
}
}
if masterPod.Name == "" {
c.logger.Warningln("No master pod in the cluster")
} else {
//TODO: do manual failover
//TODO: specify master, leave new master empty
c.logger.Infof("Recreating master pod '%s'", util.NameFromMeta(masterPod.ObjectMeta))
c.logger.Infof("Recreating master pod %q", util.NameFromMeta(masterPod.ObjectMeta))

if err := c.recreatePod(masterPod); err != nil {
return fmt.Errorf("could not recreate master pod '%s': %v", util.NameFromMeta(masterPod.ObjectMeta), err)
return fmt.Errorf("could not recreate master pod %q: %v", util.NameFromMeta(masterPod.ObjectMeta), err)
}
}

Expand Down

0 comments on commit d7e9142

Please sign in to comment.