From ac7392a0633044c4a1ad283df2977374546c4187 Mon Sep 17 00:00:00 2001 From: Rafaela Soares <119665479+rsoaresd@users.noreply.github.com> Date: Fri, 22 Mar 2024 09:26:40 +0000 Subject: [PATCH] clean up packages being imported more than once (#548) --- controllers/nstemplateset/client_test.go | 3 +-- .../nstemplateset/cluster_resources_test.go | 11 +++++------ controllers/nstemplateset/namespaces_test.go | 17 ++++++++--------- controllers/nstemplateset/space_roles_test.go | 3 +-- controllers/nstemplateset/status_test.go | 7 +++---- pkg/autoscaler/autoscaler.go | 5 ++--- 6 files changed, 20 insertions(+), 26 deletions(-) diff --git a/controllers/nstemplateset/client_test.go b/controllers/nstemplateset/client_test.go index 65dcb45f..df1b61d3 100644 --- a/controllers/nstemplateset/client_test.go +++ b/controllers/nstemplateset/client_test.go @@ -20,7 +20,6 @@ import ( "k8s.io/client-go/kubernetes/scheme" runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" ) @@ -28,7 +27,7 @@ func TestApplyToolchainObjects(t *testing.T) { // given logger := zap.New(zap.UseDevMode(true)) ctx := log.IntoContext(context.TODO(), logger) - logf.SetLogger(logger) + log.SetLogger(logger) role := newRole("john-dev", "edit-john", "john") devNs := newNamespace("advanced", "john", "dev") optionalDeployment := newOptionalDeployment("john-dev-deployment", "john") diff --git a/controllers/nstemplateset/cluster_resources_test.go b/controllers/nstemplateset/cluster_resources_test.go index 42d9a47a..353f22de 100644 --- a/controllers/nstemplateset/cluster_resources_test.go +++ b/controllers/nstemplateset/cluster_resources_test.go @@ -24,7 +24,6 @@ import ( "k8s.io/client-go/kubernetes/scheme" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" ) @@ -170,7 +169,7 @@ func TestClusterResourceKinds(t *testing.T) { func TestEnsureClusterResourcesOK(t *testing.T) { // given logger := zap.New(zap.UseDevMode(true)) - logf.SetLogger(logger) + log.SetLogger(logger) ctx := log.IntoContext(context.TODO(), logger) spacename := "johnsmith" namespaceName := "toolchain-member" @@ -296,7 +295,7 @@ func TestEnsureClusterResourcesFail(t *testing.T) { // given logger := zap.New(zap.UseDevMode(true)) - logf.SetLogger(logger) + log.SetLogger(logger) ctx := log.IntoContext(context.TODO(), logger) spacename := "johnsmith-space" namespaceName := "toolchain-member" @@ -364,7 +363,7 @@ func TestDeleteClusterResources(t *testing.T) { // given logger := zap.New(zap.UseDevMode(true)) - logf.SetLogger(logger) + log.SetLogger(logger) ctx := log.IntoContext(context.TODO(), logger) spacename := "johnsmith" namespaceName := "toolchain-member" @@ -494,7 +493,7 @@ func TestPromoteClusterResources(t *testing.T) { // given logger := zap.New(zap.UseDevMode(true)) - logf.SetLogger(logger) + log.SetLogger(logger) ctx := log.IntoContext(context.TODO(), logger) spacename := "johnsmith" namespaceName := "toolchain-member" @@ -904,7 +903,7 @@ func TestUpdateClusterResources(t *testing.T) { // given logger := zap.New(zap.UseDevMode(true)) - logf.SetLogger(logger) + log.SetLogger(logger) ctx := log.IntoContext(context.TODO(), logger) spacename := "johnsmith" namespaceName := "toolchain-member" diff --git a/controllers/nstemplateset/namespaces_test.go b/controllers/nstemplateset/namespaces_test.go index 8ff54828..c4d4315c 100644 --- a/controllers/nstemplateset/namespaces_test.go +++ b/controllers/nstemplateset/namespaces_test.go @@ -20,7 +20,6 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" "sigs.k8s.io/controller-runtime/pkg/reconcile" ) @@ -28,7 +27,7 @@ import ( func TestFindNamespace(t *testing.T) { logger := zap.New(zap.UseDevMode(true)) - logf.SetLogger(logger) + log.SetLogger(logger) namespaces := []corev1.Namespace{ { @@ -70,7 +69,7 @@ func TestNextNamespaceToProvisionOrUpdate(t *testing.T) { // given logger := zap.New(zap.UseDevMode(true)) - logf.SetLogger(logger) + log.SetLogger(logger) ctx := log.IntoContext(context.TODO(), logger) nsTmplSet := newNSTmplSet("toolchain-member", "johnsmith", "basic", withNamespaces("abcde11", "dev", "stage")) manager, fakeClient := prepareNamespacesManager(t, nsTmplSet) @@ -394,7 +393,7 @@ func TestEnsureNamespacesOK(t *testing.T) { // given logger := zap.New(zap.UseDevMode(true)) - logf.SetLogger(logger) + log.SetLogger(logger) ctx := log.IntoContext(context.TODO(), logger) spacename := "johnsmith" namespaceName := "toolchain-member" @@ -512,7 +511,7 @@ func TestEnsureNamespacesOK(t *testing.T) { func TestEnsureNamespacesFail(t *testing.T) { // given logger := zap.New(zap.UseDevMode(true)) - logf.SetLogger(logger) + log.SetLogger(logger) ctx := log.IntoContext(context.TODO(), logger) spacename := "johnsmith" namespaceName := "toolchain-member" @@ -663,7 +662,7 @@ func TestEnsureNamespacesFail(t *testing.T) { func TestDeleteNamespace(t *testing.T) { // given logger := zap.New(zap.UseDevMode(true)) - logf.SetLogger(logger) + log.SetLogger(logger) ctx := log.IntoContext(context.TODO(), logger) spacename := "johnsmith" namespaceName := "toolchain-member" @@ -795,7 +794,7 @@ func TestPromoteNamespaces(t *testing.T) { // given logger := zap.New(zap.UseDevMode(true)) - logf.SetLogger(logger) + log.SetLogger(logger) ctx := log.IntoContext(context.TODO(), logger) spacename := "johnsmith" namespaceName := "toolchain-member" @@ -1013,7 +1012,7 @@ func TestUpdateNamespaces(t *testing.T) { // given logger := zap.New(zap.UseDevMode(true)) - logf.SetLogger(logger) + log.SetLogger(logger) ctx := log.IntoContext(context.TODO(), logger) spacename := "johnsmith" namespaceName := "toolchain-member" @@ -1247,7 +1246,7 @@ func TestUpdateNamespaces(t *testing.T) { func TestIsUpToDateAndProvisioned(t *testing.T) { // given logger := zap.New(zap.UseDevMode(true)) - logf.SetLogger(logger) + log.SetLogger(logger) ctx := log.IntoContext(context.TODO(), logger) restore := test.SetEnvVarAndRestore(t, commonconfig.WatchNamespaceEnvVar, "my-member-operator-namespace") t.Cleanup(restore) diff --git a/controllers/nstemplateset/space_roles_test.go b/controllers/nstemplateset/space_roles_test.go index 6300d975..b17e385e 100644 --- a/controllers/nstemplateset/space_roles_test.go +++ b/controllers/nstemplateset/space_roles_test.go @@ -17,7 +17,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" ) @@ -25,7 +24,7 @@ func TestEnsureSpaceRoles(t *testing.T) { // given logger := zap.New(zap.UseDevMode(true)) - logf.SetLogger(logger) + log.SetLogger(logger) ctx := log.IntoContext(context.TODO(), logger) t.Run("success", func(t *testing.T) { diff --git a/controllers/nstemplateset/status_test.go b/controllers/nstemplateset/status_test.go index e51921bc..b859c501 100644 --- a/controllers/nstemplateset/status_test.go +++ b/controllers/nstemplateset/status_test.go @@ -19,13 +19,12 @@ import ( "k8s.io/client-go/kubernetes/scheme" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" ) func TestUpdateStatus(t *testing.T) { logger := zap.New(zap.UseDevMode(true)) - logf.SetLogger(logger) + log.SetLogger(logger) ctx := log.IntoContext(context.TODO(), logger) s := scheme.Scheme @@ -125,7 +124,7 @@ func TestUpdateStatus(t *testing.T) { // given nsTmplSet := newNSTmplSet(namespaceName, spacename, "basic", withNamespaces("abcde11", "dev", "code")) statusManager, _ := prepareStatusManager(t, nsTmplSet) - lctx := log.IntoContext(ctx, logf.Log.WithName("test")) + lctx := log.IntoContext(ctx, log.Log.WithName("test")) t.Run("status_updated", func(t *testing.T) { // given @@ -220,7 +219,7 @@ func TestUpdateStatus(t *testing.T) { } func TestUpdateStatusToProvisionedWhenPreviouslyWasSetToFailed(t *testing.T) { logger := zap.New(zap.UseDevMode(true)) - logf.SetLogger(logger) + log.SetLogger(logger) ctx := log.IntoContext(context.TODO(), logger) s := scheme.Scheme err := apis.AddToScheme(s) diff --git a/pkg/autoscaler/autoscaler.go b/pkg/autoscaler/autoscaler.go index 2b0656b8..3d9f26f5 100644 --- a/pkg/autoscaler/autoscaler.go +++ b/pkg/autoscaler/autoscaler.go @@ -15,10 +15,9 @@ import ( "k8s.io/apimachinery/pkg/runtime/serializer" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" - runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" ) -func Deploy(ctx context.Context, cl runtimeclient.Client, s *runtime.Scheme, namespace, requestsMemory string, replicas int) error { +func Deploy(ctx context.Context, cl client.Client, s *runtime.Scheme, namespace, requestsMemory string, replicas int) error { objs, err := getTemplateObjects(s, namespace, requestsMemory, replicas) if err != nil { return err @@ -61,7 +60,7 @@ func Delete(ctx context.Context, cl client.Client, s *runtime.Scheme, namespace return deleted, nil } -func getTemplateObjects(s *runtime.Scheme, namespace, requestsMemory string, replicas int) ([]runtimeclient.Object, error) { +func getTemplateObjects(s *runtime.Scheme, namespace, requestsMemory string, replicas int) ([]client.Object, error) { deployment, err := Asset("member-operator-autoscaler.yaml") if err != nil { return nil, err