Skip to content

Commit

Permalink
User klog.Background() instead of textlogger (#1778)
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthik-K-N authored May 16, 2024
1 parent dcf1882 commit 83e571f
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 61 deletions.
4 changes: 2 additions & 2 deletions cloud/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/IBM/go-sdk-core/v5/core"
"github.com/IBM/vpc-go-sdk/vpcv1"

"k8s.io/klog/v2/textlogger"
"k8s.io/klog/v2"

"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -74,7 +74,7 @@ func NewClusterScope(params ClusterScopeParams) (*ClusterScope, error) {
}

if params.Logger == (logr.Logger{}) {
params.Logger = textlogger.NewLogger(textlogger.NewConfig())
params.Logger = klog.Background()
}

helper, err := patch.NewHelper(params.IBMVPCCluster, params.Client)
Expand Down
4 changes: 2 additions & 2 deletions cloud/scope/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"go.uber.org/mock/gomock"

"k8s.io/client-go/kubernetes/scheme"
"k8s.io/klog/v2/textlogger"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

Expand All @@ -47,7 +47,7 @@ func setupClusterScope(clusterName string, mockvpc *mock.MockVpc) *ClusterScope
client := fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(initObjects...).Build()
return &ClusterScope{
Client: client,
Logger: textlogger.NewLogger(textlogger.NewConfig()),
Logger: klog.Background(),
IBMVPCClient: mockvpc,
Cluster: cluster,
IBMVPCCluster: vpcCluster,
Expand Down
4 changes: 2 additions & 2 deletions cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2/textlogger"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"

"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -80,7 +80,7 @@ func NewMachineScope(params MachineScopeParams) (*MachineScope, error) {
}

if params.Logger == (logr.Logger{}) {
params.Logger = textlogger.NewLogger(textlogger.NewConfig())
params.Logger = klog.Background()
}

