diff --git a/api/v1alpha2/suite_test.go b/api/v1alpha2/suite_test.go index a7c790100ab6..231881b6bc17 100644 --- a/api/v1alpha2/suite_test.go +++ b/api/v1alpha2/suite_test.go @@ -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 @@ -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) @@ -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")}, diff --git a/controllers/control_plane_init_locker_test.go b/controllers/control_plane_init_locker_test.go index 81e8e19fa9d2..8420072c15fe 100644 --- a/controllers/control_plane_init_locker_test.go +++ b/controllers/control_plane_init_locker_test.go @@ -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, }, @@ -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, @@ -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, diff --git a/controllers/kubeadmconfig_controller_reconciler_test.go b/controllers/kubeadmconfig_controller_reconciler_test.go index b29e69f997f6..0b59f10e2687 100644 --- a/controllers/kubeadmconfig_controller_reconciler_test.go +++ b/controllers/kubeadmconfig_controller_reconciler_test.go @@ -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") @@ -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, } diff --git a/controllers/kubeadmconfig_controller_test.go b/controllers/kubeadmconfig_controller_test.go index fd5277c1ff48..ceea1a611a7e 100644 --- a/controllers/kubeadmconfig_controller_test.go +++ b/controllers/kubeadmconfig_controller_test.go @@ -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, } @@ -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, } @@ -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, } @@ -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, } @@ -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, } @@ -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, } @@ -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, } @@ -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, } @@ -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, } @@ -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, } @@ -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, } @@ -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, } @@ -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, } diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 427629a0df18..d883d58eab83 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -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 ) @@ -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) @@ -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{