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

Use registry interface value #1697

Merged
merged 4 commits into from
Feb 22, 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
2 changes: 1 addition & 1 deletion accounts/pkg/command/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func PrintVersion(cfg *config.Config) *cli.Command {
Usage: "Print the versions of the running instances",
Flags: flagset.ListAccountsWithConfig(cfg),
Action: func(c *cli.Context) error {
reg := *registry.GetRegistry()
reg := registry.GetRegistry()
services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Server.Name)
if err != nil {
fmt.Println(fmt.Errorf("could not get accounts services from the registry: %v", err))
Expand Down
6 changes: 6 additions & 0 deletions changelog/unreleased/use-registry-interface.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Add initial nats and kubernetes registry support

We added initial support to use nats and kubernetes as a service registry using `MICRO_REGISTRY=nats` and `MICRO_REGISTRY=kubernetes` respectively.
Multiple nodes can be given with `MICRO_REGISTRY_ADDRESS=1.2.3.4,5.6.7.8,9.10.11.12`.

https://github.com/owncloud/ocis/pull/1697
2 changes: 1 addition & 1 deletion idp/pkg/command/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func PrintVersion(cfg *config.Config) *cli.Command {
Usage: "Print the versions of the running instances",
Flags: flagset.ListIDPWithConfig(cfg),
Action: func(c *cli.Context) error {
reg := *registry.GetRegistry()
reg := registry.GetRegistry()
services, err := reg.GetService(cfg.Service.Namespace + "." + cfg.Service.Name)
if err != nil {
fmt.Println(fmt.Errorf("could not get idp services from the registry: %v", err))
Expand Down
14 changes: 12 additions & 2 deletions ocis-pkg/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"strings"

etcdr "github.com/asim/go-micro/plugins/registry/etcd/v3"
kubernetesr "github.com/asim/go-micro/plugins/registry/kubernetes/v3"
mdnsr "github.com/asim/go-micro/plugins/registry/mdns/v3"
natsr "github.com/asim/go-micro/plugins/registry/nats/v3"

"github.com/asim/go-micro/v3/registry"
)
Expand All @@ -18,11 +20,19 @@ var (
// GetRegistry returns a configured micro registry based on Micro env vars.
// It defaults to mDNS, so mind that systems with mDNS disabled by default (i.e SUSE) will have a hard time
// and it needs to explicitly use etcd. Os awareness for providing a working registry out of the box should be done.
func GetRegistry() *registry.Registry {
func GetRegistry() registry.Registry {
addresses := strings.Split(os.Getenv(registryAddressEnv), ",")

var r registry.Registry
switch os.Getenv(registryEnv) {
case "nats":
r = natsr.NewRegistry(
registry.Addrs(addresses...),
)
case "kubernetes":
r = kubernetesr.NewRegistry(
registry.Addrs(addresses...),
)
case "etcd":
r = etcdr.NewRegistry(
registry.Addrs(addresses...),
Expand All @@ -31,5 +41,5 @@ func GetRegistry() *registry.Registry {
r = mdnsr.NewRegistry()
}

return &r
return r
}
2 changes: 1 addition & 1 deletion ocis-pkg/service/grpc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewService(opts ...Option) Service {
micro.Version(sopts.Version),
micro.Context(sopts.Context),
micro.Flags(sopts.Flags...),
micro.Registry(*registry.GetRegistry()),
micro.Registry(registry.GetRegistry()),
micro.RegisterTTL(time.Second * 30),
micro.RegisterInterval(time.Second * 10),
micro.WrapHandler(prometheus.NewHandlerWrapper()),
Expand Down
2 changes: 1 addition & 1 deletion ocis-pkg/service/http/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewService(opts ...Option) Service {
micro.Version(sopts.Version),
micro.Context(sopts.Context),
micro.Flags(sopts.Flags...),
micro.Registry(*registry.GetRegistry()),
micro.Registry(registry.GetRegistry()),
micro.RegisterTTL(time.Second * 30),
micro.RegisterInterval(time.Second * 10),
}
Expand Down
2 changes: 1 addition & 1 deletion ocis/pkg/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func Execute() error {
)
}

//r := *registry.GetRegistry()
//r := registry.GetRegistry()

//opts := micro.Options{
// Registry: r,
Expand Down
2 changes: 1 addition & 1 deletion ocis/pkg/command/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func VersionCommand(cfg *config.Config) *cli.Command {
Usage: "Lists running services with version",
Category: "Runtime",
Action: func(c *cli.Context) error {
reg := *registry.GetRegistry()
reg := registry.GetRegistry()
serviceList, err := reg.ListServices()
if err != nil {
fmt.Println(fmt.Errorf("could not list services: %v", err))
Expand Down
2 changes: 1 addition & 1 deletion ocs/pkg/command/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func PrintVersion(cfg *config.Config) *cli.Command {
Usage: "Print the versions of the running instances",
Flags: flagset.ListOcsWithConfig(cfg),
Action: func(c *cli.Context) error {
reg := *registry.GetRegistry()
reg := registry.GetRegistry()
services, err := reg.GetService(cfg.Service.Namespace + "." + cfg.Service.Name)
if err != nil {
fmt.Println(fmt.Errorf("could not get ocs services from the registry: %v", err))
Expand Down
2 changes: 1 addition & 1 deletion proxy/pkg/command/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func PrintVersion(cfg *config.Config) *cli.Command {
Usage: "Print the versions of the running instances",
Flags: flagset.ListProxyWithConfig(cfg),
Action: func(c *cli.Context) error {
reg := *registry.GetRegistry()
reg := registry.GetRegistry()
services, err := reg.GetService(cfg.Service.Namespace + "." + cfg.Service.Name)
if err != nil {
fmt.Println(fmt.Errorf("could not get proxy services from the registry: %v", err))
Expand Down
2 changes: 1 addition & 1 deletion settings/pkg/command/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func PrintVersion(cfg *config.Config) *cli.Command {
Usage: "Print the versions of the running instances",
Flags: flagset.ListSettingsWithConfig(cfg),
Action: func(c *cli.Context) error {
reg := *registry.GetRegistry()
reg := registry.GetRegistry()
services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Service.Name)
if err != nil {
fmt.Println(fmt.Errorf("could not get settings services from the registry: %v", err))
Expand Down
6 changes: 3 additions & 3 deletions storage/pkg/service/external/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ func RegisterGRPCEndpoint(ctx context.Context, serviceID, uuid, addr string, log
Address: addr,
Metadata: make(map[string]string),
}
r := oregistry.GetRegistry()

node.Metadata["broker"] = broker.String()
node.Metadata["registry"] = registry.String()
node.Metadata["registry"] = r.String()
node.Metadata["server"] = "grpc"
node.Metadata["transport"] = "grpc"
node.Metadata["protocol"] = "grpc"

r := *oregistry.GetRegistry()

service := &registry.Service{
Name: serviceID,
Version: "",
Expand Down
2 changes: 1 addition & 1 deletion store/pkg/command/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func PrintVersion(cfg *config.Config) *cli.Command {
Usage: "Print the versions of the running instances",
Flags: flagset.ListStoreWithConfig(cfg),
Action: func(c *cli.Context) error {
reg := *registry.GetRegistry()
reg := registry.GetRegistry()
services, err := reg.GetService(cfg.Service.Namespace + "." + cfg.Service.Name)
if err != nil {
fmt.Println(fmt.Errorf("could not get store services from the registry: %v", err))
Expand Down
2 changes: 1 addition & 1 deletion thumbnails/pkg/command/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func PrintVersion(cfg *config.Config) *cli.Command {
Usage: "Print the versions of the running instances",
Flags: flagset.ListThumbnailsWithConfig(cfg),
Action: func(c *cli.Context) error {
reg := *registry.GetRegistry()
reg := registry.GetRegistry()
services, err := reg.GetService(cfg.Server.Namespace + "." + cfg.Server.Name)
if err != nil {
fmt.Println(fmt.Errorf("could not get thumbnails services from the registry: %v", err))
Expand Down
2 changes: 1 addition & 1 deletion webdav/pkg/command/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func PrintVersion(cfg *config.Config) *cli.Command {
Usage: "Print the versions of the running instances",
Flags: flagset.ListWebdavWithConfig(cfg),
Action: func(c *cli.Context) error {
reg := *registry.GetRegistry()
reg := registry.GetRegistry()
services, err := reg.GetService(cfg.Service.Namespace + "." + cfg.Service.Name)
if err != nil {
fmt.Println(fmt.Errorf("could not get webdav services from the registry: %v", err))
Expand Down