MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / doLoad

Function doLoad

app/controlplane/plugins/plugins.go:91–130  ·  view source on GitHub ↗
(memoryLoader pluginsLoader, dirLoader pluginsLoader, logger *log.Helper)

Source from the content-addressed store, hash-verified

89}
90
91func doLoad(memoryLoader pluginsLoader, dirLoader pluginsLoader, logger *log.Helper) (plugins sdk.AvailablePlugins, err error) {
92 defer func() {
93 if err != nil {
94 // If there is an error, we need to clean up the plugins that were loaded
95 plugins.Cleanup()
96 }
97 }()
98
99 // Get actual plugins running processes
100 plugins, err = dirLoader.load()
101 if err != nil {
102 return plugins, fmt.Errorf("failed to load plugins: %w", err)
103 }
104
105 fromMemoryPlugins, err := memoryLoader.load()
106 if err != nil {
107 return plugins, fmt.Errorf("failed to load plugins: %w", err)
108 }
109
110 // load built-in plugins but skip them if they are loaded already as actual plugins
111 // It will enable us to rollout plugins iteratively
112BUILT_IN_LOOP:
113 for _, builtInPlugin := range fromMemoryPlugins {
114 for _, p := range plugins {
115 if p.Describe().ID == builtInPlugin.Describe().ID {
116 logger.Infow("msg", "plugin already loaded", "type", "built-in", "plugin", p.String())
117 continue BUILT_IN_LOOP
118 }
119 }
120
121 logger.Infow("msg", "loaded", "type", "built-in", "plugin", builtInPlugin.String())
122 plugins = append(plugins, &sdk.FanOutP{FanOut: builtInPlugin, DisposeFunc: func() {}})
123 }
124
125 sort.Slice(plugins, func(i, j int) bool {
126 return plugins[i].Describe().ID < plugins[j].Describe().ID
127 })
128
129 return plugins, nil
130}
131
132func (l *memoryLoader) load() (sdk.AvailablePlugins, error) {
133 res := make(sdk.AvailablePlugins, 0, len(l.plugins))

Callers 2

LoadFunction · 0.85
TestDoLoadFunction · 0.85

Calls 5

CleanupMethod · 0.65
loadMethod · 0.65
DescribeMethod · 0.65
InfowMethod · 0.65
StringMethod · 0.65

Tested by 1

TestDoLoadFunction · 0.68