-
Notifications
You must be signed in to change notification settings - Fork 9
/
migration.go
85 lines (69 loc) · 2.38 KB
/
migration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package orchestration
import (
"context"
"fmt"
"namespacelabs.dev/foundation/internal/console"
"namespacelabs.dev/foundation/internal/fnerrors"
"namespacelabs.dev/foundation/internal/planning/deploy"
"namespacelabs.dev/foundation/internal/runtime"
"namespacelabs.dev/foundation/schema"
orchpb "namespacelabs.dev/foundation/schema/orchestration"
"namespacelabs.dev/foundation/std/cfg"
"namespacelabs.dev/foundation/std/execution"
"namespacelabs.dev/foundation/std/tasks"
)
func Deploy(ctx context.Context, env cfg.Context, cluster runtime.ClusterNamespace, plan *schema.DeployPlan, wait, outputProgress bool) error {
if !UseOrchestrator {
if !wait {
return fnerrors.BadInputError("waiting is mandatory without the orchestrator")
}
p := execution.NewPlan(plan.Program.Invocation...)
// Make sure that the cluster is accessible to a serialized invocation implementation.
return execution.Execute(ctx, "deployment.execute", p,
deploy.MaybeRenderBlock(env, cluster, outputProgress),
execution.FromContext(env),
runtime.InjectCluster(cluster))
}
return tasks.Action("orchestrator.deploy").Scope(schema.PackageNames(plan.FocusServer...)...).
Run(ctx, func(ctx context.Context) error {
debug := console.Debug(ctx)
fmt.Fprintf(debug, "deploying program:\n")
for k, inv := range plan.GetProgram().GetInvocation() {
fmt.Fprintf(debug, " #%d %q --> cats:%v after:%v\n", k, inv.Description,
inv.GetOrder().GetSchedCategory(),
inv.GetOrder().GetSchedAfterCategory())
}
raw, err := cluster.Cluster().EnsureState(ctx, orchestratorStateKey)
if err != nil {
return err
}
conn, err := raw.(*RemoteOrchestrator).Connect(ctx)
if err != nil {
return err
}
defer conn.Close()
id, err := CallDeploy(ctx, env, conn, plan)
if err != nil {
return err
}
if wait {
var ch chan *orchpb.Event
var cleanup func(ctx context.Context) error
if outputProgress {
ch, cleanup = deploy.MaybeRenderBlock(env, cluster, true)(ctx)
}
err := WireDeploymentStatus(ctx, conn, id, ch)
if cleanup != nil {
cleanupErr := cleanup(ctx)
if err == nil {
return cleanupErr
}
}
return err
}
return nil
})
}