- Notifications
You must be signed in to change notification settings - Fork 54
Plugin Architecture #670
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
Plugin Architecture #670
Changes from 31 commits
7b43e43 c155135 927cc82 1fad8db 1d9fb95 08ad2bd 42a4118 7bc7ab6 5ba06aa 9071720 3f125d6 b904879 1789a53 77ac67c fcd871d 7a4ff3c f042913 e23a728 0196643 2bb6bbc 89f4d19 98c002d 7817cc7 dc05443 08b8c32 0e33b48 ec17d24 fd80b3b 3b575d6 33a9330 27ac1f3 39da86d 925f17a e351787 7311bc2 File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Plugins | ||
| | ||
| Plugins extend Warnet. Plugin authors can import commands from Warnet and interact with the kubernetes cluster, and plugin users can run plugins from the command line or from the `network.yaml` file. | ||
| | ||
| ## Activating plugins from `network.yaml` | ||
| | ||
| You can activate a plugin command by placing it in the `plugins` section at the bottom of each `network.yaml` file like so: | ||
| | ||
| ````yaml | ||
| nodes: | ||
| <<snip>> | ||
| | ||
| plugins: # This marks the beginning of the plugin section | ||
| preDeploy: # This is a hook. This particular hook will call plugins before deploying anything else. | ||
| hello: # This is the name of the plugin. | ||
| entrypoint: "../plugins/hello" # Every plugin must specify a path to its entrypoint. | ||
| podName: "hello-pre-deploy" # Plugins can have their own particular configurations, such as how to name a pod. | ||
| helloTo: "preDeploy!" # This configuration tells the hello plugin who to say "hello" to. | ||
| ```` | ||
| | ||
| ## Many kinds of hooks | ||
| There are many hooks to the Warnet `deploy` command. The example below specifies them: | ||
| | ||
| ````yaml | ||
| nodes: | ||
| <<snip>> | ||
| | ||
| plugins: | ||
| preDeploy: # Plugins will run before any other `deploy` code. | ||
| hello: | ||
| entrypoint: "../plugins/hello" | ||
| podName: "hello-pre-deploy" | ||
| helloTo: "preDeploy!" | ||
| postDeploy: # Plugins will run after all the `deploy` code has run. | ||
| simln: | ||
| entrypoint: "../plugins/simln" | ||
| activity: '[{"source": "tank-0003-ln", "destination": "tank-0005-ln", "interval_secs": 1, "amount_msat": 2000}]' | ||
| hello: | ||
| entrypoint: "../plugins/hello" | ||
| podName: "hello-post-deploy" | ||
| helloTo: "postDeploy!" | ||
| preNode: # Plugins will run before `deploy` launches a node (once per node). | ||
| hello: | ||
| entrypoint: "../plugins/hello" | ||
| helloTo: "preNode!" | ||
| postNode: # Plugins will run after `deploy` launches a node (once per node). | ||
| hello: | ||
| entrypoint: "../plugins/hello" | ||
| helloTo: "postNode!" | ||
| preNetwork: # Plugins will run before `deploy` launches the network (essentially between logging and when nodes are deployed) | ||
| hello: | ||
| entrypoint: "../plugins/hello" | ||
| helloTo: "preNetwork!" | ||
| podName: "hello-pre-network" | ||
| postNetwork: # Plugins will run after the network deploy threads have been joined. | ||
| hello: | ||
| entrypoint: "../plugins/hello" | ||
| helloTo: "postNetwork!" | ||
| podName: "hello-post-network" | ||
| ```` | ||
| | ||
| Warnet will execute these plugin commands during each invocation of `warnet deploy`. | ||
| | ||
| | ||
| | ||
| ## A "hello" example | ||
| | ||
| To get started with an example plugin, review the `README` of the `hello` plugin found in any initialized Warnet directory: | ||
| | ||
| 1. `warnet init` | ||
| 2. `cd plugins/hello/` | ||
| |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| nodes: | ||
| Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason to put this network here instead of Especially because this network.yaml generates tons of LN activity between two specific nodes, not like general network activity. It seems less default-y Collaborator Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like having the 'hello' network as as something that users get when they That said, I can understand creating a copy of the hello network in the testing directory so that all the test stuff is isolated. | ||
| - name: tank-0000 | ||
| addnode: | ||
| - tank-0001 | ||
| ln: | ||
| lnd: true | ||
| | ||
| - name: tank-0001 | ||
| addnode: | ||
| - tank-0002 | ||
| ln: | ||
| lnd: true | ||
| | ||
| - name: tank-0002 | ||
| addnode: | ||
| - tank-0000 | ||
| ln: | ||
| lnd: true | ||
| | ||
| - name: tank-0003 | ||
| addnode: | ||
| - tank-0000 | ||
| ln: | ||
| lnd: true | ||
| lnd: | ||
| config: | | ||
| bitcoin.timelockdelta=33 | ||
| channels: | ||
| - id: | ||
| block: 300 | ||
| index: 1 | ||
| target: tank-0004-ln | ||
| capacity: 100000 | ||
| push_amt: 50000 | ||
| | ||
| - name: tank-0004 | ||
| addnode: | ||
| - tank-0000 | ||
| ln: | ||
| lnd: true | ||
| lnd: | ||
| channels: | ||
| - id: | ||
| block: 300 | ||
| index: 2 | ||
| target: tank-0005-ln | ||
| capacity: 50000 | ||
| push_amt: 25000 | ||
| | ||
| - name: tank-0005 | ||
| addnode: | ||
| - tank-0000 | ||
| ln: | ||
| lnd: true | ||
| | ||
| plugins: # Each plugin section has a number of hooks available (preDeploy, postDeploy, etc) | ||
| preDeploy: # For example, the preDeploy hook means it's plugin will run before all other deploy code | ||
| hello: | ||
| entrypoint: "../../plugins/hello" # This entrypoint path is relative to the network.yaml file | ||
| podName: "hello-pre-deploy" | ||
| helloTo: "preDeploy!" | ||
| postDeploy: | ||
| hello: | ||
| entrypoint: "../../plugins/hello" | ||
| podName: "hello-post-deploy" | ||
| helloTo: "postDeploy!" | ||
| simln: # You can have multiple plugins per hook | ||
| entrypoint: "../../plugins/simln" | ||
| activity: '[{"source": "tank-0003-ln", "destination": "tank-0005-ln", "interval_secs": 1, "amount_msat": 2000}]' | ||
| preNode: # preNode plugins run before each node is deployed | ||
| hello: | ||
| entrypoint: "../../plugins/hello" | ||
| helloTo: "preNode!" | ||
| postNode: | ||
| hello: | ||
| entrypoint: "../../plugins/hello" | ||
| helloTo: "postNode!" | ||
| preNetwork: | ||
| hello: | ||
| entrypoint: "../../plugins/hello" | ||
| helloTo: "preNetwork!" | ||
| podName: "hello-pre-network" | ||
| postNetwork: | ||
| hello: | ||
| entrypoint: "../../plugins/hello" | ||
| helloTo: "postNetwork!" | ||
| podName: "hello-post-network" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| image: | ||
| repository: bitcoindevproject/bitcoin | ||
| pullPolicy: IfNotPresent | ||
| tag: "27.0" | ||
| | ||
| lnd: | ||
| defaultConfig: | | ||
| color=#000000 |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,124 @@ | ||||||||||||||||||||||||||||||||
| # Hello Plugin | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| ## Hello World! | ||||||||||||||||||||||||||||||||
| *Hello* is an example plugin to demonstrate the features of Warnet's plugin architecture. It uses each of the hooks available in the `warnet deploy` command (see the example below for details). | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| ## Usage | ||||||||||||||||||||||||||||||||
| In your python virtual environment with Warnet installed and setup, create a new Warnet user folder (follow the prompts): | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| `$ warnet new user_folder` | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| `$ cd user_folder` | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| Deploy the *hello* network. | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| `$ warnet deploy networks/hello` | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| While that is launching, take a look inside the `networks/hello/network.yaml` file. You can also see the copy below which includes commentary on the structure of plugins in the `network.yaml` file. | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| Also, take a look at the `plugins/hello/plugin.py` file to see how plugins work and to find out how to author your own plugin. | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| Once `deploy` completes, view the pods of the *hello* network by invoking `kubectl get all -A`. | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| To view the various "Hello World!" messages, run `kubectl logs pod/POD_NAME` | ||||||||||||||||||||||||||||||||
| Comment on lines +21 to +23 Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't we trying to avoid kubectl commands in the docs? Lets just reccomend Collaborator Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We could get around this by choosing to treat the first container as the primary container. Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is some logic for this already. maybe we can address in a followup: Lines 411 to 425 in 5039591
Collaborator Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If continue using the existing logic, we would need to dictate that plugins set a PLUGIN_CONTAINER as their primary container. I'm not totally opposed to that. | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| ### A `network.yaml` example | ||||||||||||||||||||||||||||||||
| When you initialize a new Warnet network, Warnet will create a new `network.yaml` file. You can modify these files to fit your needs. | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| For example, the `network.yaml` file below includes the *hello* plugin, lightning nodes, and the *simln* plugin. | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| <details> | ||||||||||||||||||||||||||||||||
| <summary>network.yaml</summary> | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| ````yaml | ||||||||||||||||||||||||||||||||
| nodes: | ||||||||||||||||||||||||||||||||
| - name: tank-0000 | ||||||||||||||||||||||||||||||||
| addnode: | ||||||||||||||||||||||||||||||||
| - tank-0001 | ||||||||||||||||||||||||||||||||
| ln: | ||||||||||||||||||||||||||||||||
| lnd: true | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| - name: tank-0001 | ||||||||||||||||||||||||||||||||
| addnode: | ||||||||||||||||||||||||||||||||
| - tank-0002 | ||||||||||||||||||||||||||||||||
| ln: | ||||||||||||||||||||||||||||||||
| lnd: true | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| - name: tank-0002 | ||||||||||||||||||||||||||||||||
| addnode: | ||||||||||||||||||||||||||||||||
| - tank-0000 | ||||||||||||||||||||||||||||||||
| ln: | ||||||||||||||||||||||||||||||||
| lnd: true | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| - name: tank-0003 | ||||||||||||||||||||||||||||||||
| addnode: | ||||||||||||||||||||||||||||||||
| - tank-0000 | ||||||||||||||||||||||||||||||||
| ln: | ||||||||||||||||||||||||||||||||
| lnd: true | ||||||||||||||||||||||||||||||||
| lnd: | ||||||||||||||||||||||||||||||||
| config: | | ||||||||||||||||||||||||||||||||
| bitcoin.timelockdelta=33 | ||||||||||||||||||||||||||||||||
| channels: | ||||||||||||||||||||||||||||||||
| - id: | ||||||||||||||||||||||||||||||||
| block: 300 | ||||||||||||||||||||||||||||||||
| index: 1 | ||||||||||||||||||||||||||||||||
| target: tank-0004-ln | ||||||||||||||||||||||||||||||||
| capacity: 100000 | ||||||||||||||||||||||||||||||||
| push_amt: 50000 | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| - name: tank-0004 | ||||||||||||||||||||||||||||||||
| addnode: | ||||||||||||||||||||||||||||||||
| - tank-0000 | ||||||||||||||||||||||||||||||||
| ln: | ||||||||||||||||||||||||||||||||
| lnd: true | ||||||||||||||||||||||||||||||||
| lnd: | ||||||||||||||||||||||||||||||||
| channels: | ||||||||||||||||||||||||||||||||
| - id: | ||||||||||||||||||||||||||||||||
| block: 300 | ||||||||||||||||||||||||||||||||
| index: 2 | ||||||||||||||||||||||||||||||||
| target: tank-0005-ln | ||||||||||||||||||||||||||||||||
| capacity: 50000 | ||||||||||||||||||||||||||||||||
| push_amt: 25000 | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| - name: tank-0005 | ||||||||||||||||||||||||||||||||
| addnode: | ||||||||||||||||||||||||||||||||
| - tank-0000 | ||||||||||||||||||||||||||||||||
| ln: | ||||||||||||||||||||||||||||||||
| lnd: true | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| plugins: # Each plugin section has a number of hooks available (preDeploy, postDeploy, etc) | ||||||||||||||||||||||||||||||||
| preDeploy: # For example, the preDeploy hook means it's plugin will run before all other deploy code | ||||||||||||||||||||||||||||||||
| hello: | ||||||||||||||||||||||||||||||||
| entrypoint: "../../plugins/hello" # This entrypoint path is relative to the network.yaml file | ||||||||||||||||||||||||||||||||
| podName: "hello-pre-deploy" | ||||||||||||||||||||||||||||||||
| helloTo: "preDeploy!" | ||||||||||||||||||||||||||||||||
| postDeploy: | ||||||||||||||||||||||||||||||||
| hello: | ||||||||||||||||||||||||||||||||
| entrypoint: "../../plugins/hello" | ||||||||||||||||||||||||||||||||
| podName: "hello-post-deploy" | ||||||||||||||||||||||||||||||||
| helloTo: "postDeploy!" | ||||||||||||||||||||||||||||||||
| simln: # You can have multiple plugins per hook | ||||||||||||||||||||||||||||||||
| entrypoint: "../../plugins/simln" | ||||||||||||||||||||||||||||||||
| activity: '[{"source": "tank-0003-ln", "destination": "tank-0005-ln", "interval_secs": 1, "amount_msat": 2000}]' | ||||||||||||||||||||||||||||||||
| preNode: # preNode plugins run before each node is deployed | ||||||||||||||||||||||||||||||||
| hello: | ||||||||||||||||||||||||||||||||
| entrypoint: "../../plugins/hello" | ||||||||||||||||||||||||||||||||
| helloTo: "preNode!" | ||||||||||||||||||||||||||||||||
| postNode: | ||||||||||||||||||||||||||||||||
| hello: | ||||||||||||||||||||||||||||||||
| entrypoint: "../../plugins/hello" | ||||||||||||||||||||||||||||||||
| helloTo: "postNode!" | ||||||||||||||||||||||||||||||||
| preNetwork: | ||||||||||||||||||||||||||||||||
| hello: | ||||||||||||||||||||||||||||||||
| entrypoint: "../../plugins/hello" | ||||||||||||||||||||||||||||||||
| helloTo: "preNetwork!" | ||||||||||||||||||||||||||||||||
| podName: "hello-pre-network" | ||||||||||||||||||||||||||||||||
| postNetwork: | ||||||||||||||||||||||||||||||||
| hello: | ||||||||||||||||||||||||||||||||
| entrypoint: "../../plugins/hello" | ||||||||||||||||||||||||||||||||
| helloTo: "postNetwork!" | ||||||||||||||||||||||||||||||||
| podName: "hello-post-network" | ||||||||||||||||||||||||||||||||
| ```` | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| </details> | ||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| apiVersion: v2 | ||
| name: hello-chart | ||
| description: A Helm chart for a hello Pod | ||
| version: 0.1.0 | ||
| appVersion: "1.0" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: {{ .Values.podName }} | ||
| labels: | ||
| app: {{ .Chart.Name }} | ||
| spec: | ||
| restartPolicy: Never | ||
| containers: | ||
| - name: {{ .Values.podName }}-container | ||
| image: alpine:latest | ||
| command: ["sh", "-c"] | ||
| args: | ||
| - echo "Hello {{ .Values.helloTo }}"; | ||
| resources: {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| podName: hello-pod | ||
| helloTo: "world" |
Uh oh!
There was an error while loading. Please reload this page.