diff --git a/docs/design/global-config.md b/docs/design/global-config.md index d215263fbfc..11d53707182 100644 --- a/docs/design/global-config.md +++ b/docs/design/global-config.md @@ -123,5 +123,5 @@ CMD helm install mysql -f etc/redis-config.yaml Before mounting Rootfs, templates need to be rendered for the files in etc, charts, and manifest directories, and render environment variables and annotations to the [configuration file]( -https://github.com/sealerio/sealer/blob/main/pkg/filesystem/filesystem.go#L145). +https://github.com/sealerio/sealer/blob/release-v0.8.6/pkg/filesystem/filesystem.go#L145). Generate the global.yaml file to the etc directory \ No newline at end of file diff --git a/docs/design/global-config_zh.md b/docs/design/global-config_zh.md index 2323abd7d81..11c3ce8acc4 100644 --- a/docs/design/global-config_zh.md +++ b/docs/design/global-config_zh.md @@ -88,5 +88,5 @@ CMD helm install dashboard dashboard-chart -f etc/global.yaml ## 开发文档 1. 在apply mountRootfs之前对etc,charts,manifest目录下的文件进行模板渲染,把环境变量和annotations渲染到[配置文件中]( - https://github.com/sealerio/sealer/blob/main/pkg/filesystem/filesystem.go#L145) 。 + https://github.com/sealerio/sealer/blob/release-v0.8.6/pkg/filesystem/filesystem.go#L145) 。 2. 生成global.yaml文件到etc目录下。 diff --git a/pkg/plugin/plugins.go b/pkg/plugin/plugins.go index 8d29dda896f..f88c40ad63d 100644 --- a/pkg/plugin/plugins.go +++ b/pkg/plugin/plugins.go @@ -23,15 +23,13 @@ import ( "plugin" "strings" - "github.com/sealerio/sealer/utils" - - "github.com/sealerio/sealer/utils/yaml" - "github.com/sealerio/sealer/common" v1 "github.com/sealerio/sealer/types/api/v1" v2 "github.com/sealerio/sealer/types/api/v2" + "github.com/sealerio/sealer/utils" "github.com/sealerio/sealer/utils/platform" strUtils "github.com/sealerio/sealer/utils/strings" + "github.com/sealerio/sealer/utils/yaml" ) type InvalidPluginTypeError struct { @@ -74,6 +72,7 @@ func (c *PluginsProcessor) Load() error { if err != nil { return fmt.Errorf("failed to load plugin dir: %v", err) } + for _, f := range files { // load shared object(.so) file if filepath.Ext(f.Name()) == ".so" { @@ -87,23 +86,36 @@ func (c *PluginsProcessor) Load() error { if yaml.Matcher(f.Name()) { plugins, err := utils.DecodeCRDFromFile(filepath.Join(path, f.Name()), common.Plugin) if err != nil { - return fmt.Errorf("failed to load plugin: %v", err) - } - var plugs []v1.Plugin - for _, p := range plugins.([]v1.Plugin) { - for _, cp := range c.Plugins { - if !isSamePluginSpec(p, cp) { - plugs = append(plugs, p) - } - } + return fmt.Errorf("failed to load plugin %v", err) } - c.Plugins = append(c.Plugins, plugs...) + + c.Plugins = append(c.Plugins, plugins.([]v1.Plugin)...) + i := deduplication(c.Plugins) + c.Plugins = i } } return nil } +func deduplication(plugins []v1.Plugin) []v1.Plugin { + result := make([]v1.Plugin, len(plugins)) + resultIdx := 0 + for i := 0; i < len(plugins); i++ { + for j := 0; j <= i; j++ { + if plugins[i].Spec.Data == plugins[j].Spec.Data && plugins[i].Spec.Type == plugins[j].Spec.Type && + plugins[i].Spec.On == plugins[j].Spec.On && plugins[i].Spec.Action == plugins[j].Spec.Action { + if i == j { + result[resultIdx] = plugins[i] + resultIdx++ + } + break + } + } + } + return result[:resultIdx] +} + // Run execute each in-tree or out-of-tree plugin by traversing the plugin list. func (c *PluginsProcessor) Run(host []net.IP, phase Phase) error { for _, plug := range c.Plugins { diff --git a/pkg/plugin/utils.go b/pkg/plugin/utils.go index adde95b9bb7..adde4ac2fbe 100644 --- a/pkg/plugin/utils.go +++ b/pkg/plugin/utils.go @@ -19,8 +19,6 @@ import ( "net" "strings" - v1 "github.com/sealerio/sealer/types/api/v1" - utilsnet "github.com/sealerio/sealer/utils/net" "github.com/sirupsen/logrus" @@ -66,8 +64,3 @@ func GetIpsByOnField(on string, context Context, phase Phase) (ipList []net.IP, } return ipList, nil } - -func isSamePluginSpec(p1, p2 v1.Plugin) bool { - return p1.Spec.Type == p2.Spec.Type && p1.Spec.On == p2.Spec.On && - p1.Spec.Data == p2.Spec.Data && p1.Spec.Action == p2.Spec.Action -}