Skip to content

Commit

Permalink
some changes to status func
Browse files Browse the repository at this point in the history
Signed-off-by: Feny Mehta <[email protected]>
  • Loading branch information
fbm3307 committed Nov 14, 2024
1 parent a4b5198 commit 9b889cc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
16 changes: 8 additions & 8 deletions pkg/cmd/adm/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

type (
NonOperatorDeploymentsRestarterFunc func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error
RolloutStatusCheckerFunc func(ctx *clicontext.CommandContext, labelSelector string) error
RolloutStatusCheckerFunc func(ctx *clicontext.CommandContext, labelSelector string, deployment appsv1.Deployment) error
)

// NewRestartCmd() is a function to restart the whole operator, it relies on the target cluster and fetches the cluster config
Expand Down Expand Up @@ -86,8 +86,8 @@ func restart(ctx *clicontext.CommandContext, clusterName string) error {
}

//return restartDeployment(ctx, cl, cfg.OperatorNamespace, factory, ioStreams, checkRolloutStatus, restartNonOperatorDeployments)
return restartDeployments(ctx, cl, cfg.OperatorNamespace, func(ctx *clicontext.CommandContext, labelSelector string) error {
return checkRolloutStatus(ctx, factory, ioStreams, labelSelector)
return restartDeployments(ctx, cl, cfg.OperatorNamespace, func(ctx *clicontext.CommandContext, labelSelector string, deployment appsv1.Deployment) error {
return checkRolloutStatus(ctx, factory, ioStreams, labelSelector, deployment)
}, func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error {
return restartNonOlmDeployments(ctx, deployment, factory, ioStreams)
})

Check warning on line 93 in pkg/cmd/adm/restart.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/adm/restart.go#L89-L93

Added lines #L89 - L93 were not covered by tests
Expand Down Expand Up @@ -117,7 +117,7 @@ func restartDeployments(ctx *clicontext.CommandContext, cl runtimeclient.Client,

ctx.Printlnf("Checking the status of the deleted pod's deployment %v", olmOperatorDeployment.Name)
//check the rollout status
if err := checker(ctx, "kubesaw-control-plane=kubesaw-controller-manager"); err != nil {
if err := checker(ctx, "kubesaw-control-plane=kubesaw-controller-manager", olmOperatorDeployment); err != nil {
return err
}
}
Expand All @@ -140,7 +140,7 @@ func restartDeployments(ctx *clicontext.CommandContext, cl runtimeclient.Client,
}
//check the rollout status
ctx.Printlnf("Checking the status of the rolled out deployment %v", nonOlmDeployment.Name)
if err := checker(ctx, "toolchain.dev.openshift.com/provider=codeready-toolchain"); err != nil {
if err := checker(ctx, "toolchain.dev.openshift.com/provider=codeready-toolchain", nonOlmDeployment); err != nil {
return err
}

Check warning on line 145 in pkg/cmd/adm/restart.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/adm/restart.go#L144-L145

Added lines #L144 - L145 were not covered by tests
return nil
Expand Down Expand Up @@ -192,15 +192,15 @@ func restartNonOlmDeployments(ctx *clicontext.CommandContext, deployment appsv1.
return o.RunRestart()
}

func checkRolloutStatus(ctx *clicontext.CommandContext, f cmdutil.Factory, ioStreams genericclioptions.IOStreams, labelSelector string) error {
func checkRolloutStatus(ctx *clicontext.CommandContext, f cmdutil.Factory, ioStreams genericclioptions.IOStreams, labelSelector string, deployment appsv1.Deployment) error {

Check failure on line 195 in pkg/cmd/adm/restart.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint

`checkRolloutStatus` - `labelSelector` is unused (unparam)

cmd := kubectlrollout.NewRolloutStatusOptions(ioStreams)

if err := cmd.Complete(f, []string{"deployment"}); err != nil {
if err := cmd.Complete(f, []string{"deployment/" + deployment.Name}); err != nil {
return err

Check warning on line 200 in pkg/cmd/adm/restart.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/adm/restart.go#L200

Added line #L200 was not covered by tests
}

cmd.LabelSelector = labelSelector
//cmd.LabelSelector = labelSelector
if err := cmd.Validate(); err != nil {
return err
}

Check warning on line 206 in pkg/cmd/adm/restart.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/adm/restart.go#L205-L206

Added lines #L205 - L206 were not covered by tests
Expand Down
38 changes: 13 additions & 25 deletions pkg/cmd/adm/restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func TestKubectlRolloutFunctionality(t *testing.T) {
ctx := clicontext.NewCommandContext(term, newClient)

//when
err := restartDeployments(ctx, fakeClient, HostNamespacedName.Namespace, func(ctx *clicontext.CommandContext, labelSelector string) error {
return checkRolloutStatus(ctx, tf, streams, labelSelector)
err := restartDeployments(ctx, fakeClient, HostNamespacedName.Namespace, func(ctx *clicontext.CommandContext, labelSelector string, deployment appsv1.Deployment) error {
return checkRolloutStatus(ctx, tf, streams, labelSelector, *hostDep)
}, func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error {
return restartNonOlmDeployments(ctx, deployment, tf, streams)
})
Expand Down Expand Up @@ -124,8 +124,8 @@ func TestKubectlRolloutFunctionality(t *testing.T) {
ctx := clicontext.NewCommandContext(term, newClient)

//when
err := restartDeployments(ctx, fakeClient, HostNamespacedName.Namespace, func(ctx *clicontext.CommandContext, labelSelector string) error {
return checkRolloutStatus(ctx, tf, streams, labelSelector)
err := restartDeployments(ctx, fakeClient, HostNamespacedName.Namespace, func(ctx *clicontext.CommandContext, labelSelector string, deployment appsv1.Deployment) error {
return checkRolloutStatus(ctx, tf, streams, labelSelector, *hostDep)
}, func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error {
return restartNonOlmDeployments(ctx, deployment, tf, streams)
})
Expand All @@ -141,8 +141,8 @@ func TestKubectlRolloutFunctionality(t *testing.T) {
ctx := clicontext.NewCommandContext(term, newClient)

//when
err := restartDeployments(ctx, fakeClient, HostNamespacedName.Namespace, func(ctx *clicontext.CommandContext, labelSelector string) error {
return checkRolloutStatus(ctx, tf, streams, labelSelector)
err := restartDeployments(ctx, fakeClient, HostNamespacedName.Namespace, func(ctx *clicontext.CommandContext, labelSelector string, deployment appsv1.Deployment) error {
return checkRolloutStatus(ctx, tf, streams, labelSelector, *hostDep)
}, func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error {
return restartNonOlmDeployments(ctx, deployment, tf, streams)
})
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestRestartDeployment(t *testing.T) {

//when
err := restartDeployments(ctx, fakeClient, "toolchain-host-operator",
func(ctx *clicontext.CommandContext, labelSelector string) error {
func(ctx *clicontext.CommandContext, labelSelector string, deployment appsv1.Deployment) error {
require.Equal(t, "toolchain.dev.openshift.com/provider=codeready-toolchain", labelSelector)
return nil
}, func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error {
Expand All @@ -202,7 +202,7 @@ func TestRestartDeployment(t *testing.T) {

//when
err := restartDeployments(ctx, fakeClient, "toolchain-host-operator",
func(ctx *clicontext.CommandContext, labelSelector string) error {
func(ctx *clicontext.CommandContext, labelSelector string, deployment appsv1.Deployment) error {
return nil
}, func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error {
return nil
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestRestartDeployment(t *testing.T) {

//when
err := restartDeployments(ctx, fakeClient, "toolchain-host-operator",
func(ctx *clicontext.CommandContext, labelSelector string) error {
func(ctx *clicontext.CommandContext, labelSelector string, deployment appsv1.Deployment) error {
return nil
}, func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error {
return nil
Expand All @@ -248,7 +248,7 @@ 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, labelSelector string) error {
func(ctx *clicontext.CommandContext, labelSelector string, deployment appsv1.Deployment) error {
return nil
}, func(ctx *clicontext.CommandContext, deployment appsv1.Deployment) error {
return expectedErr
Expand All @@ -265,7 +265,7 @@ func TestRestartDeployment(t *testing.T) {

//when
err := restartDeployments(ctx, fakeClient, "toolchain-host-operator",
func(ctx *clicontext.CommandContext, labelSelector string) error {
func(ctx *clicontext.CommandContext, labelSelector string, deployment appsv1.Deployment) error {
return nil
}, nil)

Expand All @@ -280,7 +280,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, labelSelector string) error {
func(ctx *clicontext.CommandContext, labelSelector string, deployment appsv1.Deployment) error {
return expectedErr
}, nil)

Expand Down Expand Up @@ -313,7 +313,7 @@ func TestRestartAutoScalerDeployment(t *testing.T) {
ctx := clicontext.NewCommandContext(term, newClient)
//when
err := restartDeployments(ctx, fakeClient, "toolchain-member-operator",
func(ctx *clicontext.CommandContext, labelSelector string) error {
func(ctx *clicontext.CommandContext, labelSelector string, deployment appsv1.Deployment) error {
return nil
}, mockRolloutRestartInterceptor())

Expand Down Expand Up @@ -359,18 +359,6 @@ func TestRestart(t *testing.T) {
require.NotContains(t, term.Output(), "Fetching the current OLM and non-OLM deployments of the operator in")

})
t.Run("fails when no factory and stream provided", func(t *testing.T) {
term := NewFakeTerminalWithResponse("Y")
//given
newClient, _ := NewFakeClients(t, toolchainCluster, hostDeployment, hostPod)
ctx := clicontext.NewCommandContext(term, newClient)
//when
err := restart(ctx, "host")

//then
require.Error(t, err, "the server doesn't have a resource type deployment")

})
}

func newDeployment(namespacedName types.NamespacedName, replicas int32) *appsv1.Deployment { //nolint:unparam
Expand Down

0 comments on commit 9b889cc

Please sign in to comment.