This repository was archived by the owner on Aug 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperator.go
More file actions
105 lines (86 loc) · 2.15 KB
/
operator.go
File metadata and controls
105 lines (86 loc) · 2.15 KB
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
// SPDX-License-Identifier: BSD-3-Clause
package operator
import (
"context"
"cirello.io/oversight"
"github.com/go-logr/logr"
"github.com/u-bmc/operator/pkg/log"
"github.com/u-bmc/operator/pkg/telemetry"
"github.com/u-bmc/operator/pkg/version"
"github.com/u-bmc/operator/service"
"github.com/u-bmc/operator/service/apid"
"github.com/u-bmc/operator/service/hardwared"
"github.com/u-bmc/operator/service/ipcd"
"github.com/u-bmc/operator/service/kvmd"
"github.com/u-bmc/operator/service/netd"
"github.com/u-bmc/operator/service/registryd"
"github.com/u-bmc/operator/service/telemetryd"
"github.com/u-bmc/operator/service/updated"
)
func Launch(ctx context.Context, opts ...Option) error {
c := config{
log: log.NewDefaultLogger(),
svcs: NewDefaultServiceMap(),
}
for _, opt := range opts {
opt.apply(&c)
}
// Note: Tracing currently noop until configurable
telemetry.SetupOtelSDK(ctx, telemetry.NewResource("u-bmc", version.SemVer), c.log)
c.log.Info("Starting u-bmc operator", "version", version.Version())
p := make([]oversight.ChildProcessSpecification, len(c.svcs))
for i, svc := range c.svcs {
p[i] = oversight.ChildProcessSpecification{
Name: svc.Name(),
Start: svc.Run,
Restart: oversight.Permanent(),
}
}
supervise := oversight.New(
oversight.WithSpecification(-1, 0, oversight.OneForOne()),
oversight.WithLogger(log.NewOversightLogger(c.log)),
oversight.Process(p...),
)
return supervise.Start(ctx)
}
type config struct {
log logr.Logger
svcs []service.Service
}
type Option interface {
apply(*config)
}
type logOption struct {
log logr.Logger
}
func (o *logOption) apply(c *config) {
c.log = o.log
}
func WithLogger(l logr.Logger) Option {
return &logOption{
log: l,
}
}
type serviceMapOption struct {
svcs []service.Service
}
func (o *serviceMapOption) apply(c *config) {
c.svcs = o.svcs
}
func WithServiceMap(svcs []service.Service) Option {
return &serviceMapOption{
svcs: svcs,
}
}
func NewDefaultServiceMap() []service.Service {
return []service.Service{
ipcd.New(),
registryd.New(),
netd.New(),
apid.New(),
hardwared.New(),
kvmd.New(),
telemetryd.New(),
updated.New(),
}
}