Restructre clusterctl cli interface

Turn the flat list of commands into a hierarchy of commands, converting
most required parameters into positional parameters and add plugin
loading support for clusterctl.
This commit is contained in:
Hornwitser committed 2020-08-18 18:52:11 +02:00
1 parent 9b870fde64
commit da1cbc16f7
10 files changed
+783 -428

No files matched your search

+60 -1
View File
@@ -11,11 +11,26 @@ const errors = require("lib/errors");
/**
* Conceptual base for master and instance plugins.
* @typedef {module:lib/plugin.BaseMasterPlugin|module:lib/plugin.BaseInstancePlugin} module:lib/plugin.BasePlugin
* @typedef {
* module:lib/plugin.BaseMasterPlugin
* |module:lib/plugin.BaseInstancePlugin
* |module:lib/plugin.BaseControlPlugin
* } module:lib/plugin.BasePlugin
*/
/**
* Base class for instance plugins
*
* Instance plugins are subclasses of this class which get instantiated by
* the slave when it brings up an instance with the plugin enabled in the
* config. To be discovered the class must be exported under the name
* `InstancePlugin` in the module specified by the `instanceEntrypoint` in
* the plugin's info.js file.
*
* Instances may be started and stopped many times, and many instances may
* be running at the same time, each of which will have their own instance
* of the InstancePlugin class.
*
* @static
*/
class BaseInstancePlugin {
@@ -185,6 +200,13 @@ class BaseInstancePlugin {
/**
* Base class for master plugins
*
* Master plugins are subclasses of this class which get instantiated by
* the master server on startup when the plugin is enabled in the config.
* To be discovered the class must be exported under the name `MasterPlugin`
* in the module specified by the `masterEntrypoint` in the plugin's info.js
* file.
*
* @static
*/
class BaseMasterPlugin {
@@ -316,6 +338,42 @@ class BaseMasterPlugin {
}
}
/**
* Base class for clusterctl plugins
*
* Control plugins are subclasses of this class which get instantiated by
* clusterctl in order to extend its functionallity. To be discovered the
* class must be exported under the name `ControlPlugin` in the module
* specified by the `controlEntrypoint` in the plugin's info.js file.
*
* @static
*/
class BaseControlPlugin {
constructor(info) {
/**
* The plugin's own info module
*/
this.info = info;
}
/**
* Called immediately after the class is instantiated
*/
async init() { }
/**
* Called to add commands to the command line interface.
*
* Invoked by clusterctl to let plugins add commands. `rootCommand` is
* the top level command node which the plugin should add its own {@link
* module:lib/command.CommandTree} to.
*
* @param {module:lib/command.CommandTree} rootCommand -
* Root of the clusterctl command tree.
*/
async addCommands(rootCommand) { }
}
/**
* Load plugin information
*
@@ -413,6 +471,7 @@ async function invokeHook(plugins, hook, ...args) {
module.exports = {
BaseInstancePlugin,
BaseMasterPlugin,
BaseControlPlugin,
loadPluginInfos,
attachPluginMessages,