-
Notifications
You must be signed in to change notification settings - Fork 120
/
controller.go
129 lines (109 loc) · 3.25 KB
/
controller.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package jupyt
import (
"context"
"fmt"
"go.ytsaurus.tech/library/go/core/log"
"go.ytsaurus.tech/yt/chyt/controller/internal/strawberry"
"go.ytsaurus.tech/yt/go/ypath"
"go.ytsaurus.tech/yt/go/yson"
"go.ytsaurus.tech/yt/go/yt"
"go.ytsaurus.tech/yt/go/yterrors"
)
const (
JupytPort = 27042
)
type Config struct {
}
type Controller struct {
ytc yt.Client
l log.Logger
root ypath.Path
cluster string
config Config
}
func (c *Controller) UpdateState() (changed bool, err error) {
return false, nil
}
func (c *Controller) buildCommand(speclet *Speclet) (command string, env map[string]string) {
// TODO(max): take port from YT_PORT_0.
// TODO(max): come up with a solution how to pass secrets (token or password) without exposing them in the
// strawberry attributes.
cmd := fmt.Sprintf(
"bash -x start.sh /opt/conda/bin/jupyter lab --ip '*' --port %v --LabApp.token='' --allow-root >&2", JupytPort)
return cmd, map[string]string{
"NB_GID": "0",
"NB_UID": "0",
"NB_USER": "root",
}
}
func (c *Controller) Prepare(ctx context.Context, oplet *strawberry.Oplet) (
spec map[string]any, description map[string]any, annotations map[string]any, err error) {
alias := oplet.Alias()
// description = buildDescription(c.cluster, alias, c.config.EnableYandexSpecificLinksOrDefault())
speclet := oplet.ControllerSpeclet().(Speclet)
description = map[string]any{}
// Build command.
command, env := c.buildCommand(&speclet)
spec = map[string]any{
"tasks": map[string]any{
"jupyter": map[string]any{
"command": command,
"job_count": 1,
"docker_image": speclet.JupyterDockerImage,
"memory_limit": speclet.MemoryOrDefault(),
"cpu_limit": speclet.CPUOrDefault(),
"port_count": 1,
"max_stderr_size": 1024 * 1024 * 1024,
"user_job_memory_digest_lower_bound": 1.0,
"environment": env,
},
},
"max_failed_job_count": 10 * 1000,
"max_stderr_count": 150,
"title": "JUPYT notebook *" + alias,
}
annotations = map[string]any{
"is_notebook": true,
"expose": true,
}
return
}
func (c *Controller) Family() string {
return "jupyt"
}
func (c *Controller) Root() ypath.Path {
return c.root
}
func (c *Controller) ParseSpeclet(specletYson yson.RawValue) (any, error) {
var speclet Speclet
err := yson.Unmarshal(specletYson, &speclet)
if err != nil {
return nil, yterrors.Err("failed to parse speclet", err)
}
return speclet, nil
}
func (c *Controller) DescribeOptions(parsedSpeclet any) []strawberry.OptionGroupDescriptor {
return nil
}
func (c *Controller) GetOpBriefAttributes(parsedSpeclet any) map[string]any {
return nil
}
func parseConfig(rawConfig yson.RawValue) Config {
var controllerConfig Config
if rawConfig != nil {
if err := yson.Unmarshal(rawConfig, &controllerConfig); err != nil {
panic(err)
}
}
return controllerConfig
}
func NewController(l log.Logger, ytc yt.Client, root ypath.Path, cluster string, rawConfig yson.RawValue) strawberry.Controller {
c := &Controller{
l: l,
ytc: ytc,
root: root,
cluster: cluster,
config: parseConfig(rawConfig),
}
return c
}