diff --git a/pkg/cmd/adm/register_member.go b/pkg/cmd/adm/register_member.go index 46a934b..c9d240c 100644 --- a/pkg/cmd/adm/register_member.go +++ b/pkg/cmd/adm/register_member.go @@ -487,7 +487,7 @@ func (v *registerMemberValidated) perform(ctx *extendedCommandContext) error { } // restart Host Operator using the adm-restart command - if err := v.restartFunc(ctx.CommandContext, "host", v.getRegMemConfigFlagsAndClient); err != nil { + if err := v.restartFunc(ctx.CommandContext, configuration.HostName, v.getRegMemConfigFlagsAndClient); err != nil { return err } diff --git a/pkg/cmd/adm/register_member_test.go b/pkg/cmd/adm/register_member_test.go index 27c71ec..6fac77e 100644 --- a/pkg/cmd/adm/register_member_test.go +++ b/pkg/cmd/adm/register_member_test.go @@ -83,7 +83,7 @@ func TestRegisterMember(t *testing.T) { } // when - err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(ctx *clicontext.CommandContext, restartClusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) @@ -118,7 +118,7 @@ func TestRegisterMember(t *testing.T) { ctx := newExtendedCommandContext(term, newClient) // when - err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(ctx *clicontext.CommandContext, restartClusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) @@ -140,7 +140,7 @@ func TestRegisterMember(t *testing.T) { ctx := newExtendedCommandContext(term, newClient) // when - err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(ctx *clicontext.CommandContext, restartClusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) @@ -162,7 +162,7 @@ func TestRegisterMember(t *testing.T) { ctx := newExtendedCommandContext(term, newClient) // when - err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(ctx *clicontext.CommandContext, restartClusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) @@ -180,7 +180,7 @@ func TestRegisterMember(t *testing.T) { ctx := newExtendedCommandContext(term, newClient) // when - err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, true), func(ctx *clicontext.CommandContext, restartClusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, true), func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) @@ -217,7 +217,7 @@ func TestRegisterMember(t *testing.T) { mockCreateToolchainClusterWithReadyCondition(t, fakeClient) // when - err := registerMemberCluster(ctx, newRegisterMemberArgsWithSuffix(hostKubeconfig, memberKubeconfig, false, "2"), func(ctx *clicontext.CommandContext, restartClusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err := registerMemberCluster(ctx, newRegisterMemberArgsWithSuffix(hostKubeconfig, memberKubeconfig, false, "2"), func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) @@ -240,10 +240,10 @@ func TestRegisterMember(t *testing.T) { ctx2 := newExtendedCommandContext(term2, newClient) // when - err1 := registerMemberCluster(ctx1, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(ctx *clicontext.CommandContext, restartClusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err1 := registerMemberCluster(ctx1, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) - err2 := registerMemberCluster(ctx2, newRegisterMemberArgsWithSuffix(hostKubeconfig, memberKubeconfig, false, "1"), func(ctx *clicontext.CommandContext, restartClusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err2 := registerMemberCluster(ctx2, newRegisterMemberArgsWithSuffix(hostKubeconfig, memberKubeconfig, false, "1"), func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) @@ -267,10 +267,10 @@ func TestRegisterMember(t *testing.T) { ctx2 := newExtendedCommandContext(term2, newClient) // when - err1 := registerMemberCluster(ctx1, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(ctx *clicontext.CommandContext, restartClusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err1 := registerMemberCluster(ctx1, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) - err2 := registerMemberCluster(ctx2, newRegisterMemberArgsWithSuffix(hostKubeconfig, memberKubeconfig, false, ""), func(ctx *clicontext.CommandContext, restartClusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err2 := registerMemberCluster(ctx2, newRegisterMemberArgsWithSuffix(hostKubeconfig, memberKubeconfig, false, ""), func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) @@ -326,7 +326,7 @@ func TestRegisterMember(t *testing.T) { require.NoError(t, fakeClient.Create(context.TODO(), preexistingToolchainCluster2.DeepCopy())) // when - err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(ctx *clicontext.CommandContext, restartClusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) @@ -360,7 +360,7 @@ func TestRegisterMember(t *testing.T) { require.NoError(t, fakeClient.Create(context.TODO(), preexistingToolchainCluster.DeepCopy())) // when - err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(ctx *clicontext.CommandContext, restartClusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) @@ -394,7 +394,7 @@ func TestRegisterMember(t *testing.T) { require.NoError(t, fakeClient.Create(context.TODO(), preexistingToolchainCluster.DeepCopy())) // when - err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(ctx *clicontext.CommandContext, restartClusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) @@ -429,7 +429,7 @@ func TestRegisterMember(t *testing.T) { require.NoError(t, fakeClient.Create(context.TODO(), preexistingToolchainCluster.DeepCopy())) // when - err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(ctx *clicontext.CommandContext, restartClusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) @@ -448,7 +448,7 @@ func TestRegisterMember(t *testing.T) { ctx := newExtendedCommandContext(term, newClient) // when - err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(ctx *clicontext.CommandContext, restartClusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) @@ -469,7 +469,7 @@ func TestRegisterMember(t *testing.T) { ctx := newExtendedCommandContext(term, newClient) // when - err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(ctx *clicontext.CommandContext, restartClusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) @@ -491,7 +491,7 @@ func TestRegisterMember(t *testing.T) { ctx := newExtendedCommandContext(term, newClient) // when - err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(ctx *clicontext.CommandContext, restartClusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err := registerMemberCluster(ctx, newRegisterMemberArgsWith(hostKubeconfig, memberKubeconfig, false), func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return fmt.Errorf("restart did not happen") }) diff --git a/pkg/cmd/adm/restart_test.go b/pkg/cmd/adm/restart_test.go index 6ba355a..d100542 100644 --- a/pkg/cmd/adm/restart_test.go +++ b/pkg/cmd/adm/restart_test.go @@ -91,7 +91,7 @@ func TestKubectlRolloutFunctionality(t *testing.T) { ctx := clicontext.NewCommandContext(term, newClient) //when - err := restartDeployments(ctx, fakeClient, HostNamespacedName.Namespace, func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error { + err := restartDeployments(ctx, fakeClient, HostNamespacedName.Namespace, func(ctx *clicontext.CommandContext, _ appsv1.Deployment) error { return checkRolloutStatus(ctx, tf, streams, *hostDep) }, func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error { return restartNonOlmDeployments(ctx, deployment, tf, streams) @@ -123,7 +123,7 @@ func TestKubectlRolloutFunctionality(t *testing.T) { ctx := clicontext.NewCommandContext(term, newClient) //when - err := restartDeployments(ctx, fakeClient, HostNamespacedName.Namespace, func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error { + err := restartDeployments(ctx, fakeClient, HostNamespacedName.Namespace, func(ctx *clicontext.CommandContext, _ appsv1.Deployment) error { return checkRolloutStatus(ctx, tf, streams, *hostDep) }, func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error { return restartNonOlmDeployments(ctx, deployment, tf, streams) @@ -140,7 +140,7 @@ func TestKubectlRolloutFunctionality(t *testing.T) { ctx := clicontext.NewCommandContext(term, newClient) //when - err := restartDeployments(ctx, fakeClient, HostNamespacedName.Namespace, func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error { + err := restartDeployments(ctx, fakeClient, HostNamespacedName.Namespace, func(ctx *clicontext.CommandContext, _ appsv1.Deployment) error { return checkRolloutStatus(ctx, tf, streams, *hostDep) }, func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error { return restartNonOlmDeployments(ctx, deployment, tf, streams) @@ -181,10 +181,10 @@ func TestRestartDeployment(t *testing.T) { //when err := restartDeployments(ctx, fakeClient, "toolchain-host-operator", - func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error { + func(_ *clicontext.CommandContext, deployment appsv1.Deployment) error { require.Equal(t, "host-operator-controller-manager", deployment.Name) return nil - }, func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error { + }, func(_ *clicontext.CommandContext, deployment appsv1.Deployment) error { require.Equal(t, regServDeployment, deployment) return nil }) @@ -200,9 +200,9 @@ func TestRestartDeployment(t *testing.T) { //when err := restartDeployments(ctx, fakeClient, "toolchain-host-operator", - func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error { + func(_ *clicontext.CommandContext, _ appsv1.Deployment) error { return nil - }, func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error { + }, func(_ *clicontext.CommandContext, _ appsv1.Deployment) error { return nil }) @@ -228,9 +228,9 @@ func TestRestartDeployment(t *testing.T) { //when err := restartDeployments(ctx, fakeClient, "toolchain-host-operator", - func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error { + func(_ *clicontext.CommandContext, _ appsv1.Deployment) error { return nil - }, func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error { + }, func(_ *clicontext.CommandContext, _ appsv1.Deployment) error { return nil }) @@ -246,9 +246,9 @@ func TestRestartDeployment(t *testing.T) { expectedErr := fmt.Errorf("Could not do rollout restart of the deployment") //when err := restartDeployments(ctx, fakeClient, "toolchain-host-operator", - func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error { + func(_ *clicontext.CommandContext, _ appsv1.Deployment) error { return nil - }, func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error { + }, func(_ *clicontext.CommandContext, _ appsv1.Deployment) error { return expectedErr }) @@ -263,7 +263,7 @@ func TestRestartDeployment(t *testing.T) { //when err := restartDeployments(ctx, fakeClient, "toolchain-host-operator", - func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error { + func(_ *clicontext.CommandContext, _ appsv1.Deployment) error { return nil }, nil) @@ -278,7 +278,7 @@ func TestRestartDeployment(t *testing.T) { expectedErr := fmt.Errorf("Could not check the status of the deployment") //when err := restartDeployments(ctx, fakeClient, "toolchain-host-operator", - func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error { + func(_ *clicontext.CommandContext, _ appsv1.Deployment) error { return expectedErr }, nil) @@ -310,7 +310,7 @@ func TestRestartAutoScalerDeployment(t *testing.T) { ctx := clicontext.NewCommandContext(term, newClient) //when err := restartDeployments(ctx, fakeClient, "toolchain-member-operator", - func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error { + func(_ *clicontext.CommandContext, _ appsv1.Deployment) error { return nil }, mockRolloutRestartInterceptor()) diff --git a/pkg/cmd/adm/unregister_member_test.go b/pkg/cmd/adm/unregister_member_test.go index 2885e1f..0e42cdd 100644 --- a/pkg/cmd/adm/unregister_member_test.go +++ b/pkg/cmd/adm/unregister_member_test.go @@ -21,7 +21,7 @@ func TestUnregisterMemberWhenAnswerIsY(t *testing.T) { ctx := clicontext.NewCommandContext(term, newClient) // when - err := UnregisterMemberCluster(ctx, "member1", func(ctx *clicontext.CommandContext, clusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err := UnregisterMemberCluster(ctx, "member1", func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) @@ -46,7 +46,7 @@ func TestUnregisterMemberWhenRestartError(t *testing.T) { ctx := clicontext.NewCommandContext(term, newClient) // when - err := UnregisterMemberCluster(ctx, "member1", func(ctx *clicontext.CommandContext, clusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err := UnregisterMemberCluster(ctx, "member1", func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return fmt.Errorf("restart did not happen") }) @@ -65,7 +65,7 @@ func TestUnregisterMemberCallsRestart(t *testing.T) { ctxAct := clicontext.NewCommandContext(term, newClient) called := 0 // when - err := UnregisterMemberCluster(ctxAct, "member1", func(ctx *clicontext.CommandContext, restartClusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err := UnregisterMemberCluster(ctxAct, "member1", func(ctx *clicontext.CommandContext, restartClusterName string, _ ConfigFlagsAndClientGetterFunc) error { called++ return mockRestart(ctx, restartClusterName, getConfigFlagsAndClient) }) @@ -84,7 +84,7 @@ func TestUnregisterMemberWhenAnswerIsN(t *testing.T) { ctx := clicontext.NewCommandContext(term, newClient) // when - err := UnregisterMemberCluster(ctx, "member1", func(ctx *clicontext.CommandContext, clusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err := UnregisterMemberCluster(ctx, "member1", func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) @@ -107,7 +107,7 @@ func TestUnregisterMemberWhenNotFound(t *testing.T) { ctx := clicontext.NewCommandContext(term, newClient) // when - err := UnregisterMemberCluster(ctx, "member1", func(ctx *clicontext.CommandContext, clusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err := UnregisterMemberCluster(ctx, "member1", func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) @@ -130,7 +130,7 @@ func TestUnregisterMemberWhenUnknownClusterName(t *testing.T) { ctx := clicontext.NewCommandContext(term, newClient) // when - err := UnregisterMemberCluster(ctx, "some", func(ctx *clicontext.CommandContext, clusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err := UnregisterMemberCluster(ctx, "some", func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) @@ -155,7 +155,7 @@ func TestUnregisterMemberLacksPermissions(t *testing.T) { ctx := clicontext.NewCommandContext(term, newClient) // when - err := UnregisterMemberCluster(ctx, "member1", func(ctx *clicontext.CommandContext, clusterName string, cfcGetter ConfigFlagsAndClientGetterFunc) error { + err := UnregisterMemberCluster(ctx, "member1", func(_ *clicontext.CommandContext, _ string, _ ConfigFlagsAndClientGetterFunc) error { return nil }) @@ -165,12 +165,10 @@ func TestUnregisterMemberLacksPermissions(t *testing.T) { } func mockRestart(ctx *clicontext.CommandContext, clusterName string, cfc ConfigFlagsAndClientGetterFunc) error { - if clusterName == "host" && ctx != nil { - return nil - } - _, _, err := cfc(ctx, clusterName) - if err == nil { + _, _, cfcerr := cfc(ctx, clusterName) + if clusterName == "host" && ctx != nil && cfcerr == nil { return nil } + return fmt.Errorf("cluster name is wrong") }