Move dynamic plugins to a subpackage

Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
Derek McGowan 2023-10-12 15:37:26 -07:00
parent 7b2a918213
commit 71f8b4357e
No known key found for this signature in database
GPG Key ID: F58C5D0A4405ACDB
5 changed files with 41 additions and 21 deletions

37
plugin/dynamic/dynamic.go Normal file
View File

@ -0,0 +1,37 @@
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package dynamic
import "fmt"
// Load loads all plugins at the provided path into containerd.
//
// Load is currently only implemented on non-static, non-gccgo builds for amd64
// and arm64, and plugins must be built with the exact same version of Go as
// containerd itself.
func Load(path string) (err error) {
defer func() {
if v := recover(); v != nil {
rerr, ok := v.(error)
if !ok {
rerr = fmt.Errorf("%s", v)
}
err = rerr
}
}()
return loadPlugins(path)
}

View File

@ -16,7 +16,7 @@
limitations under the License.
*/
package plugin
package dynamic
import (
"fmt"

View File

@ -16,7 +16,7 @@
limitations under the License.
*/
package plugin
package dynamic
// loadPlugins is not supported;
//

View File

@ -96,24 +96,6 @@ func (r *Registration) URI() string {
return r.Type.String() + "." + r.ID
}
// Load loads all plugins at the provided path into containerd.
//
// Load is currently only implemented on non-static, non-gccgo builds for amd64
// and arm64, and plugins must be built with the exact same version of Go as
// containerd itself.
func Load(path string) (err error) {
defer func() {
if v := recover(); v != nil {
rerr, ok := v.(error)
if !ok {
rerr = fmt.Errorf("%s", v)
}
err = rerr
}
}()
return loadPlugins(path)
}
// DisableFilter filters out disabled plugins
type DisableFilter func(r *Registration) bool

View File

@ -46,6 +46,7 @@ import (
"github.com/containerd/containerd/pkg/timeout"
"github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/plugin/dynamic"
"github.com/containerd/containerd/plugin/registry"
"github.com/containerd/containerd/plugins"
srvconfig "github.com/containerd/containerd/services/server/config"
@ -434,7 +435,7 @@ func LoadPlugins(ctx context.Context, config *srvconfig.Config) ([]plugin.Regist
if path == "" {
path = filepath.Join(config.Root, "plugins")
}
if err := plugin.Load(path); err != nil {
if err := dynamic.Load(path); err != nil {
return nil, err
}
// load additional plugins that don't automatically register themselves