@@ -42,13 +42,15 @@ type Plugin struct {
4242 client * plugin.Client
4343 // Module represents the real module impl
4444 Module Module
45+ // dir represents the working directory of the plugin binary, which will be typically set as the stack path.
46+ dir string
4547}
4648
47- func NewPlugin (key string ) (* Plugin , error ) {
49+ func NewPlugin (key , dir string ) (* Plugin , error ) {
4850 if key == "" {
4951 return nil , fmt .Errorf ("module key can not be empty" )
5052 }
51- p := & Plugin {key : key }
53+ p := & Plugin {key : key , dir : dir }
5254 err := p .initModule ()
5355 if err != nil {
5456 return nil , err
@@ -75,7 +77,7 @@ func (p *Plugin) initModule() error {
7577 return err
7678 }
7779 pluginName := prefix [0 ] + "-" + prefix [1 ]
78- client , err := NewPluginClient (pluginPath , pluginName )
80+ client , err := NewPluginClient (pluginPath , pluginName , p . dir )
7981 if err != nil {
8082 return err
8183 }
@@ -122,7 +124,7 @@ func buildPluginPath(namespace, resourceType, version string) (string, error) {
122124 return p , nil
123125}
124126
125- func NewPluginClient (modulePluginPath , moduleName string ) (* plugin.Client , error ) {
127+ func NewPluginClient (modulePluginPath , moduleName , workingDir string ) (* plugin.Client , error ) {
126128 // create the plugin log file
127129 var logFilePath string
128130 dir , err := kfile .KusionDataFolder ()
@@ -148,11 +150,14 @@ func NewPluginClient(modulePluginPath, moduleName string) (*plugin.Client, error
148150 Level : hclog .Debug ,
149151 })
150152
153+ cmd := exec .Command (modulePluginPath )
154+ cmd .Dir = workingDir
155+
151156 // We're a host! Start by launching the plugin process.Need to defer kill
152157 client := plugin .NewClient (& plugin.ClientConfig {
153158 HandshakeConfig : HandshakeConfig ,
154159 Plugins : PluginMap ,
155- Cmd : exec . Command ( modulePluginPath ) ,
160+ Cmd : cmd ,
156161 AllowedProtocols : []plugin.Protocol {
157162 plugin .ProtocolGRPC ,
158163 },
0 commit comments