From 5a1e1752b71739d29bf67f6291a48e9047c0ba9c Mon Sep 17 00:00:00 2001 From: Matthew Booth Date: Tue, 27 Feb 2024 09:33:08 +0000 Subject: [PATCH] Remove logger from scope Scope encapsulates an initialised OpenStack client which can be safely shared between reconciles which share the same credentials. The logger is initialised with context specific to an individual reconcile, so it cannot be shared between reconciles. To avoid code churn we preserve the previous interface of Scope with the creation of scope.WithLogger, which changes the initialisation to ensure that the returned logger always comes from the current reconcile even if the scope was cached. While touching logging in tests, we also take the opportunity to replace uses of logr.Discard with GinkgoLogr or logr/testr as appropriate, so test logs are now captured. --- controllers/openstackcluster_controller.go | 15 ++++---- .../openstackcluster_controller_test.go | 38 ++++++++++++++----- .../openstackfloatingippool_controller.go | 11 +++--- controllers/openstackmachine_controller.go | 11 +++--- controllers/suite_test.go | 9 ++--- .../services/compute/dependent_resources.go | 4 +- .../compute/dependent_resources_test.go | 12 +++--- pkg/cloud/services/compute/instance_test.go | 17 +++++---- .../services/compute/instance_types_test.go | 8 ++-- .../services/compute/referenced_resources.go | 2 +- .../compute/referenced_resources_test.go | 8 ++-- .../services/compute/servergroup_test.go | 7 ++-- pkg/cloud/services/compute/service.go | 4 +- .../loadbalancer/loadbalancer_test.go | 12 +++--- pkg/cloud/services/loadbalancer/service.go | 4 +- pkg/cloud/services/networking/network_test.go | 16 ++++++-- pkg/cloud/services/networking/port.go | 4 +- pkg/cloud/services/networking/port_test.go | 6 ++- .../networking/securitygroups_test.go | 12 +++--- pkg/cloud/services/networking/service.go | 4 +- pkg/scope/mock.go | 8 +--- pkg/scope/provider.go | 6 --- pkg/scope/scope.go | 19 +++++++++- 23 files changed, 143 insertions(+), 94 deletions(-) diff --git a/controllers/openstackcluster_controller.go b/controllers/openstackcluster_controller.go index e6712e5257..3abcad6cdc 100644 --- a/controllers/openstackcluster_controller.go +++ b/controllers/openstackcluster_controller.go @@ -116,10 +116,11 @@ func (r *OpenStackClusterReconciler) Reconcile(ctx context.Context, req ctrl.Req } }() - scope, err := r.ScopeFactory.NewClientScopeFromCluster(ctx, r.Client, openStackCluster, r.CaCertificates, log) + clientScope, err := r.ScopeFactory.NewClientScopeFromCluster(ctx, r.Client, openStackCluster, r.CaCertificates, log) if err != nil { return reconcile.Result{}, err } + scope := scope.NewWithLogger(clientScope, log) // Resolve and store referenced & dependent resources for the bastion if openStackCluster.Spec.Bastion != nil && openStackCluster.Spec.Bastion.Enabled { @@ -154,7 +155,7 @@ func (r *OpenStackClusterReconciler) Reconcile(ctx context.Context, req ctrl.Req return reconcileNormal(scope, cluster, openStackCluster) } -func (r *OpenStackClusterReconciler) reconcileDelete(ctx context.Context, scope scope.Scope, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster) (ctrl.Result, error) { +func (r *OpenStackClusterReconciler) reconcileDelete(ctx context.Context, scope *scope.WithLogger, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster) (ctrl.Result, error) { scope.Logger().Info("Reconciling Cluster delete") // Wait for machines to be deleted before removing the finalizer as they @@ -232,7 +233,7 @@ func contains(arr []string, target string) bool { return false } -func deleteBastion(scope scope.Scope, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster) error { +func deleteBastion(scope *scope.WithLogger, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster) error { scope.Logger().Info("Deleting Bastion") computeService, err := compute.NewService(scope) @@ -313,7 +314,7 @@ func deleteBastion(scope scope.Scope, cluster *clusterv1.Cluster, openStackClust return nil } -func reconcileNormal(scope scope.Scope, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster) (ctrl.Result, error) { //nolint:unparam +func reconcileNormal(scope *scope.WithLogger, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster) (ctrl.Result, error) { //nolint:unparam scope.Logger().Info("Reconciling Cluster") // If the OpenStackCluster doesn't have our finalizer, add it. @@ -364,7 +365,7 @@ func reconcileNormal(scope scope.Scope, cluster *clusterv1.Cluster, openStackClu return reconcile.Result{}, nil } -func reconcileBastion(scope scope.Scope, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster) (ctrl.Result, error) { +func reconcileBastion(scope *scope.WithLogger, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster) (ctrl.Result, error) { scope.Logger().Info("Reconciling Bastion") if openStackCluster.Spec.Bastion == nil || !openStackCluster.Spec.Bastion.Enabled { @@ -542,7 +543,7 @@ func getBastionSecurityGroups(openStackCluster *infrav1.OpenStackCluster) []infr return instanceSpecSecurityGroups } -func getOrCreateBastionPorts(scope scope.Scope, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster, networkingService *networking.Service, clusterName string) error { +func getOrCreateBastionPorts(scope *scope.WithLogger, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster, networkingService *networking.Service, clusterName string) error { scope.Logger().Info("Reconciling ports for bastion", "bastion", bastionName(openStackCluster.Name)) if openStackCluster.Status.Bastion == nil { @@ -584,7 +585,7 @@ func bastionHashHasChanged(computeHash string, clusterAnnotations map[string]str return latestHash != computeHash } -func reconcileNetworkComponents(scope scope.Scope, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster) error { +func reconcileNetworkComponents(scope *scope.WithLogger, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster) error { clusterName := fmt.Sprintf("%s-%s", cluster.Namespace, cluster.Name) networkingService, err := networking.NewService(scope) diff --git a/controllers/openstackcluster_controller_test.go b/controllers/openstackcluster_controller_test.go index 8b99f0dc5f..4a19d65f7a 100644 --- a/controllers/openstackcluster_controller_test.go +++ b/controllers/openstackcluster_controller_test.go @@ -22,7 +22,6 @@ import ( "reflect" "testing" - "github.com/go-logr/logr" "github.com/golang/mock/gomock" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" @@ -105,7 +104,7 @@ var _ = Describe("OpenStackCluster controller", func() { framework.CreateNamespace(ctx, input) mockCtrl = gomock.NewController(GinkgoT()) - mockScopeFactory = scope.NewMockScopeFactory(mockCtrl, "", logr.Discard()) + mockScopeFactory = scope.NewMockScopeFactory(mockCtrl, "") reconciler = func() *OpenStackClusterReconciler { return &OpenStackClusterReconciler{ Client: k8sClient, @@ -207,8 +206,10 @@ var _ = Describe("OpenStackCluster controller", func() { } err = k8sClient.Status().Update(ctx, testCluster) Expect(err).To(BeNil()) - scope, err := mockScopeFactory.NewClientScopeFromCluster(ctx, k8sClient, testCluster, nil, logr.Discard()) + log := GinkgoLogr + clientScope, err := mockScopeFactory.NewClientScopeFromCluster(ctx, k8sClient, testCluster, nil, log) Expect(err).To(BeNil()) + scope := scope.NewWithLogger(clientScope, log) computeClientRecorder := mockScopeFactory.ComputeClient.EXPECT() computeClientRecorder.GetServer("bastion-uuid").Return(nil, gophercloud.ErrResourceNotFound{}) @@ -258,8 +259,10 @@ var _ = Describe("OpenStackCluster controller", func() { err = k8sClient.Status().Update(ctx, testCluster) Expect(err).To(BeNil()) - scope, err := mockScopeFactory.NewClientScopeFromCluster(ctx, k8sClient, testCluster, nil, logr.Discard()) + log := GinkgoLogr + clientScope, err := mockScopeFactory.NewClientScopeFromCluster(ctx, k8sClient, testCluster, nil, log) Expect(err).To(BeNil()) + scope := scope.NewWithLogger(clientScope, log) server := clients.ServerExt{} server.ID = "adopted-bastion-uuid" @@ -342,8 +345,10 @@ var _ = Describe("OpenStackCluster controller", func() { err = k8sClient.Status().Update(ctx, testCluster) Expect(err).To(BeNil()) - scope, err := mockScopeFactory.NewClientScopeFromCluster(ctx, k8sClient, testCluster, nil, logr.Discard()) + log := GinkgoLogr + clientScope, err := mockScopeFactory.NewClientScopeFromCluster(ctx, k8sClient, testCluster, nil, log) Expect(err).To(BeNil()) + scope := scope.NewWithLogger(clientScope, log) server := clients.ServerExt{} server.ID = "adopted-fip-bastion-uuid" @@ -425,8 +430,10 @@ var _ = Describe("OpenStackCluster controller", func() { err = k8sClient.Status().Update(ctx, testCluster) Expect(err).To(BeNil()) - scope, err := mockScopeFactory.NewClientScopeFromCluster(ctx, k8sClient, testCluster, nil, logr.Discard()) + log := GinkgoLogr + clientScope, err := mockScopeFactory.NewClientScopeFromCluster(ctx, k8sClient, testCluster, nil, log) Expect(err).To(BeNil()) + scope := scope.NewWithLogger(clientScope, log) server := clients.ServerExt{} server.ID = "requeue-bastion-uuid" @@ -484,8 +491,10 @@ var _ = Describe("OpenStackCluster controller", func() { err = k8sClient.Status().Update(ctx, testCluster) Expect(err).To(BeNil()) - scope, err := mockScopeFactory.NewClientScopeFromCluster(ctx, k8sClient, testCluster, nil, logr.Discard()) + log := GinkgoLogr + clientScope, err := mockScopeFactory.NewClientScopeFromCluster(ctx, k8sClient, testCluster, nil, log) Expect(err).To(BeNil()) + scope := scope.NewWithLogger(clientScope, log) server := clients.ServerExt{} server.ID = "delete-bastion-uuid" @@ -534,8 +543,11 @@ var _ = Describe("OpenStackCluster controller", func() { Expect(err).To(BeNil()) err = k8sClient.Create(ctx, capiCluster) Expect(err).To(BeNil()) - scope, err := mockScopeFactory.NewClientScopeFromCluster(ctx, k8sClient, testCluster, nil, logr.Discard()) + + log := GinkgoLogr + clientScope, err := mockScopeFactory.NewClientScopeFromCluster(ctx, k8sClient, testCluster, nil, log) Expect(err).To(BeNil()) + scope := scope.NewWithLogger(clientScope, log) networkClientRecorder := mockScopeFactory.NetworkClient.EXPECT() @@ -614,8 +626,11 @@ var _ = Describe("OpenStackCluster controller", func() { Expect(err).To(BeNil()) err = k8sClient.Create(ctx, capiCluster) Expect(err).To(BeNil()) - scope, err := mockScopeFactory.NewClientScopeFromCluster(ctx, k8sClient, testCluster, nil, logr.Discard()) + + log := GinkgoLogr + clientScope, err := mockScopeFactory.NewClientScopeFromCluster(ctx, k8sClient, testCluster, nil, log) Expect(err).To(BeNil()) + scope := scope.NewWithLogger(clientScope, log) networkClientRecorder := mockScopeFactory.NetworkClient.EXPECT() @@ -675,8 +690,11 @@ var _ = Describe("OpenStackCluster controller", func() { Expect(err).To(BeNil()) err = k8sClient.Create(ctx, capiCluster) Expect(err).To(BeNil()) - scope, err := mockScopeFactory.NewClientScopeFromCluster(ctx, k8sClient, testCluster, nil, logr.Discard()) + + log := GinkgoLogr + clientScope, err := mockScopeFactory.NewClientScopeFromCluster(ctx, k8sClient, testCluster, nil, log) Expect(err).To(BeNil()) + scope := scope.NewWithLogger(clientScope, log) networkClientRecorder := mockScopeFactory.NetworkClient.EXPECT() diff --git a/controllers/openstackfloatingippool_controller.go b/controllers/openstackfloatingippool_controller.go index 7c72bc081d..fbcdeb2b63 100644 --- a/controllers/openstackfloatingippool_controller.go +++ b/controllers/openstackfloatingippool_controller.go @@ -83,10 +83,11 @@ func (r *OpenStackFloatingIPPoolReconciler) Reconcile(ctx context.Context, req c return ctrl.Result{}, client.IgnoreNotFound(err) } - scope, err := r.ScopeFactory.NewClientScopeFromFloatingIPPool(ctx, r.Client, pool, r.CaCertificates, log) + clientScope, err := r.ScopeFactory.NewClientScopeFromFloatingIPPool(ctx, r.Client, pool, r.CaCertificates, log) if err != nil { return reconcile.Result{}, err } + scope := scope.NewWithLogger(clientScope, log) // This is done before deleting the pool, because we want to handle deleted IPs before we delete the pool if err := r.reconcileIPAddresses(ctx, scope, pool); err != nil { @@ -203,7 +204,7 @@ func (r *OpenStackFloatingIPPoolReconciler) Reconcile(ctx context.Context, req c return ctrl.Result{}, r.Client.Status().Update(ctx, pool) } -func (r *OpenStackFloatingIPPoolReconciler) reconcileDelete(ctx context.Context, scope scope.Scope, pool *infrav1alpha1.OpenStackFloatingIPPool) error { +func (r *OpenStackFloatingIPPoolReconciler) reconcileDelete(ctx context.Context, scope *scope.WithLogger, pool *infrav1alpha1.OpenStackFloatingIPPool) error { log := ctrl.LoggerFrom(ctx) ipAddresses := &ipamv1.IPAddressList{} if err := r.Client.List(ctx, ipAddresses, client.InNamespace(pool.Namespace), client.MatchingFields{infrav1alpha1.OpenStackFloatingIPPoolNameIndex: pool.Name}); err != nil { @@ -267,7 +268,7 @@ func diff(a []string, b []string) []string { return result } -func (r *OpenStackFloatingIPPoolReconciler) reconcileIPAddresses(ctx context.Context, scope scope.Scope, pool *infrav1alpha1.OpenStackFloatingIPPool) error { +func (r *OpenStackFloatingIPPoolReconciler) reconcileIPAddresses(ctx context.Context, scope *scope.WithLogger, pool *infrav1alpha1.OpenStackFloatingIPPool) error { ipAddresses := &ipamv1.IPAddressList{} if err := r.Client.List(ctx, ipAddresses, client.InNamespace(pool.Namespace), client.MatchingFields{infrav1alpha1.OpenStackFloatingIPPoolNameIndex: pool.Name}); err != nil { return err @@ -309,7 +310,7 @@ func (r *OpenStackFloatingIPPoolReconciler) reconcileIPAddresses(ctx context.Con return nil } -func (r *OpenStackFloatingIPPoolReconciler) getIP(ctx context.Context, scope scope.Scope, pool *infrav1alpha1.OpenStackFloatingIPPool) (string, error) { +func (r *OpenStackFloatingIPPoolReconciler) getIP(ctx context.Context, scope *scope.WithLogger, pool *infrav1alpha1.OpenStackFloatingIPPool) (string, error) { // There's a potential leak of IPs here, if the reconcile loop fails after we claim an IP but before we create the IPAddress object. var ip string @@ -388,7 +389,7 @@ func (r *OpenStackFloatingIPPoolReconciler) getIP(ctx context.Context, scope sco return ip, nil } -func (r *OpenStackFloatingIPPoolReconciler) reconcileFloatingIPNetwork(scope scope.Scope, pool *infrav1alpha1.OpenStackFloatingIPPool) error { +func (r *OpenStackFloatingIPPoolReconciler) reconcileFloatingIPNetwork(scope *scope.WithLogger, pool *infrav1alpha1.OpenStackFloatingIPPool) error { // If the pool already has a network, we don't need to do anything if pool.Status.FloatingIPNetwork != nil { return nil diff --git a/controllers/openstackmachine_controller.go b/controllers/openstackmachine_controller.go index 77d092f268..2a296bcfed 100644 --- a/controllers/openstackmachine_controller.go +++ b/controllers/openstackmachine_controller.go @@ -142,10 +142,11 @@ func (r *OpenStackMachineReconciler) Reconcile(ctx context.Context, req ctrl.Req } }() - scope, err := r.ScopeFactory.NewClientScopeFromMachine(ctx, r.Client, openStackMachine, infraCluster, r.CaCertificates, log) + clientScope, err := r.ScopeFactory.NewClientScopeFromMachine(ctx, r.Client, openStackMachine, infraCluster, r.CaCertificates, log) if err != nil { return reconcile.Result{}, err } + scope := scope.NewWithLogger(clientScope, log) // Resolve and store referenced resources changed, err := compute.ResolveReferencedMachineResources(scope, infraCluster, &openStackMachine.Spec, &openStackMachine.Status.ReferencedResources) @@ -240,7 +241,7 @@ func (r *OpenStackMachineReconciler) SetupWithManager(ctx context.Context, mgr c Complete(r) } -func (r *OpenStackMachineReconciler) reconcileDelete(scope scope.Scope, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster, machine *clusterv1.Machine, openStackMachine *infrav1.OpenStackMachine) (ctrl.Result, error) { //nolint:unparam +func (r *OpenStackMachineReconciler) reconcileDelete(scope *scope.WithLogger, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster, machine *clusterv1.Machine, openStackMachine *infrav1.OpenStackMachine) (ctrl.Result, error) { //nolint:unparam scope.Logger().Info("Reconciling Machine delete") clusterName := fmt.Sprintf("%s-%s", cluster.ObjectMeta.Namespace, cluster.Name) @@ -333,7 +334,7 @@ func GetPortIDs(ports []infrav1.PortStatus) []string { return portIDs } -func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope scope.Scope, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster, machine *clusterv1.Machine, openStackMachine *infrav1.OpenStackMachine) (_ ctrl.Result, reterr error) { +func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope *scope.WithLogger, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster, machine *clusterv1.Machine, openStackMachine *infrav1.OpenStackMachine) (_ ctrl.Result, reterr error) { var err error // If the OpenStackMachine is in an error state, return early. @@ -489,7 +490,7 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope return ctrl.Result{}, nil } -func getOrCreateMachinePorts(scope scope.Scope, openStackCluster *infrav1.OpenStackCluster, machine *clusterv1.Machine, openStackMachine *infrav1.OpenStackMachine, networkingService *networking.Service, clusterName string) error { +func getOrCreateMachinePorts(scope *scope.WithLogger, openStackCluster *infrav1.OpenStackCluster, machine *clusterv1.Machine, openStackMachine *infrav1.OpenStackMachine, networkingService *networking.Service, clusterName string) error { scope.Logger().Info("Reconciling ports for machine", "machine", machine.Name) var machinePortsStatus []infrav1.PortStatus var err error @@ -647,7 +648,7 @@ func getManagedSecurityGroups(openStackCluster *infrav1.OpenStackCluster, machin return machineSpecSecurityGroups } -func (r *OpenStackMachineReconciler) reconcileLoadBalancerMember(scope scope.Scope, openStackCluster *infrav1.OpenStackCluster, openStackMachine *infrav1.OpenStackMachine, instanceNS *compute.InstanceNetworkStatus, clusterName string) error { +func (r *OpenStackMachineReconciler) reconcileLoadBalancerMember(scope *scope.WithLogger, openStackCluster *infrav1.OpenStackCluster, openStackMachine *infrav1.OpenStackMachine, instanceNS *compute.InstanceNetworkStatus, clusterName string) error { ip := instanceNS.IP(openStackCluster.Status.Network.Name) loadbalancerService, err := loadbalancer.NewService(scope) if err != nil { diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 2986a4dde6..0a49b42403 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -22,7 +22,6 @@ import ( "path/filepath" "testing" - "github.com/go-logr/logr" "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -127,8 +126,9 @@ var _ = Describe("EnvTest sanity check", func() { }) var _ = Describe("When calling getOrCreate", func() { + logger := GinkgoLogr + var ( - logger logr.Logger reconsiler OpenStackMachineReconciler mockCtrl *gomock.Controller mockScopeFactory *scope.MockScopeFactory @@ -138,11 +138,10 @@ var _ = Describe("When calling getOrCreate", func() { BeforeEach(func() { ctx = context.Background() - logger = logr.Discard() reconsiler = OpenStackMachineReconciler{} mockCtrl = gomock.NewController(GinkgoT()) - mockScopeFactory = scope.NewMockScopeFactory(mockCtrl, "1234", logger) - computeService, err = compute.NewService(mockScopeFactory) + mockScopeFactory = scope.NewMockScopeFactory(mockCtrl, "1234") + computeService, err = compute.NewService(scope.NewWithLogger(mockScopeFactory, logger)) Expect(err).NotTo(HaveOccurred()) }) diff --git a/pkg/cloud/services/compute/dependent_resources.go b/pkg/cloud/services/compute/dependent_resources.go index 6e2a5eb270..ab8bf67547 100644 --- a/pkg/cloud/services/compute/dependent_resources.go +++ b/pkg/cloud/services/compute/dependent_resources.go @@ -22,7 +22,7 @@ import ( "sigs.k8s.io/cluster-api-provider-openstack/pkg/scope" ) -func ResolveDependentMachineResources(scope scope.Scope, openStackMachine *infrav1.OpenStackMachine) (changed bool, err error) { +func ResolveDependentMachineResources(scope *scope.WithLogger, openStackMachine *infrav1.OpenStackMachine) (changed bool, err error) { changed = false networkingService, err := networking.NewService(scope) @@ -33,7 +33,7 @@ func ResolveDependentMachineResources(scope scope.Scope, openStackMachine *infra return networkingService.AdoptMachinePorts(scope, openStackMachine, openStackMachine.Status.ReferencedResources.PortsOpts) } -func ResolveDependentBastionResources(scope scope.Scope, openStackCluster *infrav1.OpenStackCluster, bastionName string) (changed bool, err error) { +func ResolveDependentBastionResources(scope *scope.WithLogger, openStackCluster *infrav1.OpenStackCluster, bastionName string) (changed bool, err error) { changed = false networkingService, err := networking.NewService(scope) diff --git a/pkg/cloud/services/compute/dependent_resources_test.go b/pkg/cloud/services/compute/dependent_resources_test.go index 1bfb8d5791..e1e91f27f3 100644 --- a/pkg/cloud/services/compute/dependent_resources_test.go +++ b/pkg/cloud/services/compute/dependent_resources_test.go @@ -19,7 +19,7 @@ package compute import ( "testing" - "github.com/go-logr/logr" + "github.com/go-logr/logr/testr" "github.com/golang/mock/gomock" "github.com/google/go-cmp/cmp" . "github.com/onsi/gomega" @@ -93,8 +93,9 @@ func Test_ResolveDependentMachineResources(t *testing.T) { for _, tt := range tests { t.Run(tt.testName, func(t *testing.T) { g := NewWithT(t) + log := testr.New(t) mockCtrl := gomock.NewController(t) - mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "", logr.Discard()) + mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "") defaultOpenStackMachine := &infrav1.OpenStackMachine{ ObjectMeta: metav1.ObjectMeta{ @@ -103,7 +104,7 @@ func Test_ResolveDependentMachineResources(t *testing.T) { Status: tt.openStackMachineStatus, } - _, err := ResolveDependentMachineResources(mockScopeFactory, defaultOpenStackMachine) + _, err := ResolveDependentMachineResources(scope.NewWithLogger(mockScopeFactory, log), defaultOpenStackMachine) if tt.wantErr { g.Expect(err).Error() return @@ -192,10 +193,11 @@ func TestResolveDependentBastionResources(t *testing.T) { for _, tt := range tests { t.Run(tt.testName, func(t *testing.T) { g := NewWithT(t) + log := testr.New(t) mockCtrl := gomock.NewController(t) - mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "", logr.Discard()) + mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "") - _, err := ResolveDependentBastionResources(mockScopeFactory, tt.openStackCluster, bastionName) + _, err := ResolveDependentBastionResources(scope.NewWithLogger(mockScopeFactory, log), tt.openStackCluster, bastionName) if tt.wantErr { g.Expect(err).Error() return diff --git a/pkg/cloud/services/compute/instance_test.go b/pkg/cloud/services/compute/instance_test.go index 69b0ac05b8..bc5b01def5 100644 --- a/pkg/cloud/services/compute/instance_test.go +++ b/pkg/cloud/services/compute/instance_test.go @@ -22,7 +22,7 @@ import ( "testing" "time" - "github.com/go-logr/logr" + "github.com/go-logr/logr/testr" "github.com/golang/mock/gomock" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" @@ -120,9 +120,10 @@ func TestService_getImageID(t *testing.T) { for _, tt := range tests { t.Run(tt.testName, func(t *testing.T) { mockCtrl := gomock.NewController(t) - mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "", logr.Discard()) + log := testr.New(t) + mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "") - s, err := NewService(mockScopeFactory) + s, err := NewService(scope.NewWithLogger(mockScopeFactory, log)) if err != nil { t.Fatalf("Failed to create service: %v", err) } @@ -666,7 +667,8 @@ func TestService_ReconcileInstance(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { mockCtrl := gomock.NewController(t) - mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "", logr.Discard()) + log := testr.New(t) + mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "") computeRecorder := mockScopeFactory.ComputeClient.EXPECT() imageRecorder := mockScopeFactory.ImageClient.EXPECT() @@ -675,7 +677,7 @@ func TestService_ReconcileInstance(t *testing.T) { tt.expect(&recorders{computeRecorder, imageRecorder, networkRecorder, volumeRecorder}) - s, err := NewService(mockScopeFactory) + s, err := NewService(scope.NewWithLogger(mockScopeFactory, log)) if err != nil { t.Fatalf("Failed to create service: %v", err) } @@ -759,7 +761,8 @@ func TestService_DeleteInstance(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { mockCtrl := gomock.NewController(t) - mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "", logr.Discard()) + log := testr.New(t) + mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "") computeRecorder := mockScopeFactory.ComputeClient.EXPECT() networkRecorder := mockScopeFactory.NetworkClient.EXPECT() @@ -767,7 +770,7 @@ func TestService_DeleteInstance(t *testing.T) { tt.expect(&recorders{computeRecorder, networkRecorder, volumeRecorder}) - s, err := NewService(mockScopeFactory) + s, err := NewService(scope.NewWithLogger(mockScopeFactory, log)) if err != nil { t.Fatalf("Failed to create service: %v", err) } diff --git a/pkg/cloud/services/compute/instance_types_test.go b/pkg/cloud/services/compute/instance_types_test.go index 271af92f60..650fda62ef 100644 --- a/pkg/cloud/services/compute/instance_types_test.go +++ b/pkg/cloud/services/compute/instance_types_test.go @@ -19,7 +19,7 @@ package compute import ( "testing" - "github.com/go-logr/logr" + "github.com/go-logr/logr/testr" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" @@ -196,10 +196,11 @@ func TestNetworkStatus_Addresses(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) + log := testr.New(t) is := &InstanceStatus{ server: serverWithAddresses(tt.addresses), - logger: logr.Discard(), + logger: log, } instanceNS, err := is.NetworkStatus() g.Expect(err).NotTo(HaveOccurred()) @@ -411,10 +412,11 @@ func TestInstanceNetworkStatus(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) + log := testr.New(t) is := &InstanceStatus{ server: serverWithAddresses(tt.addresses), - logger: logr.Discard(), + logger: log, } ns, err := is.NetworkStatus() g.Expect(err).NotTo(HaveOccurred()) diff --git a/pkg/cloud/services/compute/referenced_resources.go b/pkg/cloud/services/compute/referenced_resources.go index c78298ce16..657a14f93a 100644 --- a/pkg/cloud/services/compute/referenced_resources.go +++ b/pkg/cloud/services/compute/referenced_resources.go @@ -28,7 +28,7 @@ import ( // Note that we only set the fields in ReferencedMachineResources that are not set yet. This is ok because: // - OpenStackMachine is immutable, so we can't change the spec after the machine is created. // - the bastion is mutable, but we delete the bastion when the spec changes, so the bastion status will be empty. -func ResolveReferencedMachineResources(scope scope.Scope, openStackCluster *infrav1.OpenStackCluster, spec *infrav1.OpenStackMachineSpec, resources *infrav1.ReferencedMachineResources) (changed bool, err error) { +func ResolveReferencedMachineResources(scope *scope.WithLogger, openStackCluster *infrav1.OpenStackCluster, spec *infrav1.OpenStackMachineSpec, resources *infrav1.ReferencedMachineResources) (changed bool, err error) { changed = false computeService, err := NewService(scope) diff --git a/pkg/cloud/services/compute/referenced_resources_test.go b/pkg/cloud/services/compute/referenced_resources_test.go index 06f6a8f5d2..e4107ba302 100644 --- a/pkg/cloud/services/compute/referenced_resources_test.go +++ b/pkg/cloud/services/compute/referenced_resources_test.go @@ -19,7 +19,7 @@ package compute import ( "testing" - "github.com/go-logr/logr" + "github.com/go-logr/logr/testr" "github.com/golang/mock/gomock" "github.com/google/go-cmp/cmp" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups" @@ -148,8 +148,9 @@ func Test_ResolveReferencedMachineResources(t *testing.T) { for _, tt := range tests { t.Run(tt.testName, func(t *testing.T) { g := NewWithT(t) + log := testr.New(t) mockCtrl := gomock.NewController(t) - mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "", logr.Discard()) + mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "") tt.expectComputeMock(mockScopeFactory.ComputeClient.EXPECT()) tt.expectImageMock(mockScopeFactory.ImageClient.EXPECT()) @@ -178,7 +179,8 @@ func Test_ResolveReferencedMachineResources(t *testing.T) { resources := &infrav1.ReferencedMachineResources{} - _, err := ResolveReferencedMachineResources(mockScopeFactory, openStackCluster, machineSpec, resources) + scope := scope.NewWithLogger(mockScopeFactory, log) + _, err := ResolveReferencedMachineResources(scope, openStackCluster, machineSpec, resources) if tt.wantErr { g.Expect(err).Error() return diff --git a/pkg/cloud/services/compute/servergroup_test.go b/pkg/cloud/services/compute/servergroup_test.go index af8ed35f02..2771ccf26a 100644 --- a/pkg/cloud/services/compute/servergroup_test.go +++ b/pkg/cloud/services/compute/servergroup_test.go @@ -20,7 +20,7 @@ import ( "fmt" "testing" - "github.com/go-logr/logr" + "github.com/go-logr/logr/testr" "github.com/golang/mock/gomock" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups" @@ -107,9 +107,10 @@ func TestService_GetServerGroupID(t *testing.T) { for _, tt := range tests { t.Run(tt.testName, func(t *testing.T) { mockCtrl := gomock.NewController(t) - mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "", logr.Discard()) + log := testr.New(t) + mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "") - s, err := NewService(mockScopeFactory) + s, err := NewService(scope.NewWithLogger(mockScopeFactory, log)) if err != nil { t.Fatalf("Failed to create service: %v", err) } diff --git a/pkg/cloud/services/compute/service.go b/pkg/cloud/services/compute/service.go index b819d33e31..ac3a9a8022 100644 --- a/pkg/cloud/services/compute/service.go +++ b/pkg/cloud/services/compute/service.go @@ -25,7 +25,7 @@ import ( ) type Service struct { - scope scope.Scope + scope *scope.WithLogger _computeClient clients.ComputeClient _volumeClient clients.VolumeClient _imageClient clients.ImageClient @@ -33,7 +33,7 @@ type Service struct { } // NewService returns an instance of the compute service. -func NewService(scope scope.Scope) (*Service, error) { +func NewService(scope *scope.WithLogger) (*Service, error) { return &Service{ scope: scope, }, nil diff --git a/pkg/cloud/services/loadbalancer/loadbalancer_test.go b/pkg/cloud/services/loadbalancer/loadbalancer_test.go index 0c9996ca0f..f264a83415 100644 --- a/pkg/cloud/services/loadbalancer/loadbalancer_test.go +++ b/pkg/cloud/services/loadbalancer/loadbalancer_test.go @@ -22,7 +22,7 @@ import ( "net" "testing" - "github.com/go-logr/logr" + "github.com/go-logr/logr/testr" "github.com/golang/mock/gomock" "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/apiversions" "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners" @@ -139,9 +139,10 @@ func Test_ReconcileLoadBalancer(t *testing.T) { for _, tt := range lbtests { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) + log := testr.New(t) - mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "", logr.Discard()) - lbs, err := NewService(mockScopeFactory) + mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "") + lbs, err := NewService(scope.NewWithLogger(mockScopeFactory, log)) g.Expect(err).NotTo(HaveOccurred()) tt.expectNetwork(mockScopeFactory.NetworkClient.EXPECT()) @@ -485,9 +486,10 @@ func Test_getOrCreateAPILoadBalancer(t *testing.T) { for _, tt := range lbtests { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) + log := testr.New(t) - mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "", logr.Discard()) - lbs, err := NewService(mockScopeFactory) + mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "") + lbs, err := NewService(scope.NewWithLogger(mockScopeFactory, log)) g.Expect(err).NotTo(HaveOccurred()) tt.expectLoadBalancer(mockScopeFactory.LbClient.EXPECT()) diff --git a/pkg/cloud/services/loadbalancer/service.go b/pkg/cloud/services/loadbalancer/service.go index 380ebd05d9..58ffc07912 100644 --- a/pkg/cloud/services/loadbalancer/service.go +++ b/pkg/cloud/services/loadbalancer/service.go @@ -26,13 +26,13 @@ import ( // Service interfaces with the OpenStack Neutron LBaaS v2 API. type Service struct { - scope scope.Scope + scope *scope.WithLogger loadbalancerClient clients.LbClient networkingService *networking.Service } // NewService returns an instance of the loadbalancer service. -func NewService(scope scope.Scope) (*Service, error) { +func NewService(scope *scope.WithLogger) (*Service, error) { loadbalancerClient, err := scope.NewLbClient() if err != nil { return nil, err diff --git a/pkg/cloud/services/networking/network_test.go b/pkg/cloud/services/networking/network_test.go index 1781ecab67..27a07580ba 100644 --- a/pkg/cloud/services/networking/network_test.go +++ b/pkg/cloud/services/networking/network_test.go @@ -19,7 +19,7 @@ package networking import ( "testing" - "github.com/go-logr/logr" + "github.com/go-logr/logr/testr" "github.com/golang/mock/gomock" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external" @@ -188,9 +188,12 @@ func Test_ReconcileNetwork(t *testing.T) { g := NewWithT(t) mockClient := mock.NewMockNetworkClient(mockCtrl) tt.expect(mockClient.EXPECT()) + + scopeFactory := scope.NewMockScopeFactory(mockCtrl, "") + log := testr.New(t) s := Service{ client: mockClient, - scope: scope.NewMockScopeFactory(mockCtrl, "", logr.Discard()), + scope: scope.NewWithLogger(scopeFactory, log), } err := s.ReconcileNetwork(tt.openStackCluster, clusterName) g.Expect(err).ShouldNot(HaveOccurred()) @@ -410,9 +413,12 @@ func Test_ReconcileExternalNetwork(t *testing.T) { g := NewWithT(t) mockClient := mock.NewMockNetworkClient(mockCtrl) tt.expect(mockClient.EXPECT()) + + scopeFactory := scope.NewMockScopeFactory(mockCtrl, "") + log := testr.New(t) s := Service{ client: mockClient, - scope: scope.NewMockScopeFactory(mockCtrl, "", logr.Discard()), + scope: scope.NewWithLogger(scopeFactory, log), } err := s.ReconcileExternalNetwork(tt.openStackCluster) if (err != nil) != tt.wantErr { @@ -668,11 +674,13 @@ func Test_ReconcileSubnet(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) + log := testr.New(t) mockClient := mock.NewMockNetworkClient(mockCtrl) tt.expect(mockClient.EXPECT()) + mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "") s := Service{ client: mockClient, - scope: scope.NewMockScopeFactory(mockCtrl, "", logr.Discard()), + scope: scope.NewWithLogger(mockScopeFactory, log), } err := s.ReconcileSubnet(tt.openStackCluster, clusterName) g.Expect(err).ShouldNot(HaveOccurred()) diff --git a/pkg/cloud/services/networking/port.go b/pkg/cloud/services/networking/port.go index 5df5002534..1ecf4beaca 100644 --- a/pkg/cloud/services/networking/port.go +++ b/pkg/cloud/services/networking/port.go @@ -518,7 +518,7 @@ func (s *Service) IsTrunkExtSupported() (trunknSupported bool, err error) { // by checking if they exist and if they do, it'll add them to the OpenStackMachine status. // A port is searched by name and network ID and has to be unique. // If the port is not found, it'll be ignored because it'll be created after the adoption. -func (s *Service) AdoptMachinePorts(scope scope.Scope, openStackMachine *infrav1.OpenStackMachine, desiredPorts []infrav1.PortOpts) (changed bool, err error) { +func (s *Service) AdoptMachinePorts(scope *scope.WithLogger, openStackMachine *infrav1.OpenStackMachine, desiredPorts []infrav1.PortOpts) (changed bool, err error) { changed = false // We can skip adoption if the instance is ready because OpenStackMachine is immutable once ready @@ -572,7 +572,7 @@ func (s *Service) AdoptMachinePorts(scope scope.Scope, openStackMachine *infrav1 // it'll add them to the OpenStackCluster status. // A port is searched by name and network ID and has to be unique. // If the port is not found, it'll be ignored because it'll be created after the adoption. -func (s *Service) AdoptBastionPorts(scope scope.Scope, openStackCluster *infrav1.OpenStackCluster, bastionName string) (changed bool, err error) { +func (s *Service) AdoptBastionPorts(scope *scope.WithLogger, openStackCluster *infrav1.OpenStackCluster, bastionName string) (changed bool, err error) { changed = false if openStackCluster.Status.Network == nil { diff --git a/pkg/cloud/services/networking/port_test.go b/pkg/cloud/services/networking/port_test.go index 57103319e0..96d741d992 100644 --- a/pkg/cloud/services/networking/port_test.go +++ b/pkg/cloud/services/networking/port_test.go @@ -19,7 +19,7 @@ package networking import ( "testing" - "github.com/go-logr/logr" + "github.com/go-logr/logr/testr" "github.com/golang/mock/gomock" "github.com/google/go-cmp/cmp" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags" @@ -774,14 +774,16 @@ func TestService_normalizePorts(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) + log := testr.New(t) mockClient := mock.NewMockNetworkClient(mockCtrl) if tt.expectNetwork != nil { tt.expectNetwork(mockClient.EXPECT()) } + mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "") s := Service{ client: mockClient, - scope: scope.NewMockScopeFactory(mockCtrl, "", logr.Discard()), + scope: scope.NewWithLogger(mockScopeFactory, log), } got, err := s.normalizePorts(tt.ports, openStackCluster, tt.instanceTrunk) diff --git a/pkg/cloud/services/networking/securitygroups_test.go b/pkg/cloud/services/networking/securitygroups_test.go index e09ba9b7fb..b88a81cd43 100644 --- a/pkg/cloud/services/networking/securitygroups_test.go +++ b/pkg/cloud/services/networking/securitygroups_test.go @@ -19,7 +19,7 @@ import ( "reflect" "testing" - "github.com/go-logr/logr" + "github.com/go-logr/logr/testr" "github.com/golang/mock/gomock" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules" @@ -342,9 +342,10 @@ func TestGenerateDesiredSecGroups(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) - mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "", logr.Discard()) + log := testr.New(t) + mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "") - s, err := NewService(mockScopeFactory) + s, err := NewService(scope.NewWithLogger(mockScopeFactory, log)) if err != nil { t.Fatalf("Failed to create service: %v", err) } @@ -515,9 +516,10 @@ func TestReconcileGroupRules(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) - mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "", logr.Discard()) + log := testr.New(t) + mockScopeFactory := scope.NewMockScopeFactory(mockCtrl, "") - s, err := NewService(mockScopeFactory) + s, err := NewService(scope.NewWithLogger(mockScopeFactory, log)) if err != nil { t.Fatalf("Failed to create service: %v", err) } diff --git a/pkg/cloud/services/networking/service.go b/pkg/cloud/services/networking/service.go index b0a9b8da17..3a01c48b85 100644 --- a/pkg/cloud/services/networking/service.go +++ b/pkg/cloud/services/networking/service.go @@ -37,12 +37,12 @@ const ( // Service interfaces with the OpenStack Networking API. // It will create a network related infrastructure for the cluster, like network, subnet, router, security groups. type Service struct { - scope scope.Scope + scope *scope.WithLogger client clients.NetworkClient } // NewService returns an instance of the networking service. -func NewService(scope scope.Scope) (*Service, error) { +func NewService(scope *scope.WithLogger) (*Service, error) { networkClient, err := scope.NewNetworkClient() if err != nil { return nil, err diff --git a/pkg/scope/mock.go b/pkg/scope/mock.go index 4568a66d19..3f3cec13be 100644 --- a/pkg/scope/mock.go +++ b/pkg/scope/mock.go @@ -40,12 +40,11 @@ type MockScopeFactory struct { ImageClient *mock.MockImageClient LbClient *mock.MockLbClient - logger logr.Logger projectID string clientScopeCreateError error } -func NewMockScopeFactory(mockCtrl *gomock.Controller, projectID string, logger logr.Logger) *MockScopeFactory { +func NewMockScopeFactory(mockCtrl *gomock.Controller, projectID string) *MockScopeFactory { computeClient := mock.NewMockComputeClient(mockCtrl) volumeClient := mock.NewMockVolumeClient(mockCtrl) imageClient := mock.NewMockImageClient(mockCtrl) @@ -59,7 +58,6 @@ func NewMockScopeFactory(mockCtrl *gomock.Controller, projectID string, logger l NetworkClient: networkClient, LbClient: lbClient, projectID: projectID, - logger: logger, } } @@ -108,10 +106,6 @@ func (f *MockScopeFactory) NewLbClient() (clients.LbClient, error) { return f.LbClient, nil } -func (f *MockScopeFactory) Logger() logr.Logger { - return f.logger -} - func (f *MockScopeFactory) ProjectID() string { return f.projectID } diff --git a/pkg/scope/provider.go b/pkg/scope/provider.go index 2b531f361d..cda179d2e6 100644 --- a/pkg/scope/provider.go +++ b/pkg/scope/provider.go @@ -141,7 +141,6 @@ type providerScope struct { providerClient *gophercloud.ProviderClient providerClientOpts *clientconfig.ClientOpts projectID string - logger logr.Logger } func NewProviderScope(cloud clientconfig.Cloud, caCert []byte, logger logr.Logger) (Scope, error) { @@ -154,7 +153,6 @@ func NewProviderScope(cloud clientconfig.Cloud, caCert []byte, logger logr.Logge providerClient: providerClient, providerClientOpts: clientOpts, projectID: projectID, - logger: logger, }, nil } @@ -186,10 +184,6 @@ func NewCachedProviderScope(cache *cache.LRUExpireCache, cloud clientconfig.Clou return scope, nil } -func (s *providerScope) Logger() logr.Logger { - return s.logger -} - func (s *providerScope) ProjectID() string { return s.projectID } diff --git a/pkg/scope/scope.go b/pkg/scope/scope.go index 6b16e908f1..6792df2fb7 100644 --- a/pkg/scope/scope.go +++ b/pkg/scope/scope.go @@ -54,7 +54,24 @@ type Scope interface { NewImageClient() (clients.ImageClient, error) NewNetworkClient() (clients.NetworkClient, error) NewLbClient() (clients.LbClient, error) - Logger() logr.Logger ProjectID() string ExtractToken() (*tokens.Token, error) } + +// WithLogger extends Scope with a logger. +type WithLogger struct { + Scope + + logger logr.Logger +} + +func NewWithLogger(scope Scope, logger logr.Logger) *WithLogger { + return &WithLogger{ + Scope: scope, + logger: logger, + } +} + +func (s *WithLogger) Logger() logr.Logger { + return s.logger +}