Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions otdfctl/cmd/migrate/namespaced_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
func migrateNamespacedPolicyCmd() *cobra.Command {
doc := man.Docs.GetCommand("migrate/namespaced-policy", man.WithRun(migrateNamespacedPolicy))
doc.Args = cobra.NoArgs
doc.Hidden = true
doc.Flags().StringP(
doc.GetDocFlag("scope").Name,
doc.GetDocFlag("scope").Shorthand,
Expand Down Expand Up @@ -46,7 +45,7 @@ func migrateNamespacedPolicy(cmd *cobra.Command, args []string) {
plannerOpts = append(plannerOpts, namespacedpolicy.WithInteractiveReviewer(namespacedpolicy.NewHuhInteractiveReviewer(&h, prompter)))
}

planner, err := namespacedpolicy.NewPlanner(&h, scopeCSV, plannerOpts...)
planner, err := namespacedpolicy.NewMigrationPlanner(&h, scopeCSV, plannerOpts...)
if err != nil {
cli.ExitWithError("could not create namespaced-policy planner", err)
}
Expand All @@ -65,39 +64,39 @@ func migrateNamespacedPolicy(cmd *cobra.Command, args []string) {
}
}

func confirmNamespacedPolicyCommit(cmd *cobra.Command, plan *namespacedpolicy.Plan, interactive bool, prompter namespacedpolicy.InteractivePrompter) error {
func confirmNamespacedPolicyCommit(cmd *cobra.Command, plan *namespacedpolicy.MigrationPlan, interactive bool, prompter namespacedpolicy.InteractivePrompter) error {
if !interactive {
return nil
}
if err := namespacedpolicy.ConfirmNamespacedPolicyBackup(cmd.Context(), prompter); err != nil {
return err
}
if err := namespacedpolicy.ReviewNamespacedPolicyInteractiveCommit(cmd.Context(), plan, prompter); err != nil {
if err := namespacedpolicy.ConfirmMigrationPlan(cmd.Context(), plan, prompter); err != nil {
return err
}
return nil
}

func executeNamespacedPolicyCommit(cmd *cobra.Command, h namespacedpolicy.ExecutorHandler, plan *namespacedpolicy.Plan, interactive bool, prompter namespacedpolicy.InteractivePrompter) {
func executeNamespacedPolicyCommit(cmd *cobra.Command, h namespacedpolicy.ExecutorHandler, plan *namespacedpolicy.MigrationPlan, interactive bool, prompter namespacedpolicy.InteractivePrompter) {
if err := confirmNamespacedPolicyCommit(cmd, plan, interactive, prompter); err != nil {
if errors.Is(err, namespacedpolicy.ErrNamespacedPolicyBackupNotConfirmed) || errors.Is(err, namespacedpolicy.ErrInteractiveReviewAborted) {
writeNamespacedPolicySummary(cmd, plan, false, "aborted")
}
cli.ExitWithError("could not review namespaced-policy commit", err)
}

executor, err := namespacedpolicy.NewExecutor(h)
executor, err := namespacedpolicy.NewMigrationExecutor(h)
if err != nil {
cli.ExitWithError("could not create namespaced-policy executor", err)
}

if err := executor.Execute(cmd.Context(), plan); err != nil {
if err := executor.ExecuteMigration(cmd.Context(), plan); err != nil {
writeNamespacedPolicySummary(cmd, plan, true, "failure")
cli.ExitWithError("could not execute namespaced-policy commit", err)
}
}

func writeNamespacedPolicySummary(cmd *cobra.Command, plan *namespacedpolicy.Plan, commit bool, result string) {
func writeNamespacedPolicySummary(cmd *cobra.Command, plan *namespacedpolicy.MigrationPlan, commit bool, result string) {
if _, err := cmd.OutOrStdout().Write([]byte(namespacedpolicy.RenderNamespacedPolicySummaryWithResult(plan, commit, result) + "\n")); err != nil {
cli.ExitWithError("could not write namespaced-policy summary", err)
}
Expand Down
3 changes: 1 addition & 2 deletions otdfctl/cmd/migrate/prune/namespaced_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
func pruneNamespacedPolicyCmd() *cobra.Command {
doc := man.Docs.GetCommand("migrate/prune/namespaced-policy", man.WithRun(pruneNamespacedPolicy))
doc.Args = cobra.NoArgs
doc.Hidden = true
doc.Flags().StringP(
doc.GetDocFlag("scope").Name,
doc.GetDocFlag("scope").Shorthand,
Expand Down Expand Up @@ -79,7 +78,7 @@ func executeNamespacedPolicyPruneCommit(cmd *cobra.Command, h namespacedpolicy.E
}
}

executor, err := namespacedpolicy.NewExecutor(h)
executor, err := namespacedpolicy.NewPruneExecutor(h)
if err != nil {
cli.ExitWithError("could not create namespaced-policy prune executor", err)
}
Expand Down
1 change: 0 additions & 1 deletion otdfctl/cmd/migrate/prune/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ var (
)

func InitCommands() {
Cmd.Hidden = true
Cmd.AddCommand(pruneNamespacedPolicyCmd())
}
19 changes: 5 additions & 14 deletions otdfctl/docs/man/migrate/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,11 @@ command:
default: false
---

`migrate` groups commands used to migrate policy resources and related state.
`migrate` groups migration and migration-related cleanup workflows.

The end-to-end workflow is not implemented yet, but the command surface is in place.
Use this command family when you want to inspect a migration plan, review changes interactively, or apply migration-related updates.

Available subcommands currently include `namespaced-policy` for migration planning and execution, and `prune` for cleanup flows.
The parent `migrate` command owns flags shared by its subcommands:

The parent `migrate` command owns the shared `--commit` and `--interactive` flags.

`migrate prune` is separate from the existing destructive `otdfctl policy subject-condition-sets prune` command.

## Planned examples

```shell
otdfctl migrate namespaced-policy --scope=registered-resources --output=policy-migration.json
otdfctl migrate prune namespaced-policy --scope=registered-resources
otdfctl migrate namespaced-policy --scope=actions,subject-mappings,registered-resources --output=policy-migration.json --commit
```
- `--commit`, `-c`: apply the planned changes instead of only rendering the plan
- `--interactive`, `-i`: walk through the plan interactively before continuing
Loading
Loading