Skip to content

Commit

Permalink
postgres/migrate: rename Cleanup to Finalize
Browse files Browse the repository at this point in the history
This better expresses the actual intent of the command.

Co-authored-by: Morten Lied Johansen <morten.lied.johansen@nav.no>
  • Loading branch information
tronghn and mortenlj committed Oct 1, 2024
1 parent ac1858b commit 6433221
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"github.com/urfave/cli/v2"
)

func cleanupCommand() *cli.Command {
func finalizeCommand() *cli.Command {
return &cli.Command{
Name: "cleanup",
Usage: "Clean up after migration",
UsageText: "nais postgres migrate cleanup APP_NAME NAMESPACE TARGET_INSTANCE_NAME",
Description: "Cleanup will remove the source instance and associated resources after a successful migration.",
Name: "finalize",
Usage: "Finalize the migration",
UsageText: "nais postgres migrate finalize APP_NAME NAMESPACE TARGET_INSTANCE_NAME",
Description: "Finalize will remove the source instance and associated resources after a successful migration.",
Args: true,
Flags: []cli.Flag{
kubeConfigFlag(),
Expand All @@ -29,7 +29,7 @@ func cleanupCommand() *cli.Command {
client := k8s.SetupClient(k8s.WithKubeContext(cluster))
migrator := migrate.NewMigrator(client, cfg)

err := migrator.Cleanup(context.Background())
err := migrator.Finalize(context.Background())
if err != nil {
return fmt.Errorf("error cleaning up instance: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/postgrescmd/migratecmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package migratecmd

import (
"fmt"

"github.com/nais/cli/pkg/gcp"
"github.com/nais/cli/pkg/option"
"github.com/nais/cli/pkg/postgres/migrate/config"
Expand All @@ -22,7 +23,7 @@ func Command() *cli.Command {
Subcommands: []*cli.Command{
setupCommand(),
promoteCommand(),
cleanupCommand(),
finalizeCommand(),
rollbackCommand(),
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ import (
"fmt"
)

const CleanupStartedMessage = `
Cleanup has been started successfully.
const FinalizeStartedMessage = `
Finalize has been started successfully.
To monitor the cleanup, run the following command in a separate terminal:
To monitor the finalize, run the following command in a separate terminal:
kubectl logs -f -l %s -n %s
Pausing to wait for cleanup job to complete in order to do final cleanup actions ...
Pausing to wait for finalize job to complete in order to do final finalize actions ...
`

const CleanupSuccessMessage = `
Cleanup has completed successfully.
const FinalizeSuccessMessage = `
Finalize has completed successfully.
The old instance has been deleted and the migration is complete.
Congratulations, you're all done! 🎉
`

func (m *Migrator) Cleanup(ctx context.Context) error {
func (m *Migrator) Finalize(ctx context.Context) error {
fmt.Println("Resolving config")
cfgMap, err := m.cfg.PopulateFromConfigMap(ctx, m.client)
if err != nil {
Expand All @@ -41,15 +41,15 @@ Only proceed if you are sure that the migration was successful and that your app
return err
}

jobName, err := m.doNaisJob(ctx, cfgMap, CommandCleanup)
jobName, err := m.doNaisJob(ctx, cfgMap, CommandFinalize)
if err != nil {
return err
}

label := m.kubectlLabelSelector(CommandCleanup)
fmt.Printf(CleanupStartedMessage, label, m.cfg.Namespace)
label := m.kubectlLabelSelector(CommandFinalize)
fmt.Printf(FinalizeStartedMessage, label, m.cfg.Namespace)

err = m.waitForJobCompletion(ctx, jobName, CommandCleanup)
err = m.waitForJobCompletion(ctx, jobName, CommandFinalize)
if err != nil {
return err
}
Expand All @@ -59,6 +59,6 @@ Only proceed if you are sure that the migration was successful and that your app
return err
}

fmt.Print(CleanupSuccessMessage)
fmt.Print(FinalizeSuccessMessage)
return nil
}
9 changes: 5 additions & 4 deletions pkg/postgres/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/nais/cli/pkg/postgres/migrate/config"
"github.com/sethvargo/go-retry"
"net/http"
"os"
"strings"
"time"

"github.com/nais/cli/pkg/postgres/migrate/config"
"github.com/sethvargo/go-retry"

nais_io_v1 "github.com/nais/liberator/pkg/apis/nais.io/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -28,7 +29,7 @@ func (c Command) JobName(cfg config.Config) string {
}

const (
CommandCleanup Command = "cleanup"
CommandFinalize Command = "finalize"
CommandPromote Command = "promote"
CommandRollback Command = "rollback"
CommandSetup Command = "setup"
Expand Down Expand Up @@ -182,7 +183,7 @@ func makeRoleBinding(cfg config.Config) *rbacv1.RoleBinding {
},
{
Kind: "ServiceAccount",
Name: CommandCleanup.JobName(cfg),
Name: CommandFinalize.JobName(cfg),
},
{
Kind: "ServiceAccount",
Expand Down
4 changes: 2 additions & 2 deletions pkg/postgres/migrate/promote.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ The promote will take some time to complete, you can check completion status wit
When promotion is complete, your application should be up and running with the new database instance.
At this point it is important to verify that your application works as expected, and that all data is present.
Once you are satisfied that everything works as expected, you must perform the final cleanup step:
nais postgres migrate cleanup %s %s %s
Once you are satisfied that everything works as expected, you must perform the final finalize step:
nais postgres migrate finalize %s %s %s
If things are not working as expected, and you need to rollback to the previous database instance, you can run:
nais postgres migrate rollback %s %s %s
Expand Down
2 changes: 1 addition & 1 deletion pkg/postgres/migrate/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Rollback has been started successfully.
To monitor the rollback, run the following command in a separate terminal:
kubectl logs -f -l %s -n %s
Pausing to wait for rollback job to complete in order to do final cleanup actions ...
Pausing to wait for rollback job to complete in order to do final finalize actions ...
`

const RollbackSuccessMessage = `
Expand Down

0 comments on commit 6433221

Please sign in to comment.