/*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 athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed 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 andlimitations under the License.*/package pluginimport ("errors""fmt""sync")var (// ErrNoType is returned when no type is specifiedErrNoType = errors.New("plugin: no type")// ErrNoPluginID is returned when no id is specifiedErrNoPluginID = errors.New("plugin: no id")// ErrIDRegistered is returned when a duplicate id is already registeredErrIDRegistered = errors.New("plugin: id already registered")// ErrSkipPlugin is used when a plugin is not initialized and should not be loaded,// this allows the plugin loader differentiate between a plugin which is configured// not to load and one that fails to load.ErrSkipPlugin = errors.New("skip plugin")// ErrInvalidRequires will be thrown if the requirements for a plugin are// defined in an invalid manner.ErrInvalidRequires = errors.New("invalid requires"))// IsSkipPlugin returns true if the error is skipping the pluginfunc IsSkipPlugin(err error) bool {return errors.Is(err, ErrSkipPlugin)}// Type is the type of the plugintype Type stringfunc (t Type) String() string { return string(t) }const (// InternalPlugin implements an internal plugin to containerdInternalPlugin Type = "io.containerd.internal.v1"// RuntimePlugin implements a runtimeRuntimePlugin Type = "io.containerd.runtime.v1"// RuntimePluginV2 implements a runtime v2RuntimePluginV2 Type = "io.containerd.runtime.v2"// ServicePlugin implements a internal serviceServicePlugin Type = "io.containerd.service.v1"// GRPCPlugin implements a grpc serviceGRPCPlugin Type = "io.containerd.grpc.v1"// TTRPCPlugin implements a ttrpc shim serviceTTRPCPlugin Type = "io.containerd.ttrpc.v1"// SnapshotPlugin implements a snapshotterSnapshotPlugin Type = "io.containerd.snapshotter.v1"// TaskMonitorPlugin implements a task monitorTaskMonitorPlugin Type = "io.containerd.monitor.v1"// DiffPlugin implements a differDiffPlugin Type = "io.containerd.differ.v1"// MetadataPlugin implements a metadata storeMetadataPlugin Type = "io.containerd.metadata.v1"// ContentPlugin implements a content storeContentPlugin Type = "io.containerd.content.v1"// GCPlugin implements garbage collection policyGCPlugin Type = "io.containerd.gc.v1"// EventPlugin implements event handlingEventPlugin Type = "io.containerd.event.v1"// LeasePlugin implements lease managerLeasePlugin Type = "io.containerd.lease.v1"// StreamingPlugin implements a stream managerStreamingPlugin Type = "io.containerd.streaming.v1"// TracingProcessorPlugin implements a open telemetry span processorTracingProcessorPlugin Type = "io.containerd.tracing.processor.v1"// NRIApiPlugin implements the NRI adaptation interface for containerd.NRIApiPlugin Type = "io.containerd.nri.v1"// TransferPlugin implements a transfer serviceTransferPlugin Type = "io.containerd.transfer.v1"// SandboxStorePlugin implements a sandbox storeSandboxStorePlugin Type = "io.containerd.sandbox.store.v1"// SandboxControllerPlugin implements a sandbox controllerSandboxControllerPlugin Type = "io.containerd.sandbox.controller.v1")const (// RuntimeRuncV2 is the runc runtime that supports multiple containers per shimRuntimeRuncV2 = "io.containerd.runc.v2")// Registration contains information for registering a plugintype Registration struct {// Type of the pluginType Type// ID of the pluginID string// Config specific to the pluginConfig interface{}// Requires is a list of plugins that the registered plugin requires to be availableRequires []Type// InitFn is called when initializing a plugin. The registration and// context are passed in. The init function may modify the registration to// add exports, capabilities and platform support declarations.InitFn func(*InitContext) (interface{}, error)// Disable the plugin from loadingDisable bool}// Init the registered pluginfunc (r *Registration) Init(ic *InitContext) *Plugin {p, err := r.InitFn(ic)return &Plugin{Registration: r,Config: ic.Config,Meta: ic.Meta,instance: p,err: err,}}// URI returns the full plugin URIfunc (r *Registration) URI() string {return r.Type.String() + "." + r.ID}var register = struct {sync.RWMutexr []*Registration}{}// 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)}// Register allows plugins to registerfunc Register(r *Registration) {register.Lock()defer register.Unlock()if r.Type == "" {panic(ErrNoType)}if r.ID == "" {panic(ErrNoPluginID)}if err := checkUnique(r); err != nil {panic(err)}for _, requires := range r.Requires {if requires == "*" && len(r.Requires) != 1 {panic(ErrInvalidRequires)}}register.r = append(register.r, r)}func checkUnique(r *Registration) error {for _, registered := range register.r {if r.URI() == registered.URI() {return fmt.Errorf("%s: %w", r.URI(), ErrIDRegistered)}}return nil}// DisableFilter filters out disabled pluginstype DisableFilter func(r *Registration) bool// Graph returns an ordered list of registered plugins for initialization.// Plugins in disableList specified by id will be disabled.func Graph(filter DisableFilter) (ordered []*Registration) {register.RLock()defer register.RUnlock()for _, r := range register.r {if filter(r) {r.Disable = true}}added := map[*Registration]bool{}for _, r := range register.r {if r.Disable {continue}children(r, added, &ordered)if !added[r] {ordered = append(ordered, r)added[r] = true}}return ordered}func children(reg *Registration, added map[*Registration]bool, ordered *[]*Registration) {for _, t := range reg.Requires {for _, r := range register.r {if !r.Disable &&r.URI() != reg.URI() &&(t == "*" || r.Type == t) {children(r, added, ordered)if !added[r] {*ordered = append(*ordered, r)added[r] = true}}}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。