-
Notifications
You must be signed in to change notification settings - Fork 8
/
wire.go
76 lines (62 loc) · 2.49 KB
/
wire.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
// 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 service
import (
"context"
"log"
"strings"
"time"
"google.golang.org/grpc/codes"
pb "google.golang.org/protobuf/proto"
"namespacelabs.dev/foundation/framework/rpcerrors"
"namespacelabs.dev/foundation/internal/console"
"namespacelabs.dev/foundation/internal/fnapi"
"namespacelabs.dev/foundation/internal/planning/deploy"
"namespacelabs.dev/foundation/internal/runtime/kubernetes"
"namespacelabs.dev/foundation/internal/runtime/kubernetes/client"
"namespacelabs.dev/foundation/internal/runtime/kubernetes/kubeops"
"namespacelabs.dev/foundation/orchestration"
"namespacelabs.dev/foundation/orchestration/proto"
"namespacelabs.dev/foundation/std/go/server"
"namespacelabs.dev/foundation/std/tasks"
"namespacelabs.dev/foundation/universe/aws/iam"
)
type Service struct {
deployer deployer
}
func (svc *Service) Deploy(ctx context.Context, req *proto.DeployRequest) (*proto.DeployResponse, error) {
log.Printf("new Deploy request for %d focus servers: %s\n", len(req.Plan.FocusServer), strings.Join(req.Plan.FocusServer, ","))
now := time.Now()
if req.Auth != nil {
if _, err := fnapi.StoreUser(ctx, req.Auth); err != nil {
return nil, err
}
}
var extra []pb.Message
if req.Aws != nil {
extra = append(extra, req.Aws)
}
env := orchestration.MakeSyntheticContext(req.Plan.Workspace, req.Plan.Environment, &client.HostEnv{Incluster: true}, extra...)
// TODO store target state (req.Plan + merged with history) ?
id, err := svc.deployer.Schedule(req.Plan, env, now)
if err != nil {
return nil, rpcerrors.Errorf(codes.Internal, "failed to deploy plan: %w", err)
}
res := &proto.DeployResponse{Id: id.ID}
return res, nil
}
func (svc *Service) DeploymentStatus(req *proto.DeploymentStatusRequest, stream proto.OrchestrationService_DeploymentStatusServer) error {
return svc.deployer.Status(stream.Context(), req.Id, req.LogLevel, stream.Send)
}
func WireService(ctx context.Context, srv server.Registrar, deps ServiceDeps) {
proto.RegisterOrchestrationServiceServer(srv, &Service{deployer: newDeployer()})
kubernetes.Register()
kubeops.Register()
iam.RegisterGraphHandlers()
deploy.RegisterDeployOps()
// Always log actions, we filter if we show them on the client.
tasks.LogActions = true
// Always log debug to console, we redirect the log on the client.
console.DebugToConsole = true
}