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

Fix plugin's registration when reva is built with version 1.21 #4113

Merged
merged 3 commits into from
Aug 15, 2023
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
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