Skip to content

Commit

Permalink
clean up packages being imported more than once (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoaresd authored Mar 22, 2024
1 parent 23beb33 commit ac7392a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 26 deletions.
3 changes: 1 addition & 2 deletions controllers/nstemplateset/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ 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"
)

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")
Expand Down
11 changes: 5 additions & 6 deletions controllers/nstemplateset/cluster_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
17 changes: 8 additions & 9 deletions controllers/nstemplateset/namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ 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"
)

func TestFindNamespace(t *testing.T) {

logger := zap.New(zap.UseDevMode(true))
logf.SetLogger(logger)
log.SetLogger(logger)

namespaces := []corev1.Namespace{
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions controllers/nstemplateset/space_roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ 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"
)

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) {
Expand Down
7 changes: 3 additions & 4 deletions controllers/nstemplateset/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions pkg/autoscaler/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ac7392a

Please sign in to comment.