Skip to content

Commit

Permalink
feat: start machined earlier & in maintenance mode
Browse files Browse the repository at this point in the history
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 #4791.

Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
  • Loading branch information
utkuozdemir committed Feb 21, 2023
1 parent 36ab414 commit 5ac9f43
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
6 changes: 5 additions & 1 deletion internal/app/machined/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -252,7 +257,6 @@ func run() error {

// Start the machine API.
system.Services(c.Runtime()).LoadAndStart(
&services.Machined{Controller: c},
&services.APID{},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ func (*Sequencer) Initialize(r runtime.Runtime) []runtime.Phase {
"etc",
CreateSystemCgroups,
CreateOSReleaseFile,
).Append(
"machined",
StartMachined,
).Append(
"config",
LoadConfig,
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 1 addition & 9 deletions internal/app/machined/pkg/system/runner/goroutine/goroutine.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"context"
"fmt"
"io"
"os"
stdlibruntime "runtime"
"sync"

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/app/trustd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func trustdMain() error {

go runDebugServer(ctx)

startup.LimitMaxProcs(constants.ApidMaxProcs)
startup.LimitMaxProcs(constants.TrustdMaxProcs)

var err error

Expand Down

0 comments on commit 5ac9f43

Please sign in to comment.