Skip to content

Commit

Permalink
Merge pull request #1460 from FabianKramm/pluginv2
Browse files Browse the repository at this point in the history
fix: plugin v2 problems
  • Loading branch information
FabianKramm authored Jan 18, 2024
2 parents fb72265 + 3c67d9c commit 93a9126
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
7 changes: 7 additions & 0 deletions pkg/plugin/v2/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 17 additions & 8 deletions pkg/plugin/v2/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
})

Expand Down
8 changes: 6 additions & 2 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down

0 comments on commit 93a9126

Please sign in to comment.