-
Notifications
You must be signed in to change notification settings - Fork 9
/
env.go
57 lines (45 loc) · 2.14 KB
/
env.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
// 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"
"google.golang.org/protobuf/proto"
"namespacelabs.dev/foundation/framework/kubernetes/kubedef"
"namespacelabs.dev/foundation/framework/kubernetes/kubetool"
"namespacelabs.dev/foundation/internal/protos"
"namespacelabs.dev/foundation/internal/runtime/kubernetes/client"
"namespacelabs.dev/foundation/schema"
"namespacelabs.dev/foundation/std/cfg"
)
func MakeSyntheticConfiguration(wsproto *schema.Workspace, envName string, hostEnv *client.HostEnv, extra ...proto.Message) cfg.Configuration {
messages := []proto.Message{hostEnv}
messages = append(messages, extra...)
ws := cfg.MakeSyntheticWorkspace(wsproto, nil)
return cfg.MakeConfigurationWith(envName, ws, cfg.ConfigurationSlice{Configuration: protos.WrapAnysOrDie(messages...)})
}
func MakeSyntheticContext(wsproto *schema.Workspace, env *schema.Environment, hostEnv *client.HostEnv, extra ...proto.Message) cfg.Context {
newCfg := MakeSyntheticConfiguration(wsproto, env.Name, hostEnv, extra...)
return cfg.MakeUnverifiedContext(newCfg, env)
}
func MakeOrchestratorContext(ctx context.Context, conf cfg.Configuration) (cfg.Context, error) {
// We use a static environment here, since the orchestrator has global scope.
envProto := &schema.Environment{
Name: kubedef.AdminNamespace,
Runtime: "kubernetes", // XXX should be an input.
Ephemeral: false,
// TODO - this can't be empty, since std/runtime/kubernetes/extension.cue checks it.
Purpose: schema.Environment_PRODUCTION,
Labels: []*schema.Label{{
Name: "namespace.so/environment-scope",
Value: "admin",
}},
}
newCfg := conf.Derive(kubedef.AdminNamespace, func(previous cfg.ConfigurationSlice) cfg.ConfigurationSlice {
previous.Configuration = append(previous.Configuration, protos.WrapAnyOrDie(
&kubetool.KubernetesEnv{Namespace: kubedef.AdminNamespace}, // pin deployments to admin namespace
))
return previous
})
return cfg.MakeUnverifiedContext(newCfg, envProto), nil
}