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() { ...@@ -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 ...@@ -2,6 +2,7 @@ package plugins
import ( import (
"fmt" "fmt"
"os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
...@@ -9,6 +10,7 @@ import ( ...@@ -9,6 +10,7 @@ import (
plugin "github.com/hashicorp/go-plugin" plugin "github.com/hashicorp/go-plugin"
"github.com/link33/sidecar/internal/repo" "github.com/link33/sidecar/internal/repo"
"github.com/link33/sidecar/tool"
) )
var logger = hclog.New(&hclog.LoggerOptions{ var logger = hclog.New(&hclog.LoggerOptions{
...@@ -43,7 +45,7 @@ func CreateClient(sidecarID string, appchainConfig repo.Appchain, extra []byte) ...@@ -43,7 +45,7 @@ func CreateClient(sidecarID string, appchainConfig repo.Appchain, extra []byte)
} }
// Request the plugin // Request the plugin
raw, err := rpcClient.Dispense(PluginName) raw, err := rpcClient.Dispense(appchainConfig.Plugin)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
...@@ -74,7 +76,14 @@ func CreateClients(appchainConfigs repo.Appchains, extra []byte) []Client { ...@@ -74,7 +76,14 @@ func CreateClients(appchainConfigs repo.Appchains, extra []byte) []Client {
var clients []Client var clients []Client
for _, appchainConfig := range appchainConfigs.Appchains { for _, appchainConfig := range appchainConfigs.Appchains {
pluginConfigPath := filepath.Join(rootPath, appchainConfig.Config) 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{ kernel := plugin.NewClient(&plugin.ClientConfig{
HandshakeConfig: Handshake, HandshakeConfig: Handshake,
Plugins: PluginMap, Plugins: PluginMap,
...@@ -86,27 +95,21 @@ func CreateClients(appchainConfigs repo.Appchains, extra []byte) []Client { ...@@ -86,27 +95,21 @@ func CreateClients(appchainConfigs repo.Appchains, extra []byte) []Client {
}) })
// Connect via RPC // Connect via RPC
rpcClient, err := kernel.Client() rpcClient, err := kernel.Client()
if err != nil { tool.Asset(err)
panic(err)
}
// Request the plugin // Request the plugin
raw, err := rpcClient.Dispense(PluginName) raw, err := rpcClient.Dispense(appchainConfig.Plugin)
if err != nil { tool.Asset(err)
panic(err)
}
var appchain Client var appchain Client
switch raw.(type) { switch raw.(type) {
case *GRPCClient: case *GRPCClient:
appchain = raw.(*GRPCClient) appchain = raw.(*GRPCClient)
default: default:
panic(fmt.Errorf("unsupported kernel type")) tool.Asset(fmt.Errorf("unsupported kernel type"))
} }
// initialize our kernel plugin // initialize our kernel plugin
err = appchain.Initialize(pluginConfigPath, appchainConfig.DID, extra) err = appchain.Initialize(pluginConfigPath, appchainConfig.DID, extra)
if err != nil { tool.Asset(err)
panic(err)
}
appchain.Bind(kernel) appchain.Bind(kernel)
clients = append(clients, appchain) 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