helper, err := patch.NewHelper(params.IBMVPCMachine, params.Client)
Expand Down
4 changes: 2 additions & 2 deletions cloud/scope/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/klog/v2/textlogger"
"k8s.io/klog/v2"
capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
Expand Down Expand Up @@ -66,7 +66,7 @@ func setupMachineScope(clusterName string, machineName string, mockvpc *mock.Moc
client := fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(initObjects...).Build()
return &MachineScope{
Client: client,
Logger: textlogger.NewLogger(textlogger.NewConfig()),
Logger: klog.Background(),
IBMVPCClient: mockvpc,
Cluster: cluster,
Machine: machine,
Expand Down
4 changes: 2 additions & 2 deletions cloud/scope/powervs_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"github.com/IBM/platform-services-go-sdk/resourcemanagerv2"
"github.com/IBM/vpc-go-sdk/vpcv1"

"k8s.io/klog/v2/textlogger"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"

"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -117,7 +117,7 @@ func NewPowerVSClusterScope(params PowerVSClusterScopeParams) (*PowerVSClusterSc
return nil, err
}
if params.Logger == (logr.Logger{}) {
params.Logger = textlogger.NewLogger(textlogger.NewConfig())
params.Logger = klog.Background()
}

helper, err := patch.NewHelper(params.IBMPowerVSCluster, params.Client)
Expand Down
4 changes: 2 additions & 2 deletions cloud/scope/powervs_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/IBM/go-sdk-core/v5/core"
"github.com/IBM/platform-services-go-sdk/resourcecontrollerv2"

"k8s.io/klog/v2/textlogger"
"k8s.io/klog/v2"

"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -80,7 +80,7 @@ func NewPowerVSImageScope(params PowerVSImageScopeParams) (scope *PowerVSImageSc
scope.IBMPowerVSImage = params.IBMPowerVSImage

if params.Logger == (logr.Logger{}) {
params.Logger = textlogger.NewLogger(textlogger.NewConfig())
params.Logger = klog.Background()
}
scope.Logger = params.Logger

Expand Down
4 changes: 2 additions & 2 deletions cloud/scope/powervs_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/klog/v2/textlogger"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

Expand Down Expand Up @@ -63,7 +63,7 @@ func setupPowerVSImageScope(imageName string, mockpowervs *mock.MockPowerVS) *Po
client := fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(initObjects...).Build()
return &PowerVSImageScope{
Client: client,
Logger: textlogger.NewLogger(textlogger.NewConfig()),
Logger: klog.Background(),
IBMPowerVSClient: mockpowervs,
IBMPowerVSImage: powervsImage,
}
Expand Down
4 changes: 2 additions & 2 deletions cloud/scope/powervs_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/tools/cache"
"k8s.io/klog/v2/textlogger"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"

"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -133,7 +133,7 @@ func NewPowerVSMachineScope(params PowerVSMachineScopeParams) (scope *PowerVSMac
scope.IBMPowerVSImage = params.IBMPowerVSImage

if params.Logger == (logr.Logger{}) {
params.Logger = textlogger.NewLogger(textlogger.NewConfig())
params.Logger = klog.Background()
}
if params.Logger.V(DEBUGLEVEL).Enabled() {
core.SetLoggingLevel(core.LevelDebug)
Expand Down
4 changes: 2 additions & 2 deletions cloud/scope/powervs_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/cache"
"k8s.io/klog/v2/textlogger"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -89,7 +89,7 @@ func setupPowerVSMachineScope(clusterName string, machineName string, imageID *s
client := fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(initObjects...).Build()
return &PowerVSMachineScope{
Client: client,
Logger: textlogger.NewLogger(textlogger.NewConfig()),
Logger: klog.Background(),
IBMPowerVSClient: mockpowervs,
Cluster: cluster,
Machine: machine,
Expand Down
6 changes: 3 additions & 3 deletions controllers/ibmpowervscluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/klog/v2/textlogger"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util"
Expand Down Expand Up @@ -178,7 +178,7 @@ func TestIBMPowerVSClusterReconciler_delete(t *testing.T) {
t.Run("Should reconcile successfully if no descendants are found", func(t *testing.T) {
g := NewWithT(t)
clusterScope = &scope.PowerVSClusterScope{
Logger: textlogger.NewLogger(textlogger.NewConfig()),
Logger: klog.Background(),
IBMPowerVSCluster: &infrav1beta2.IBMPowerVSCluster{
TypeMeta: metav1.TypeMeta{
Kind: "IBMPowerVSCluster",
Expand All @@ -200,7 +200,7 @@ func TestIBMPowerVSClusterReconciler_delete(t *testing.T) {
t.Run("Should reconcile with requeue by deleting the cluster descendants", func(t *testing.T) {
g := NewWithT(t)
clusterScope = &scope.PowerVSClusterScope{
Logger: textlogger.NewLogger(textlogger.NewConfig()),
Logger: klog.Background(),
IBMPowerVSCluster: &infrav1beta2.IBMPowerVSCluster{
TypeMeta: metav1.TypeMeta{
Kind: "IBMPowerVSCluster",
Expand Down
8 changes: 4 additions & 4 deletions controllers/ibmpowervsimage_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2/textlogger"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util"
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestIBMPowerVSImageReconciler_reconcile(t *testing.T) {
Name: "capi-powervs-cluster"},
}
imageScope := &scope.PowerVSImageScope{
Logger: textlogger.NewLogger(textlogger.NewConfig()),
Logger: klog.Background(),
IBMPowerVSImage: &infrav1beta2.IBMPowerVSImage{
ObjectMeta: metav1.ObjectMeta{
Name: "capi-image",
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestIBMPowerVSImageReconciler_reconcile(t *testing.T) {

mockclient := fake.NewClientBuilder().WithObjects([]client.Object{powervsCluster, powervsImage}...).Build()
imageScope := &scope.PowerVSImageScope{
Logger: textlogger.NewLogger(textlogger.NewConfig()),
Logger: klog.Background(),
Client: mockclient,
IBMPowerVSImage: powervsImage,
IBMPowerVSClient: mockpowervs,
Expand Down Expand Up @@ -337,7 +337,7 @@ func TestIBMPowerVSImageReconciler_delete(t *testing.T) {
Recorder: recorder,
}
imageScope = &scope.PowerVSImageScope{
Logger: textlogger.NewLogger(textlogger.NewConfig()),
Logger: klog.Background(),
IBMPowerVSImage: &infrav1beta2.IBMPowerVSImage{},
IBMPowerVSClient: mockpowervs,
}
Expand Down
24 changes: 12 additions & 12 deletions controllers/ibmpowervsmachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2/textlogger"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util"
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestIBMPowerVSMachineReconciler_Reconcile(t *testing.T) {
g := NewWithT(t)
reconciler := &IBMPowerVSMachineReconciler{
Client: testEnv.Client,
Log: textlogger.NewLogger(textlogger.NewConfig()),
Log: klog.Background(),
}
ns, err := testEnv.CreateNamespace(ctx, fmt.Sprintf("namespace-%s", util.RandomString(5)))
g.Expect(err).To(BeNil())
Expand Down Expand Up @@ -262,7 +262,7 @@ func TestIBMPowerVSMachineReconciler_Delete(t *testing.T) {
recorder := record.NewFakeRecorder(2)
reconciler = IBMPowerVSMachineReconciler{
Client: testEnv.Client,
Log: textlogger.NewLogger(textlogger.NewConfig()),
Log: klog.Background(),
Recorder: recorder,
}
}
Expand All @@ -276,7 +276,7 @@ func TestIBMPowerVSMachineReconciler_Delete(t *testing.T) {
setup(t)
t.Cleanup(teardown)
machineScope = &scope.PowerVSMachineScope{
Logger: textlogger.NewLogger(textlogger.NewConfig()),
Logger: klog.Background(),
IBMPowerVSClient: mockpowervs,
IBMPowerVSMachine: &infrav1beta2.IBMPowerVSMachine{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -294,7 +294,7 @@ func TestIBMPowerVSMachineReconciler_Delete(t *testing.T) {
setup(t)
t.Cleanup(teardown)
machineScope = &scope.PowerVSMachineScope{
Logger: textlogger.NewLogger(textlogger.NewConfig()),
Logger: klog.Background(),
IBMPowerVSClient: mockpowervs,
IBMPowerVSMachine: &infrav1beta2.IBMPowerVSMachine{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -330,7 +330,7 @@ func TestIBMPowerVSMachineReconciler_Delete(t *testing.T) {
mockClient := fake.NewClientBuilder().WithObjects([]client.Object{secret}...).Build()
machineScope = &scope.PowerVSMachineScope{
Client: mockClient,
Logger: textlogger.NewLogger(textlogger.NewConfig()),
Logger: klog.Background(),
IBMPowerVSClient: mockpowervs,
IBMPowerVSMachine: &infrav1beta2.IBMPowerVSMachine{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -377,7 +377,7 @@ func TestIBMPowerVSMachineReconciler_ReconcileOperations(t *testing.T) {
recorder := record.NewFakeRecorder(2)
reconciler = IBMPowerVSMachineReconciler{
Client: testEnv.Client,
Log: textlogger.NewLogger(textlogger.NewConfig()),
Log: klog.Background(),
Recorder: recorder,
}
}
Expand All @@ -390,7 +390,7 @@ func TestIBMPowerVSMachineReconciler_ReconcileOperations(t *testing.T) {
setup(t)
t.Cleanup(teardown)
machineScope = &scope.PowerVSMachineScope{
Logger: textlogger.NewLogger(textlogger.NewConfig()),
Logger: klog.Background(),
Cluster: &capiv1beta1.Cluster{
Status: capiv1beta1.ClusterStatus{
InfrastructureReady: false,
Expand All @@ -408,7 +408,7 @@ func TestIBMPowerVSMachineReconciler_ReconcileOperations(t *testing.T) {
setup(t)
t.Cleanup(teardown)
machineScope = &scope.PowerVSMachineScope{
Logger: textlogger.NewLogger(textlogger.NewConfig()),
Logger: klog.Background(),
Cluster: &capiv1beta1.Cluster{
Status: capiv1beta1.ClusterStatus{
InfrastructureReady: true,
Expand All @@ -431,7 +431,7 @@ func TestIBMPowerVSMachineReconciler_ReconcileOperations(t *testing.T) {
setup(t)
t.Cleanup(teardown)
machineScope = &scope.PowerVSMachineScope{
Logger: textlogger.NewLogger(textlogger.NewConfig()),
Logger: klog.Background(),
Cluster: &capiv1beta1.Cluster{
Status: capiv1beta1.ClusterStatus{
InfrastructureReady: true,
Expand All @@ -457,7 +457,7 @@ func TestIBMPowerVSMachineReconciler_ReconcileOperations(t *testing.T) {
var instances = &models.PVMInstances{}
mockclient := fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects().Build()
machineScope = &scope.PowerVSMachineScope{
Logger: textlogger.NewLogger(textlogger.NewConfig()),
Logger: klog.Background(),
Client: mockclient,
Cluster: &capiv1beta1.Cluster{
Status: capiv1beta1.ClusterStatus{
Expand Down Expand Up @@ -540,7 +540,7 @@ func TestIBMPowerVSMachineReconciler_ReconcileOperations(t *testing.T) {

mockclient := fake.NewClientBuilder().WithObjects([]client.Object{secret, pvsmachine, machine}...).Build()
machineScope = &scope.PowerVSMachineScope{
Logger: textlogger.NewLogger(textlogger.NewConfig()),
Logger: klog.Background(),
Client: mockclient,
Cluster: &capiv1beta1.Cluster{
Status: capiv1beta1.ClusterStatus{
Expand Down
Loading

0 comments on commit 83e571f

Please sign in to comment.