mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
refactor: simplify and speed up plan output formatting by removing name resolver dependency
This commit is contained in:
@@ -125,15 +125,9 @@ func runDeploy(ctx context.Context, uncli *cli.CLI, opts deployOptions) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Initialise a machine and container name resolver to properly format the plan output.
|
||||
resolver, err := clusterClient.ServiceOperationNameResolver(ctx, svc)
|
||||
if err != nil {
|
||||
return fmt.Errorf("create machine and container name resolver for service operations: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
fmt.Println("Deployment plan:")
|
||||
fmt.Println(plan.Format(resolver))
|
||||
fmt.Println(plan.Format())
|
||||
fmt.Println()
|
||||
|
||||
confirmed, err := tui.Confirm("")
|
||||
|
||||
+1
-23
@@ -11,11 +11,9 @@ import (
|
||||
"github.com/docker/compose/v2/pkg/progress"
|
||||
"github.com/psviderski/uncloud/internal/cli"
|
||||
"github.com/psviderski/uncloud/internal/cli/tui"
|
||||
"github.com/psviderski/uncloud/pkg/api"
|
||||
"github.com/psviderski/uncloud/pkg/client"
|
||||
"github.com/psviderski/uncloud/pkg/client/compose"
|
||||
"github.com/psviderski/uncloud/pkg/client/deploy"
|
||||
"github.com/psviderski/uncloud/pkg/client/deploy/operation"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -193,10 +191,7 @@ func runDeploy(ctx context.Context, uncli *cli.CLI, opts deployOptions) error {
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
if err = printPlan(ctx, clusterClient, plan); err != nil {
|
||||
return fmt.Errorf("print deployment plan: %w", err)
|
||||
}
|
||||
fmt.Println()
|
||||
fmt.Println(plan.Format())
|
||||
|
||||
// Ask for plan confirmation before proceeding with the deployment unless auto-confirmed with --yes.
|
||||
if !opts.yes {
|
||||
@@ -235,20 +230,3 @@ func runDeploy(ctx context.Context, uncli *cli.CLI, opts deployOptions) error {
|
||||
return nil
|
||||
}, uncli.ProgressOut(), title)
|
||||
}
|
||||
|
||||
func printPlan(ctx context.Context, cli *client.Client, plan compose.Plan) error {
|
||||
resolvers := make(map[string]operation.NameResolver)
|
||||
for _, svcPlan := range plan.Services {
|
||||
svc, err := cli.InspectService(ctx, svcPlan.ServiceID)
|
||||
if err != nil && !errors.Is(err, api.ErrNotFound) {
|
||||
return fmt.Errorf("inspect service: %w", err)
|
||||
}
|
||||
resolver, err := cli.ServiceOperationNameResolver(ctx, svc)
|
||||
if err != nil {
|
||||
return fmt.Errorf("create resolver for service '%s': %w", svcPlan.ServiceName, err)
|
||||
}
|
||||
resolvers[svcPlan.ServiceID] = resolver
|
||||
}
|
||||
fmt.Print(plan.Format(resolvers))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -214,15 +214,8 @@ func add(ctx context.Context, uncli *cli.CLI, remoteMachine *cli.RemoteMachine,
|
||||
if len(plan.Operations) == 0 {
|
||||
fmt.Printf("%s service is up to date.\n", client.CaddyServiceName)
|
||||
} else {
|
||||
// Initialise a machine and container name resolver to properly format the plan output.
|
||||
resolver, err := clusterClient.ServiceOperationNameResolver(ctx, caddySvc)
|
||||
if err != nil {
|
||||
return fmt.Errorf("create machine and container name resolver for service operations: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println("caddy deployment plan:")
|
||||
fmt.Println(plan.Format(resolver))
|
||||
fmt.Println()
|
||||
fmt.Println(plan.Format())
|
||||
|
||||
if !opts.yes {
|
||||
confirmed, err := tui.Confirm("")
|
||||
|
||||
@@ -91,14 +91,8 @@ func scale(ctx context.Context, uncli *cli.CLI, opts scaleOptions) error {
|
||||
}
|
||||
|
||||
if opts.replicas < currentReplicas {
|
||||
// Initialise a machine and container name resolver to properly format the plan output.
|
||||
resolver, err := clusterClient.ServiceOperationNameResolver(ctx, svc)
|
||||
if err != nil {
|
||||
return fmt.Errorf("create machine and container name resolver for service operations: %w", err)
|
||||
}
|
||||
|
||||
fmt.Printf("Scaling plan for service %s (%d → %d replicas):\n", svc.Name, currentReplicas, opts.replicas)
|
||||
fmt.Println(plan.Format(resolver))
|
||||
fmt.Println(plan.Format())
|
||||
fmt.Println()
|
||||
|
||||
// Ask for confirmation before scaling down as it may cause data loss.
|
||||
|
||||
Reference in New Issue
Block a user