/
exec_node.go
132 lines (112 loc) · 3.39 KB
/
exec_node.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
130
131
132
package components
import (
"context"
"go.ytsaurus.tech/library/go/ptr"
corev1 "k8s.io/api/core/v1"
ytv1 "github.com/ytsaurus/yt-k8s-operator/api/v1"
"github.com/ytsaurus/yt-k8s-operator/pkg/apiproxy"
"github.com/ytsaurus/yt-k8s-operator/pkg/consts"
"github.com/ytsaurus/yt-k8s-operator/pkg/labeller"
"github.com/ytsaurus/yt-k8s-operator/pkg/ytconfig"
)
type ExecNode struct {
baseExecNode
localComponent
master Component
}
func NewExecNode(
cfgen *ytconfig.NodeGenerator,
ytsaurus *apiproxy.Ytsaurus,
master Component,
spec ytv1.ExecNodesSpec,
) *ExecNode {
resource := ytsaurus.GetResource()
l := labeller.Labeller{
ObjectMeta: &resource.ObjectMeta,
APIProxy: ytsaurus.APIProxy(),
ComponentLabel: cfgen.FormatComponentStringWithDefault(consts.YTComponentLabelExecNode, spec.Name),
ComponentName: cfgen.FormatComponentStringWithDefault(string(consts.ExecNodeType), spec.Name),
}
if spec.InstanceSpec.MonitoringPort == nil {
spec.InstanceSpec.MonitoringPort = ptr.Int32(consts.ExecNodeMonitoringPort)
}
srv := newServer(
&l,
ytsaurus,
&spec.InstanceSpec,
"/usr/bin/ytserver-node",
"ytserver-exec-node.yson",
cfgen.GetExecNodesStatefulSetName(spec.Name),
cfgen.GetExecNodesServiceName(spec.Name),
func() ([]byte, error) {
return cfgen.GetExecNodeConfig(spec)
},
WithContainerPorts(corev1.ContainerPort{
Name: consts.YTRPCPortName,
ContainerPort: consts.ExecNodeRPCPort,
Protocol: corev1.ProtocolTCP,
}),
)
var sidecarConfig *ConfigHelper
if spec.JobEnvironment != nil && spec.JobEnvironment.CRI != nil {
sidecarConfig = NewConfigHelper(
&l,
ytsaurus.APIProxy(),
l.GetSidecarConfigMapName(consts.JobsContainerName),
ytsaurus.GetResource().Spec.ConfigOverrides,
map[string]ytconfig.GeneratorDescriptor{
consts.ContainerdConfigFileName: {
F: func() ([]byte, error) {
return cfgen.GetContainerdConfig(&spec)
},
Fmt: ytconfig.ConfigFormatToml,
},
})
}
return &ExecNode{
localComponent: newLocalComponent(&l, ytsaurus),
baseExecNode: baseExecNode{
server: srv,
cfgen: cfgen,
spec: &spec,
sidecarConfig: sidecarConfig,
},
master: master,
}
}
func (n *ExecNode) IsUpdatable() bool {
return true
}
func (n *ExecNode) GetType() consts.ComponentType { return consts.ExecNodeType }
func (n *ExecNode) doSync(ctx context.Context, dry bool) (ComponentStatus, error) {
var err error
if ytv1.IsReadyToUpdateClusterState(n.ytsaurus.GetClusterState()) && n.server.needUpdate() {
return SimpleStatus(SyncStatusNeedLocalUpdate), err
}
if n.ytsaurus.GetClusterState() == ytv1.ClusterStateUpdating {
if status, err := handleUpdatingClusterState(ctx, n.ytsaurus, n, &n.localComponent, n.server, dry); status != nil {
return *status, err
}
}
masterStatus, err := n.master.Status(ctx)
if err != nil {
return masterStatus, err
}
if !IsRunningStatus(masterStatus.SyncStatus) {
return WaitingStatus(SyncStatusBlocked, n.master.GetName()), err
}
if LocalServerNeedSync(n.server, n.ytsaurus) {
return n.doSyncBase(ctx, dry)
}
if !n.server.arePodsReady(ctx) {
return WaitingStatus(SyncStatusBlocked, "pods"), err
}
return SimpleStatus(SyncStatusReady), err
}
func (n *ExecNode) Status(ctx context.Context) (ComponentStatus, error) {
return n.doSync(ctx, true)
}
func (n *ExecNode) Sync(ctx context.Context) error {
_, err := n.doSync(ctx, false)
return err
}