Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Proposal: plugin mechanism for Dragonfly #1309

Open
lowzj opened this issue Apr 27, 2020 · 6 comments
Open

Proposal: plugin mechanism for Dragonfly #1309

lowzj opened this issue Apr 27, 2020 · 6 comments
Labels
kind/proposal any proposals for project

Comments

@lowzj
Copy link
Member

lowzj commented Apr 27, 2020

Why you need it?

More and more customized requirements that are not covered by Dragonfly come out.

and so on.

Here is a simple plugin implementation in supernode: supernode/plugins.
But I think that it's not enough for the whole Dragonfly project including componentssupernode/dfget/dfdaemon. So there should be a plugin mechanism for Dragonfly, and put its implementation into pkg package.

How it could be?

Here is a document comparing the 3 ways to implement plugin:

Dragonfly can select a suitable solution to implement as its foundation for users to implements their own plugins conveniently.

Based on this, Dragonfly abstracts some pluggable components in the next step.
Furthermore, a new individual project dragonflyoss/plugins could be created for users to submit their plugin implementation which cannot be merged into the main project for the time being but hope to be developed in the community.

Other related information

@inoc603
Copy link
Member

inoc603 commented May 12, 2020

I think before we choose a plugin mechanism, we should refactor our code to identify the parts where customization is necessary, and make them configurable in code first.

For example, if we need adding customizable protocols in dfdaemon, we should first define the interface for a custom protocol, and probably implement http/https as one.

type Protocol interface {
  // ...
}

func WithProtocol(p Protocol) Option {
  // ...
}

Then we can define the plugin interface for users to customize. Take go plugin as an example, we may ask the user to provide a specific function in their plugin

func ProtocolFactory(config map[string]interface{}) Protocol

Then for plugins that would be widely used, we can implement them in dragonfly. For other more specific requirements, the user may choose to implement them as plugin or fork the project, and both methods will use the same interface in code.

@lowzj
Copy link
Member Author

lowzj commented May 12, 2020

I think before we choose a plugin mechanism, we should refactor our code to identify the parts where customization is necessary, and make them configurable in code first.

@inoc603 agreed. It's necessary to define an interface for a component before we make it pluggable and configurable.

But I think that the definition interface of pluggable components and the common implementation of plugin mechanism can be executed in parallel.

The plugin mechanism should provide these features:

  • provide a way for Dragonfly to select a specific implementation of a plugin
  • provide a way for user to register their own implementation of a plugin
  • provide a way to construct a plugin with configuration

And Dragonfly components can use this mechanism to make themself pluggable in a unified way.

@lowzj
Copy link
Member Author

lowzj commented May 12, 2020

I will create a project here to list and track tasks about interface definition.

@inoc603
Copy link
Member

inoc603 commented May 13, 2020

I think before we choose a plugin mechanism, we should refactor our code to identify the parts where customization is necessary, and make them configurable in code first.

@inoc603 agreed. It's necessary to define an interface for a component before we make it pluggable and configurable.

But I think that the definition interface of pluggable components and the common implementation of plugin mechanism can be executed in parallel.

The plugin mechanism should provide these features:

  • provide a way for Dragonfly to select a specific implementation of a plugin
  • provide a way for user to register their own implementation of a plugin
  • provide a way to construct a plugin with configuration

And Dragonfly components can use this mechanism to make themself pluggable in a unified way.

For dynamically loaded plugins, I think we can use a very simple configuration:

# a list of plugins that will be dynamically loaded
plugins:
-
  # type of the protocol, should be one of the plugin types provided by dragonfly
  type: protocol
  # name of the plugin
  name: nfs
  # how to load the plugin
  # take go plugin as an example, we need the path of the plugin
  path: /path/to/plugin
  # configuration for the plugin
  args:
    # any valid yaml

@lowzj
Copy link
Member Author

lowzj commented May 14, 2020

For dynamically loaded plugins, I think we can use a very simple configuration:

# a list of plugins that will be dynamically loaded
plugins:
-
  # type of the protocol, should be one of the plugin types provided by dragonfly
  type: protocol
  # name of the plugin
  name: nfs
  # how to load the plugin
  # take go plugin as an example, we need the path of the plugin
  path: /path/to/plugin
  # configuration for the plugin
  args:
    # any valid yaml

Where should the configurations be placed? An individual file or integrated with current supernod.yml/dfget.yml/dfdaemon.yml?

@zcc35357949
Copy link
Contributor

Is there any further updates for this issue?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/proposal any proposals for project
Projects
None yet
Development

No branches or pull requests

4 participants