Skip to content

Commit

Permalink
Use same logger throughout the codebase
Browse files Browse the repository at this point in the history
Signed-off-by: Vince Prignano <[email protected]>
  • Loading branch information
vincepri committed Aug 13, 2019
1 parent dc6e6a4 commit e62c4a5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 24 deletions.
11 changes: 8 additions & 3 deletions api/v1alpha2/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import (

"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/klog"
"k8s.io/klog/klogr"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

// These tests use Ginkgo (BDD-style Go testing framework). Refer to
Expand All @@ -38,6 +39,12 @@ var cfg *rest.Config
var k8sClient client.Client
var testEnv *envtest.Environment

func init() {
klog.InitFlags(nil)
klog.SetOutput(GinkgoWriter)
logf.SetLogger(klogr.New())
}

func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)

Expand All @@ -47,8 +54,6 @@ func TestAPIs(t *testing.T) {
}

var _ = BeforeSuite(func(done Done) {
logf.SetLogger(zap.LoggerTo(GinkgoWriter, true))

By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
Expand Down
6 changes: 3 additions & 3 deletions controllers/control_plane_init_locker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestControlPlaneInitLockerAcquire(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
l := &controlPlaneInitLocker{
log: log.ZapLogger(true),
log: log.Log,
configMapClient: &configMapsGetter{
getError: tc.getError,
},
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestControlPlaneInitLockerAcquireErrors(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
l := &controlPlaneInitLocker{
log: log.ZapLogger(true),
log: log.Log,
configMapClient: &configMapsGetter{
configMap: tc.configMap,
getError: tc.getError,
Expand Down Expand Up @@ -152,7 +152,7 @@ func TestControlPlaneInitLockerRelease(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
l := &controlPlaneInitLocker{
log: log.ZapLogger(true),
log: log.Log,
configMapClient: &configMapsGetter{
configMap: tc.configMap,
getError: tc.getError,
Expand Down
4 changes: 2 additions & 2 deletions controllers/kubeadmconfig_controller_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var _ = Describe("KubeadmConfigReconciler", func() {
Expect(k8sClient.Create(context.Background(), config)).To(Succeed())

reconciler := KubeadmConfigReconciler{
Log: log.ZapLogger(true),
Log: log.Log,
Client: k8sClient,
}
By("Calling reconcile should requeue")
Expand Down Expand Up @@ -91,7 +91,7 @@ var _ = Describe("KubeadmConfigReconciler", func() {
Expect(k8sClient.Create(context.Background(), workerConfig)).To(Succeed())
reconciler := KubeadmConfigReconciler{
Log: log.ZapLogger(true),
Log: log.Log,
Client: k8sClient,
}
Expand Down
26 changes: 13 additions & 13 deletions controllers/kubeadmconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestBailIfKubeadmConfigStatusReady(t *testing.T) {
myclient := fake.NewFakeClientWithScheme(setupScheme(), objects...)

k := &KubeadmConfigReconciler{
Log: log.ZapLogger(true),
Log: log.Log,
Client: myclient,
}

Expand Down Expand Up @@ -82,7 +82,7 @@ func TestRequeueIfNoMachineRefIsSet(t *testing.T) {
myclient := fake.NewFakeClientWithScheme(setupScheme(), objects...)

k := &KubeadmConfigReconciler{
Log: log.ZapLogger(true),
Log: log.Log,
Client: myclient,
}

Expand Down Expand Up @@ -115,7 +115,7 @@ func TestFailsIfMachineRefIsNotFound(t *testing.T) {
myclient := fake.NewFakeClientWithScheme(setupScheme(), objects...)

k := &KubeadmConfigReconciler{
Log: log.ZapLogger(true),
Log: log.Log,
Client: myclient,
}

Expand Down Expand Up @@ -143,7 +143,7 @@ func TestBailIfMachineAlreadyHasBootstrapData(t *testing.T) {
myclient := fake.NewFakeClientWithScheme(setupScheme(), objects...)

k := &KubeadmConfigReconciler{
Log: log.ZapLogger(true),
Log: log.Log,
Client: myclient,
}

Expand Down Expand Up @@ -176,7 +176,7 @@ func TestFailsNoClusterRefIsSet(t *testing.T) {
myclient := fake.NewFakeClientWithScheme(setupScheme(), objects...)

k := &KubeadmConfigReconciler{
Log: log.ZapLogger(true),
Log: log.Log,
Client: myclient,
}

Expand Down Expand Up @@ -205,7 +205,7 @@ func TestFailsIfClusterIsNotFound(t *testing.T) {
myclient := fake.NewFakeClientWithScheme(setupScheme(), objects...)

k := &KubeadmConfigReconciler{
Log: log.ZapLogger(true),
Log: log.Log,
Client: myclient,
}

Expand Down Expand Up @@ -236,7 +236,7 @@ func TestRequeueIfInfrastructureIsNotReady(t *testing.T) {
myclient := fake.NewFakeClientWithScheme(setupScheme(), objects...)

k := &KubeadmConfigReconciler{
Log: log.ZapLogger(true),
Log: log.Log,
Client: myclient,
}

Expand Down Expand Up @@ -280,7 +280,7 @@ func TestRequeueKubeadmConfigForJoinNodesIfControlPlaneIsNotReady(t *testing.T)
myclient := fake.NewFakeClientWithScheme(setupScheme(), objects...)

k := &KubeadmConfigReconciler{
Log: log.ZapLogger(true),
Log: log.Log,
Client: myclient,
}

Expand Down Expand Up @@ -334,7 +334,7 @@ func TestReconcileKubeadmConfigForInitNodesIfControlPlaneIsNotReady(t *testing.T
myclient := fake.NewFakeClientWithScheme(setupScheme(), objects...)

k := &KubeadmConfigReconciler{
Log: log.ZapLogger(true),
Log: log.Log,
Client: myclient,
}

Expand Down Expand Up @@ -388,7 +388,7 @@ func TestFailIfNotJoinConfigurationAndControlPlaneIsReady(t *testing.T) {
myclient := fake.NewFakeClientWithScheme(setupScheme(), objects...)

k := &KubeadmConfigReconciler{
Log: log.ZapLogger(true),
Log: log.Log,
Client: myclient,
}

Expand Down Expand Up @@ -421,7 +421,7 @@ func TestFailIfJoinConfigurationInconsistentWithMachineRole(t *testing.T) {
myclient := fake.NewFakeClientWithScheme(setupScheme(), objects...)

k := &KubeadmConfigReconciler{
Log: log.ZapLogger(true),
Log: log.Log,
Client: myclient,
}

Expand Down Expand Up @@ -453,7 +453,7 @@ func TestFailIfMissingControlPaneEndpointAndControlPlaneIsReady(t *testing.T) {
myclient := fake.NewFakeClientWithScheme(setupScheme(), objects...)

k := &KubeadmConfigReconciler{
Log: log.ZapLogger(true),
Log: log.Log,
Client: myclient,
}

Expand Down Expand Up @@ -491,7 +491,7 @@ func TestReconcileIfJoinNodesAndControlPlaneIsReady(t *testing.T) {
myclient := fake.NewFakeClientWithScheme(setupScheme(), objects...)

k := &KubeadmConfigReconciler{
Log: log.ZapLogger(true),
Log: log.Log,
Client: myclient,
}

Expand Down
11 changes: 8 additions & 3 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import (
. "github.com/onsi/gomega"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/klog"
"k8s.io/klog/klogr"
kubeadmv1alpha2 "sigs.k8s.io/cluster-api-bootstrap-provider-kubeadm/api/v1alpha2"
"sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha2"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
// +kubebuilder:scaffold:imports
)

Expand All @@ -40,6 +41,12 @@ var cfg *rest.Config
var k8sClient client.Client
var testEnv *envtest.Environment

func init() {
klog.InitFlags(nil)
klog.SetOutput(GinkgoWriter)
logf.SetLogger(klogr.New())
}

func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)

Expand All @@ -49,8 +56,6 @@ func TestAPIs(t *testing.T) {
}

var _ = BeforeSuite(func(done Done) {
logf.SetLogger(zap.LoggerTo(GinkgoWriter, true))

By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{
Expand Down

0 comments on commit e62c4a5

Please sign in to comment.