Skip to content

Commit b187ba2

Browse files
author
kakzhou719
committed
add example,readme and gitignore file
1 parent fcbe61f commit b187ba2

File tree

6 files changed

+191
-21
lines changed

6 files changed

+191
-21
lines changed

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
_output
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
.idea
14+
seautil/seautil
15+
sealer/sealer
16+
*.swp
17+
18+
pkg/cloud/dashboard/target/
19+
pkg/cloud/dashboard/dist/
20+
pkg/cloud/dashboard/Cargo.lock
21+
22+
docs/site/node_modules
23+
docs/site/package-lock.json
24+

README.md

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
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

517
PluginSpec defines the desired state of Plugin
@@ -13,27 +25,33 @@ 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`s scope, it is usually the role name, support use '|' to specify multiple scopes. if
31+
not set, default is all hosts excluding cluster type plugins.
32+
* for `PluginSpec.Action`: phase of this plugin will run. if action is `host type`,will execute on `PluginSpec.Scope`
33+
specified, if it is `cluster type` , only execute plugin at master0. below is the phase list we currently supported.
2034

2135
plugin will be executed by `PluginSpec.Name` in alphabetical order at the same stage.
2236

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 |
39-
37+
The following is a detailed introduction for plugin action.it is divided into 2 categories, one is the `host type`
38+
plugin and the other is the `cluster type` plugin.
39+
40+
| action name | action scope | category| explanation |
41+
| :-----| ----: | ----: |----: |
42+
| pre-init-host | all host |host type | will run before init cluster host |
43+
| post-init-host | all host | host type| will run after init cluster host |
44+
| pre-clean-host | all host | host type| will run before clean cluster host |
45+
| post-clean-host | all host | host type| will run after clean cluster host |
46+
| pre-install | master0 | cluster type| will run before install cluster |
47+
| post-install | master0 |cluster type | will run after install cluster |
48+
| pre-uninstall | master0 |cluster type | will run before uninstall cluster |
49+
| post-uninstall | master0 | cluster type| will run after uninstall cluster |
50+
| pre-scaleup | master0 | cluster type| will run before scaleup cluster |
51+
| post-scaleup | master0 | cluster type| will run after scaleup cluster |
52+
| upgrade-host | all host | host type| will run before upgrade cluster |
53+
| upgrade | master0 | cluster type| will run for upgrading cluster |
54+
55+
## How to use
56+
57+
see more details see [example here](./plugins/example/readme.md)

plugins/example/Clusterfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: sealer.io/v2
2+
kind: Cluster
3+
metadata:
4+
name: default-kubernetes-cluster
5+
spec:
6+
image: docker.io/sealerio/kubernetes:v1.22.15
7+
ssh:
8+
passwd: xxx
9+
hosts:
10+
- ips: [ 192.168.0.2,192.168.0.3,192.168.0.4 ]
11+
roles: [ master ]
12+
- ips: [ 192.168.0.5 ]
13+
roles: [ node ]
14+
---
15+
apiVersion: sealer.io/v2
16+
kind: Plugin
17+
metadata:
18+
name: pre_install
19+
spec:
20+
type: SHELL
21+
action: pre-install
22+
data: |
23+
set -e;set -x
24+
echo "i am a pre-install plugin from clusterfile"

plugins/example/Kubefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM docker.io/sealerio/kubernetes:v1-22-15-sealerio-2
2+
COPY example.yaml plugins/

plugins/example/example.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright © 2021 Alibaba Group Holding Ltd.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: sealer.io/v2
16+
kind: Plugin
17+
metadata:
18+
name: pre_init_host # Specify this plugin name,will dump in $rootfs/plugin dir.
19+
spec:
20+
type: SHELL
21+
action: pre-init-host
22+
scope: master
23+
data: |
24+
set -e;set -x
25+
echo "i am pre init host plugin"

plugins/example/readme.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# example plugin
2+
3+
## How to use
4+
5+
### use plugin though Kubefile
6+
7+
Define the default plugin in Kubefile to build the image and run it.
8+
9+
In many cases it is possible to use plugins without using Clusterfile, essentially sealer stores the Clusterfile plugin
10+
configuration in the Rootfs/Plugins directory before using it, so we can define the default plugin when we build the
11+
image.
12+
13+
Plugin configuration shell.yaml:
14+
15+
```yaml
16+
apiVersion: sealer.io/v2
17+
kind: Plugin
18+
metadata:
19+
name: post_install # Specify this plugin name,will dump in $rootfs/plugin dir.
20+
spec:
21+
type: SHELL
22+
action: post-install
23+
data: |
24+
set -e;set -x
25+
echo "i am post install plugin"
26+
```
27+
28+
Kubefile:
29+
30+
```shell script
31+
FROM docker.io/sealerio/kubernetes:v1-22-15-sealerio-2
32+
COPY example.yaml plugins/
33+
```
34+
35+
Build a Sealer Image that contains a plugin (or more plugins):
36+
37+
```shell script
38+
sealer build -t kubernetes-with-plugin:v1 .
39+
```
40+
41+
Run the image and the plugin will also be executed without having to define the plugin in the Clusterfile:
42+
`sealer run kubernetes-with-plugin:v1 -m x.x.x.x -p xxx`
43+
44+
### use plugin though Clusterfile
45+
46+
For example, set node label after install kubernetes cluster:
47+
48+
```yaml
49+
apiVersion: sealer.io/v2
50+
kind: Cluster
51+
metadata:
52+
name: default-kubernetes-cluster
53+
spec:
54+
image: docker.io/sealerio/kubernetes:v1.22.15
55+
ssh:
56+
passwd: xxx
57+
hosts:
58+
- ips: [ 192.168.0.2,192.168.0.3,192.168.0.4 ]
59+
roles: [ master ]
60+
- ips: [ 192.168.0.5 ]
61+
roles: [ node ]
62+
---
63+
apiVersion: sealer.io/v2
64+
kind: Plugin
65+
metadata:
66+
name: pre_install
67+
spec:
68+
type: SHELL
69+
action: pre-install
70+
data: |
71+
set -e;set -x
72+
echo "i am a plugin from clusterfile"
73+
```
74+
75+
```shell script
76+
sealer apply -f Clusterfile
77+
```

0 commit comments

Comments
 (0)