11# plugins
22
3+ ## What is plugin
4+
5+ Sealer provide plugin mechanism that allows users to run sealer image according to different plugin configurations.
6+
7+ This will bring the possibility of flexible configuration of any image default setting, any cluster node, any cluster
8+ startup stage, such as host disk initialization, cluster preflight ,status checker before or after cluster installation
9+ and so on.
10+
11+ At present, sealer only support the ` shell ` type plugins. it provides a shell operation entry that means user could
12+ execute any shell scripts on any node at any cluster launch stage. user only need to do is writing a yaml file which
13+ defined shell data and its scope to experience sealer plugin feature.
14+
315## Plugin Spec
416
517PluginSpec defines the desired state of Plugin
@@ -13,27 +25,99 @@ type PluginSpec struct {
1325}
1426```
1527
16- 1 . for ` PluginSpec.Type ` : plugin type,currently only supported "SHELL".
17- 2 . for ` PluginSpec.Data ` : plugin`s real data, sealer will use it to do actual action.
18- 3 . for ` PluginSpec.Scope ` : plugin`s scope, it is usually the role name, support use '|' to specify multiple scopes.
19- 4 . for ` PluginSpec.Action ` : phase of this plugin will run. below is the phase list we currently supported.
28+ * for ` PluginSpec.Type ` : plugin type,currently only supported "SHELL".
29+ * for ` PluginSpec.Data ` : plugin`s real data, sealer will use it to do actual action.
30+ * for ` PluginSpec.Scope ` : plugin scope, it is usually the role name, support use '|' to specify multiple scopes.
31+ * for ` PluginSpec.Action ` : phase of this plugin will run. if action is ` host type ` ,will execute on ` PluginSpec.Scope `
32+ specified, if it is ` cluster type ` , only execute plugin at master0. below is the phase list we currently supported.
2033
2134plugin will be executed by ` PluginSpec.Name ` in alphabetical order at the same stage.
2235
23- The following is a detailed introduction for plugin action.
24-
25- | action name | action scope | explanation |
26- | :-----| ----: | :----: |
27- | pre-init-host | cluster host | will run before init cluster host |
28- | post-init-host | cluster host | will run after init cluster host |
29- | pre-clean-host | cluster host | will run before clean cluster host |
30- | post-clean-host | cluster host | will run after clean cluster host |
31- | pre-install | master0 | will run before install cluster |
32- | post-install | master0 | will run after install cluster |
33- | pre-uninstall | master0 | will run before uninstall cluster |
34- | post-uninstall | master0 | will run after uninstall cluster |
35- | pre-scaleup | master0 | will run before scaleup cluster |
36- | post-scaleup | master0 | will run after scaleup cluster |
37- | upgrade-host | cluster host | will run before upgrade cluster |
38- | upgrade | master0 | will run for upgrading cluster |
36+ The following is a detailed introduction for plugin action.it is divided into 2 categories, one is the ` host type `
37+ plugin and the other is the ` cluster type ` plugin.
38+
39+ | action name | action scope | category| explanation |
40+ | :-----| ----: | ----: | ----: |
41+ | pre-init-host | all host | host type | will run before init cluster host |
42+ | post-init-host | all host | host type| will run after init cluster host |
43+ | pre-clean-host | all host | host type| will run before clean cluster host |
44+ | post-clean-host | all host | host type| will run after clean cluster host |
45+ | pre-install | master0 | cluster type| will run before install cluster |
46+ | post-install | master0 | cluster type | will run after install cluster |
47+ | pre-uninstall | master0 | cluster type | will run before uninstall cluster |
48+ | post-uninstall | master0 | cluster type| will run after uninstall cluster |
49+ | pre-scaleup | master0 | cluster type| will run before scaleup cluster |
50+ | post-scaleup | master0 | cluster type| will run after scaleup cluster |
51+ | upgrade-host | all host | host type| will run before upgrade cluster |
52+ | upgrade | master0 | cluster type| will run for upgrading cluster |
53+
54+ ## How to use
55+
56+ ### use plugin though Kubefile
57+
58+ Define the default plugin in Kubefile to build the image and run it.
59+
60+ In many cases it is possible to use plugins without using Clusterfile, essentially sealer stores the Clusterfile plugin
61+ configuration in the Rootfs/Plugins directory before using it, so we can define the default plugin when we build the
62+ image.
63+
64+ For example, build a new sealer image with plugins/example/example.yaml, only need to do is coping your plugin file
65+ to ` plugins/ ` directory.
66+
67+ Kubefile:
68+
69+ ``` shell script
70+ FROM docker.io/sealerio/kubernetes:v1-22-15-sealerio-2
71+ COPY example.yaml plugins/
72+ ```
73+
74+ Build a Sealer Image that contains a plugin (or more plugins):
75+
76+ ``` shell script
77+ sealer build -t kubernetes-with-plugin:v1 .
78+ ```
79+
80+ Run the image and the plugin will also be executed without having to define the plugin in the Clusterfile:
81+ ` sealer run kubernetes-with-plugin:v1 -m x.x.x.x -p xxx `
82+
83+ ### use plugin though Clusterfile
84+
85+ For example, set plugins/example/example.yaml content at clusterfile:
86+
87+ ``` yaml
88+ apiVersion : sealer.io/v2
89+ kind : Cluster
90+ metadata :
91+ name : default-kubernetes-cluster
92+ spec :
93+ image : docker.io/sealerio/kubernetes:v1.22.15
94+ ssh :
95+ passwd : xxx
96+ hosts :
97+ - ips : [ 192.168.0.2,192.168.0.3,192.168.0.4 ]
98+ roles : [ master ]
99+ - ips : [ 192.168.0.5 ]
100+ roles : [ node ]
101+ ---
102+ apiVersion : sealer.io/v2
103+ kind : Plugin
104+ metadata :
105+ name : pre_init_host
106+ spec :
107+ type : SHELL
108+ action : pre-init-host
109+ scope : master
110+ data : |
111+ set -e;set -x
112+ echo "i am pre init host plugin"
113+ ` ` `
114+
115+ ` ` ` shell script
116+ sealer apply -f Clusterfile
117+ ```
118+
119+ ## Available plugin list
39120
121+ | name | owner | category| link | description |
122+ | :-----| ----: | ----: | ----: | ----: |
123+ | example | sealer community | host type | plugins/example/example.yaml| just a little plugin example for user to quickly experience |
0 commit comments