@@ -42,13 +42,15 @@ type Plugin struct {
42
42
client * plugin.Client
43
43
// Module represents the real module impl
44
44
Module Module
45
+ // dir represents the working directory of the plugin binary, which will be typically set as the stack path.
46
+ dir string
45
47
}
46
48
47
- func NewPlugin (key string ) (* Plugin , error ) {
49
+ func NewPlugin (key , dir string ) (* Plugin , error ) {
48
50
if key == "" {
49
51
return nil , fmt .Errorf ("module key can not be empty" )
50
52
}
51
- p := & Plugin {key : key }
53
+ p := & Plugin {key : key , dir : dir }
52
54
err := p .initModule ()
53
55
if err != nil {
54
56
return nil , err
@@ -75,7 +77,7 @@ func (p *Plugin) initModule() error {
75
77
return err
76
78
}
77
79
pluginName := prefix [0 ] + "-" + prefix [1 ]
78
- client , err := NewPluginClient (pluginPath , pluginName )
80
+ client , err := NewPluginClient (pluginPath , pluginName , p . dir )
79
81
if err != nil {
80
82
return err
81
83
}
@@ -122,7 +124,7 @@ func buildPluginPath(namespace, resourceType, version string) (string, error) {
122
124
return p , nil
123
125
}
124
126
125
- func NewPluginClient (modulePluginPath , moduleName string ) (* plugin.Client , error ) {
127
+ func NewPluginClient (modulePluginPath , moduleName , workingDir string ) (* plugin.Client , error ) {
126
128
// create the plugin log file
127
129
var logFilePath string
128
130
dir , err := kfile .KusionDataFolder ()
@@ -148,11 +150,14 @@ func NewPluginClient(modulePluginPath, moduleName string) (*plugin.Client, error
148
150
Level : hclog .Debug ,
149
151
})
150
152
153
+ cmd := exec .Command (modulePluginPath )
154
+ cmd .Dir = workingDir
155
+
151
156
// We're a host! Start by launching the plugin process.Need to defer kill
152
157
client := plugin .NewClient (& plugin.ClientConfig {
153
158
HandshakeConfig : HandshakeConfig ,
154
159
Plugins : PluginMap ,
155
- Cmd : exec . Command ( modulePluginPath ) ,
160
+ Cmd : cmd ,
156
161
AllowedProtocols : []plugin.Protocol {
157
162
plugin .ProtocolGRPC ,
158
163
},
0 commit comments