Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.

Commit

Permalink
use logr instead of fmt printfs
Browse files Browse the repository at this point in the history
  • Loading branch information
ashish-amarnath committed Jul 3, 2019
1 parent 3aa185e commit 603fffb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions actuators/actuators.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"io/ioutil"

"github.com/go-logr/logr"
"github.com/pkg/errors"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -43,8 +44,8 @@ func getRole(machine *clusterv1.Machine) string {
return setValue
}

func getExternalLoadBalancerNode(clusterName string) (*nodes.Node, error) {
fmt.Printf("Getting external load balancer node for cluster %q\n", clusterName)
func getExternalLoadBalancerNode(clusterName string, log logr.Logger) (*nodes.Node, error) {
log.Info("Getting external load balancer node for cluster", "cluster-name", clusterName)
elb, err := nodes.List(
fmt.Sprintf("label=%s=%s", constants.NodeRoleKey, constants.ExternalLoadBalancerNodeRoleValue),
fmt.Sprintf("label=%s=%s", constants.ClusterLabelKey, clusterName),
Expand All @@ -59,7 +60,7 @@ func getExternalLoadBalancerNode(clusterName string) (*nodes.Node, error) {
if len(elb) > 1 {
return nil, errors.New("too many external load balancers")
}
fmt.Printf("External loadbalancer node for cluster %q is %v\n", clusterName, elb[0])
log.Info("External loadbalancer node for cluster", "cluster-name", clusterName, "elb", elb[0])
return &elb[0], nil
}

Expand Down
4 changes: 2 additions & 2 deletions actuators/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type Cluster struct {

// Reconcile setups an external load balancer for the cluster if needed
func (c *Cluster) Reconcile(cluster *clusterv1.Cluster) error {
fmt.Printf("Reconciling cluster %s/%s\n", cluster.Namespace, cluster.Name)
elb, err := getExternalLoadBalancerNode(cluster.Name)
c.Log.Info("Reconciling cluster", "cluster-namespace", cluster.Namespace, "cluster-name", cluster.Name)
elb, err := getExternalLoadBalancerNode(cluster.Name, c.Log)
if err != nil {
c.Log.Error(err, "Error getting external load balancer node")
return err
Expand Down
2 changes: 1 addition & 1 deletion actuators/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (m *Machine) Create(ctx context.Context, c *clusterv1.Cluster, machine *clu
}

m.Log.Info("Creating a brand new cluster")
elb, err := getExternalLoadBalancerNode(c.Name)
elb, err := getExternalLoadBalancerNode(c.Name, m.Log)
if err != nil {
m.Log.Error(err, "Error getting external load balancer node")
return err
Expand Down

0 comments on commit 603fffb

Please sign in to comment.