Skip to content

Commit

Permalink
cosmetic changes and cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Feny Mehta <[email protected]>
  • Loading branch information
fbm3307 committed Dec 18, 2024
1 parent 8c31569 commit a05065e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 44 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/adm/register_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
34 changes: 17 additions & 17 deletions pkg/cmd/adm/register_member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down Expand Up @@ -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
})

Expand All @@ -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
})

Expand All @@ -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
})

Expand All @@ -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
})

Expand Down Expand Up @@ -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
})

Expand All @@ -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
})

Expand All @@ -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
})

Expand Down Expand Up @@ -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
})

Expand Down Expand Up @@ -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
})

Expand Down Expand Up @@ -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
})

Expand Down Expand Up @@ -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
})

Expand All @@ -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
})

Expand All @@ -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
})

Expand All @@ -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")
})

Expand Down
28 changes: 14 additions & 14 deletions pkg/cmd/adm/restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
})
Expand All @@ -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
})

Expand All @@ -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
})

Expand All @@ -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
})

Expand All @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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())

Expand Down
22 changes: 10 additions & 12 deletions pkg/cmd/adm/unregister_member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand All @@ -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")
})

Expand All @@ -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)
})
Expand All @@ -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
})

Expand All @@ -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
})

Expand All @@ -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
})

Expand All @@ -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
})

Expand All @@ -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")
}

0 comments on commit a05065e

Please sign in to comment.