Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow config parsing on supervise mode only with run subcommand #1931

Merged
merged 4 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/config-parsing-run-subcommand.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Parse config on supervised mode with run subcommand

Currenntly it is not possible to parse a single config file from an extension when running on supervised mode.

https://github.com/owncloud/ocis/pull/1931
3 changes: 3 additions & 0 deletions ocis-pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ type Runtime struct {

// Config combines all available configuration parts.
type Config struct {
// Mode is mostly used whenever we need to run an extension. The technical debt this introduces is in regards of
// what it does. Supervised (0) loads configuration from a unified config file because of known limitations of Viper; whereas
// Unsupervised (1) MUST parse config from all known sources.
Mode Mode
File string

Expand Down
16 changes: 12 additions & 4 deletions ocis/pkg/runtime/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,18 @@ func NewService(options ...Option) (*Service, error) {
// Start an rpc service. By default the package scope Start will run all default extensions to provide with a working
// oCIS instance.
func Start(o ...Option) error {
// Start the runtime. Most likely this was called ONLY by the `ocis server` subcommand, but since we cannot protect
// from the caller, the previous statement holds truth.

// prepare a new rpc Service struct.
s, err := NewService(o...)
if err != nil {
return err
}

// notify goroutines that they are running on supervised mode
s.cfg.Mode = ociscfg.SUPERVISED

setMicroLogger()

// Start creates its own supervisor. Running services under `ocis server` will create its own supervision tree.
Expand All @@ -129,15 +135,12 @@ func Start(o ...Option) error {
},
})

// reva storages have their own logging. For consistency sake the top level logging will be cascade to reva.
// reva storages have their own logging. For consistency sake the top level logging will cascade to reva.
s.cfg.Storage.Log.Color = s.cfg.Log.Color
s.cfg.Storage.Log.Level = s.cfg.Log.Level
s.cfg.Storage.Log.Pretty = s.cfg.Log.Pretty
s.cfg.Storage.Log.File = s.cfg.Log.File

// notify goroutines that they are running on supervised mode
s.cfg.Mode = ociscfg.SUPERVISED

if err := rpc.Register(s); err != nil {
if s != nil {
s.Log.Fatal().Err(err)
Expand Down Expand Up @@ -193,6 +196,11 @@ func Start(o ...Option) error {

// Start indicates the Service Controller to start a new supervised service as an OS thread.
func (s *Service) Start(name string, reply *int) error {
// RPC calls to a Service object will allow for parsing config. Mind that since the runtime is running on a different
// machine, the configuration needs to be present in the given machine. RPC does not yet allow providing a config
// during transport.
s.cfg.Mode = ociscfg.UNSUPERVISED

swap := deepcopy.Copy(s.cfg)
if _, ok := s.ServicesRegistry[name]; ok {
*reply = 0
Expand Down