Skip to content

Commit

Permalink
Fix plugin's registration when reva is built with version 1.21 (#4113)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 authored Aug 15, 2023
1 parent b1579eb commit f2afa84
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/fix-plugins-go1.21.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Fix plugin's registration when reva is built with version 1.21

With go 1.21 the logic for package initialization has changed,
and the plugins were failing in the registration.
Now the registration of the plugins is deferred in the main.

https://github.com/cs3org/reva/pull/4113
11 changes: 11 additions & 0 deletions cmd/revad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ import (
"sync"
"syscall"

"github.com/cs3org/reva"
"github.com/cs3org/reva/cmd/revad/pkg/config"
"github.com/cs3org/reva/cmd/revad/pkg/grace"
"github.com/cs3org/reva/cmd/revad/runtime"
"github.com/cs3org/reva/pkg/logger"
"github.com/cs3org/reva/pkg/plugin"
"github.com/cs3org/reva/pkg/sysinfo"
"github.com/google/uuid"
"github.com/pkg/errors"
Expand All @@ -58,6 +60,8 @@ var (
func Main() {
flag.Parse()

initPlugins()

// initialize the global system information
if err := sysinfo.InitSystemInfo(&sysinfo.RevaVersion{Version: version, BuildDate: buildDate, GitCommit: gitCommit, GoVersion: goVersion}); err != nil {
fmt.Fprintf(os.Stderr, "error initializing system info: %s\n", err.Error())
Expand Down Expand Up @@ -89,6 +93,13 @@ func Main() {
runConfigs(confs)
}

func initPlugins() {
plugins := reva.GetPlugins("")
for _, p := range plugins {
plugin.RegisterPlugin(p.ID.Namespace(), p.ID.Name(), p.New)
}
}

func handleVersionFlag() {
if *versionFlag {
fmt.Fprintf(os.Stderr, "%s\n", getVersionString())
Expand Down
4 changes: 3 additions & 1 deletion pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

package plugin

import "reflect"
import (
"reflect"
)

// RegistryFunc is the func a component that is pluggable
// must define to register the new func in its own registry.
Expand Down
5 changes: 0 additions & 5 deletions plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ package reva
import (
"sort"
"strings"

"github.com/cs3org/reva/pkg/plugin"
)

// Plugin is a type used as reva plugin.
Expand Down Expand Up @@ -98,10 +96,7 @@ func RegisterPlugin(p Plugin) {
panic("plugin new func cannot be nil")
}

name := plug.ID.Name()
ns := plug.ID.Namespace()
registry[string(p.RevaPlugin().ID)] = p
plugin.RegisterPlugin(ns, name, plug.New)
}

func hasPrefixSlices(s, prefix []string) bool {
Expand Down

0 comments on commit f2afa84

Please sign in to comment.