-
Notifications
You must be signed in to change notification settings - Fork 8
/
orchestrator.go
52 lines (42 loc) · 2.05 KB
/
orchestrator.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
// 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 prepare
import (
"context"
"fmt"
"namespacelabs.dev/foundation/internal/compute"
"namespacelabs.dev/foundation/internal/console"
"namespacelabs.dev/foundation/internal/runtime/kubernetes"
"namespacelabs.dev/foundation/orchestration"
"namespacelabs.dev/foundation/schema"
"namespacelabs.dev/foundation/std/cfg"
"namespacelabs.dev/foundation/std/tasks"
)
func PrepareOrchestrator(env cfg.Context, kube compute.Computable[*kubernetes.Cluster], confs ...compute.Computable[*schema.DevHost_ConfigureEnvironment]) compute.Computable[*schema.DevHost_ConfigureEnvironment] {
return compute.Map(
tasks.Action("prepare.orchestrator").HumanReadablef("Deploying the Namespace Orchestrator"),
compute.Inputs().Str("kind", "orchestrator").Computable("runtime", kube).
Computable("conf", compute.Transform("parse results",
compute.Collect(tasks.Action("prepare.kubernetes.configs"), confs...), mergeConfigs)).
Proto("env", env.Environment()).Proto("workspace", env.Workspace().Proto()),
compute.Output{NotCacheable: true},
func(ctx context.Context, deps compute.Resolved) (*schema.DevHost_ConfigureEnvironment, error) {
devhost, _ := compute.GetDepWithType[*schema.DevHost](deps, "conf")
config, err := cfg.MakeConfigurationCompat(env, env.Workspace(), devhost.Value, env.Environment())
if err != nil {
return nil, err
}
kube := compute.MustGetDepValue(deps, kube, "runtime")
if err := PrepareOrchestratorInKube(ctx, config, kube); err != nil {
return nil, err
}
fmt.Fprintln(console.Stdout(ctx), "[✓] Ensure Namespace Orchestrator is running in Kubernetes.")
// The orchestrator produces no unique configuration.
return nil, nil
})
}
func PrepareOrchestratorInKube(ctx context.Context, config cfg.Configuration, kube *kubernetes.Cluster) error {
_, err := orchestration.PrepareOrchestrator(ctx, config, kube, false)
return err
}