diff --git a/pkg/plugin/v2/grpc.go b/pkg/plugin/v2/grpc.go index 1d5a3cbf9..eac97480e 100644 --- a/pkg/plugin/v2/grpc.go +++ b/pkg/plugin/v2/grpc.go @@ -10,6 +10,13 @@ import ( "google.golang.org/grpc" ) +var HandshakeConfig = plugin.HandshakeConfig{ + ProtocolVersion: 1, + + MagicCookieKey: "VCLUSTER_PLUGIN", + MagicCookieValue: "vcluster", +} + // GRPCProviderPlugin is an implementation of the // github.com/hashicorp/go-plugin#Plugin and // github.com/hashicorp/go-plugin#GRPCPlugin interfaces diff --git a/pkg/plugin/v2/plugin.go b/pkg/plugin/v2/plugin.go index e39afd1e3..afee03930 100644 --- a/pkg/plugin/v2/plugin.go +++ b/pkg/plugin/v2/plugin.go @@ -10,6 +10,7 @@ import ( "path/filepath" "time" + "github.com/hashicorp/go-hclog" "github.com/hashicorp/go-plugin" plugintypes "github.com/loft-sh/vcluster/pkg/plugin/types" "github.com/loft-sh/vcluster/pkg/plugin/v2/pluginv2" @@ -296,36 +297,44 @@ func (m *Manager) buildInitRequest( } func (m *Manager) loadPlugin(pluginPath string) error { + // Create an hclog.Logger + logger := hclog.New(&hclog.LoggerOptions{ + Name: "plugin", + Output: os.Stdout, + Level: hclog.Info, + }) + // connect to plugin - client := plugin.NewClient(&plugin.ClientConfig{ - HandshakeConfig: plugin.HandshakeConfig{ - ProtocolVersion: 1, - }, + pluginClient := plugin.NewClient(&plugin.ClientConfig{ + HandshakeConfig: HandshakeConfig, + Logger: logger, Plugins: map[string]plugin.Plugin{ "plugin": &GRPCProviderPlugin{}, }, Cmd: exec.Command(pluginPath), + SyncStdout: os.Stdout, + SyncStderr: os.Stderr, AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC}, }) // Connect via RPC - rpcClient, err := client.Client() + rpcClient, err := pluginClient.Client() if err != nil { - client.Kill() + pluginClient.Kill() return err } // Request the plugin raw, err := rpcClient.Dispense("plugin") if err != nil { - client.Kill() + pluginClient.Kill() return err } // add to loaded plugins m.Plugins = append(m.Plugins, &vClusterPlugin{ Path: pluginPath, - Client: client, + Client: pluginClient, GRPCClient: raw.(pluginv2.PluginClient), }) diff --git a/pkg/types/types.go b/pkg/types/types.go index 5e07abed6..cd98e2193 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -9,13 +9,17 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -type Object interface { +type Base interface { Name() string +} + +type Object interface { + Base Resource() client.Object } type Exporter interface { - Name() string + Base Register() }