feat: start machined earlier & in maintenance mode
Load & start machined earlier and in initialize sequence, so that it is possible to use its API over its unix socket in maintenance mode. Additionally, do not return features from Version API if a config is not yet available. Related to siderolabs/talos#4791. Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
This commit is contained in:
parent
36ab414a1d
commit
5ac9f43e45
@ -1134,8 +1134,13 @@ func (s *Server) Version(ctx context.Context, in *emptypb.Empty) (reply *machine
|
||||
}
|
||||
}
|
||||
|
||||
features := &machine.FeaturesInfo{
|
||||
Rbac: s.Controller.Runtime().Config().Machine().Features().RBACEnabled(),
|
||||
var features *machine.FeaturesInfo
|
||||
|
||||
config := s.Controller.Runtime().Config()
|
||||
if config != nil {
|
||||
features = &machine.FeaturesInfo{
|
||||
Rbac: config.Machine().Features().RBACEnabled(),
|
||||
}
|
||||
}
|
||||
|
||||
return &machine.VersionResponse{
|
||||
|
@ -232,6 +232,11 @@ func run() error {
|
||||
// Inject controller into maintenance service.
|
||||
maintenance.InjectController(c)
|
||||
|
||||
// Load machined service.
|
||||
system.Services(c.Runtime()).Load(
|
||||
&services.Machined{Controller: c},
|
||||
)
|
||||
|
||||
initializeCanceled := false
|
||||
|
||||
// Initialize the machine.
|
||||
@ -252,7 +257,6 @@ func run() error {
|
||||
|
||||
// Start the machine API.
|
||||
system.Services(c.Runtime()).LoadAndStart(
|
||||
&services.Machined{Controller: c},
|
||||
&services.APID{},
|
||||
)
|
||||
|
||||
|
@ -76,6 +76,9 @@ func (*Sequencer) Initialize(r runtime.Runtime) []runtime.Phase {
|
||||
"etc",
|
||||
CreateSystemCgroups,
|
||||
CreateOSReleaseFile,
|
||||
).Append(
|
||||
"machined",
|
||||
StartMachined,
|
||||
).Append(
|
||||
"config",
|
||||
LoadConfig,
|
||||
@ -100,8 +103,9 @@ func (*Sequencer) Initialize(r runtime.Runtime) []runtime.Phase {
|
||||
CreateSystemCgroups,
|
||||
CreateOSReleaseFile,
|
||||
).Append(
|
||||
"udevd",
|
||||
"earlyServices",
|
||||
StartUdevd,
|
||||
StartMachined,
|
||||
).AppendWithDeferredCheck(
|
||||
func() bool {
|
||||
return r.State().Machine().Installed()
|
||||
|
@ -773,6 +773,25 @@ func WriteUdevRules(seq runtime.Sequence, data interface{}) (runtime.TaskExecuti
|
||||
}, "writeUdevRules"
|
||||
}
|
||||
|
||||
// StartMachined represents the task to start machined.
|
||||
func StartMachined(_ runtime.Sequence, _ interface{}) (runtime.TaskExecutionFunc, string) {
|
||||
return func(ctx context.Context, logger *log.Logger, r runtime.Runtime) error {
|
||||
svc := &services.Machined{}
|
||||
|
||||
id := svc.ID(r)
|
||||
|
||||
err := system.Services(r).Start(id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to start machined service: %w", err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, 5*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
return system.WaitForService(system.StateEventUp, id).Wait(ctx)
|
||||
}, "startMachined"
|
||||
}
|
||||
|
||||
// StartUdevd represents the task to start udevd.
|
||||
func StartUdevd(seq runtime.Sequence, data interface{}) (runtime.TaskExecutionFunc, string) {
|
||||
return func(ctx context.Context, logger *log.Logger, r runtime.Runtime) (err error) {
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
stdlibruntime "runtime"
|
||||
"sync"
|
||||
|
||||
@ -89,14 +88,7 @@ func (r *goroutineRunner) wrappedMain() (err error) {
|
||||
//nolint:errcheck
|
||||
defer w.Close()
|
||||
|
||||
var writer io.Writer
|
||||
if r.runtime.Config().Debug() {
|
||||
writer = io.MultiWriter(w, os.Stdout)
|
||||
} else {
|
||||
writer = w
|
||||
}
|
||||
|
||||
err = r.main(r.ctx, r.runtime, writer)
|
||||
err = r.main(r.ctx, r.runtime, w)
|
||||
if err == context.Canceled {
|
||||
// clear error if service was aborted
|
||||
err = nil
|
||||
|
@ -63,7 +63,7 @@ func trustdMain() error {
|
||||
|
||||
go runDebugServer(ctx)
|
||||
|
||||
startup.LimitMaxProcs(constants.ApidMaxProcs)
|
||||
startup.LimitMaxProcs(constants.TrustdMaxProcs)
|
||||
|
||||
var err error
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user