Commit ef14a915 authored by suyanlong's avatar suyanlong

Fixed CreateClients function bug for plugin create

parent 09b5d909
Pipeline #8082 failed with stages
......@@ -142,23 +142,3 @@ func runtimePProf() {
}
}()
}
func checkPlugin(pluginName string) error {
// check if plugin exists
pluginRoot, err := repo.PluginPath()
if err != nil {
return err
}
pluginPath := filepath.Join(pluginRoot, pluginName)
_, err = os.Stat(pluginPath)
if err != nil {
if os.IsNotExist(err) {
return fmt.Errorf("plugin file `%s` is required", pluginPath)
}
return fmt.Errorf("get plugin file state error: %w", err)
}
return nil
}
......@@ -2,6 +2,7 @@ package plugins
import (
"fmt"
"os"
"os/exec"
"path/filepath"
......@@ -9,6 +10,7 @@ import (
plugin "github.com/hashicorp/go-plugin"
"github.com/link33/sidecar/internal/repo"
"github.com/link33/sidecar/tool"
)
var logger = hclog.New(&hclog.LoggerOptions{
......@@ -43,7 +45,7 @@ func CreateClient(sidecarID string, appchainConfig repo.Appchain, extra []byte)
}
// Request the plugin
raw, err := rpcClient.Dispense(PluginName)
raw, err := rpcClient.Dispense(appchainConfig.Plugin)
if err != nil {
return nil, nil, err
}
......@@ -74,7 +76,14 @@ func CreateClients(appchainConfigs repo.Appchains, extra []byte) []Client {
var clients []Client
for _, appchainConfig := range appchainConfigs.Appchains {
pluginConfigPath := filepath.Join(rootPath, appchainConfig.Config)
pluginPath := filepath.Join(rootPath, "plugins", appchainConfig.Config)
pluginPath := filepath.Join(rootPath, "plugins", appchainConfig.Plugin)
_, err = os.Stat(pluginPath)
if err != nil {
if os.IsNotExist(err) {
tool.Asset(fmt.Errorf("plugin file `%s` is required", pluginPath))
}
tool.Asset(fmt.Errorf("get plugin file state error: %w", err))
}
kernel := plugin.NewClient(&plugin.ClientConfig{
HandshakeConfig: Handshake,
Plugins: PluginMap,
......@@ -86,27 +95,21 @@ func CreateClients(appchainConfigs repo.Appchains, extra []byte) []Client {
})
// Connect via RPC
rpcClient, err := kernel.Client()
if err != nil {
panic(err)
}
tool.Asset(err)
// Request the plugin
raw, err := rpcClient.Dispense(PluginName)
if err != nil {
panic(err)
}
raw, err := rpcClient.Dispense(appchainConfig.Plugin)
tool.Asset(err)
var appchain Client
switch raw.(type) {
case *GRPCClient:
appchain = raw.(*GRPCClient)
default:
panic(fmt.Errorf("unsupported kernel type"))
tool.Asset(fmt.Errorf("unsupported kernel type"))
}
// initialize our kernel plugin
err = appchain.Initialize(pluginConfigPath, appchainConfig.DID, extra)
if err != nil {
panic(err)
}
tool.Asset(err)
appchain.Bind(kernel)
clients = append(clients, appchain)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment