diff --git a/ocis/go.sum b/ocis/go.sum index af559420c..4c6a68157 100644 --- a/ocis/go.sum +++ b/ocis/go.sum @@ -1506,6 +1506,7 @@ github.com/spf13/cobra v0.0.6/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHN github.com/spf13/cobra v0.0.7/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8= github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= +github.com/spf13/cobra v1.1.3 h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M= github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= diff --git a/ocis/pkg/runtime/cmd/root.go b/ocis/pkg/runtime/cmd/root.go index c461bb3eb..22127444e 100644 --- a/ocis/pkg/runtime/cmd/root.go +++ b/ocis/pkg/runtime/cmd/root.go @@ -19,8 +19,12 @@ func RootCmd(cfg *config.Config) *cobra.Command { rootCmd.PersistentFlags().StringVarP(&cfg.Port, "port", "p", "10666", "port to send messages to the rpc oCIS runtime.") rootCmd.PersistentFlags().BoolVarP(&cfg.KeepAlive, "keep-alive", "k", false, "restart supervised processes that abruptly die.") - viper.BindPFlag("hostname", rootCmd.PersistentFlags().Lookup("hostname")) - viper.BindPFlag("port", rootCmd.PersistentFlags().Lookup("port")) + if err := viper.BindPFlag("hostname", rootCmd.PersistentFlags().Lookup("hostname")); err != nil { + panic(err) + } + if err := viper.BindPFlag("port", rootCmd.PersistentFlags().Lookup("port")); err != nil { + panic(err) + } rootCmd.AddCommand(List(cfg)) rootCmd.AddCommand(Run(cfg)) diff --git a/ocis/pkg/runtime/controller/janitor.go b/ocis/pkg/runtime/controller/janitor.go index dca359cd7..61131eab3 100644 --- a/ocis/pkg/runtime/controller/janitor.go +++ b/ocis/pkg/runtime/controller/janitor.go @@ -39,7 +39,7 @@ func (j *janitor) cleanup() { // On unix like systems (linux, freebsd, etc) os.FindProcess will never return an error if p, err := os.FindProcess(pid); err == nil { if err := p.Signal(syscall.Signal(0)); err != nil { - j.store.Delete(process.ProcEntry{ + _ = j.store.Delete(process.ProcEntry{ Pid: pid, Extension: name, }) diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 629761f85..731e1f083 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -34,12 +34,16 @@ type Service struct { // loadFromEnv would set cmd global variables. This is a workaround spf13/viper since pman used as a library does not // parse flags. -func loadFromEnv() *config.Config { +func loadFromEnv() (*config.Config, error) { cfg := config.NewConfig() viper.AutomaticEnv() - viper.BindEnv("keep-alive", "RUNTIME_KEEP_ALIVE") - viper.BindEnv("port", "RUNTIME_PORT") + if err := viper.BindEnv("keep-alive", "RUNTIME_KEEP_ALIVE"); err != nil { + return nil, err + } + if err := viper.BindEnv("port", "RUNTIME_PORT"); err != nil { + return nil, err + } cfg.KeepAlive = viper.GetBool("keep-alive") @@ -47,7 +51,7 @@ func loadFromEnv() *config.Config { cfg.Port = viper.GetString("port") } - return cfg + return cfg, nil } // NewService returns a configured service with a controller and a default logger. @@ -55,14 +59,17 @@ func loadFromEnv() *config.Config { // calls are done explicitly to loadFromEnv(). // Since this is the public constructor, options need to be added, at the moment only logging options // are supported in order to match the running OwnCloud services structured log. -func NewService(options ...Option) *Service { +func NewService(options ...Option) (*Service, error) { opts := NewOptions() for _, f := range options { f(opts) } - cfg := loadFromEnv() + cfg, err := loadFromEnv() + if err != nil { + return nil, err + } l := log.NewLogger( log.WithPretty(opts.Log.Pretty), ) @@ -74,12 +81,15 @@ func NewService(options ...Option) *Service { controller.WithConfig(cfg), controller.WithLog(&l), ), - } + }, nil } // Start an rpc service. func Start(o ...Option) error { - s := NewService(o...) + s, err := NewService(o...) + if err != nil { + s.Log.Fatal().Err(err) + } if err := rpc.Register(s); err != nil { s.Log.Fatal().Err(err) diff --git a/ocis/pkg/runtime/storage/map_test.go b/ocis/pkg/runtime/storage/map_test.go index 8aaee1574..00941d4d0 100644 --- a/ocis/pkg/runtime/storage/map_test.go +++ b/ocis/pkg/runtime/storage/map_test.go @@ -12,7 +12,9 @@ import ( ) func TestMain(m *testing.M) { - loadStore() + if err := loadStore(); err != nil { + os.Exit(1) + } os.Exit(m.Run()) } @@ -20,13 +22,17 @@ var ( store = NewMapStorage() ) -func loadStore() { +func loadStore() error { for i := 0; i < 20; i++ { - store.Store(process.ProcEntry{ - Pid: rand.Int(), + if err := store.Store(process.ProcEntry{ + Pid: rand.Int(), //nolint:gosec Extension: fmt.Sprintf("extension-%s", strconv.Itoa(i)), - }) + }); err != nil { + return err + } } + + return nil } func TestLoadAll(t *testing.T) { @@ -35,9 +41,10 @@ func TestLoadAll(t *testing.T) { } func TestDelete(t *testing.T) { - store.Delete(process.ProcEntry{ + err := store.Delete(process.ProcEntry{ Extension: "extension-1", }) + assert.Nil(t, err) all := store.LoadAll() assert.Zero(t, all["extension-1"]) }