new CLI option dump-all-plugins

allows Kong to know which plugins are manages by a specific instance of
a plugin server.
This commit is contained in:
Javier Guerra
2020-11-22 17:22:04 -05:00
parent a443f0493c
commit 5aaf044a25
2 changed files with 39 additions and 7 deletions

View File

@@ -115,7 +115,6 @@ func (s *PluginServer) StartInstance(config PluginConfig, status *InstanceStatus
s.instances[instance.id] = &instance
plug.lastStartInstance = instance.startTime
s.expireInstances()
s.lock.Unlock()

37
main.go
View File

@@ -10,8 +10,11 @@ import (
"net"
"net/rpc"
"os"
"path"
"path/filepath"
"reflect"
"runtime"
"strings"
"time"
)
@@ -21,6 +24,7 @@ var version = "development"
var (
kongPrefix = flag.String("kong-prefix", "/usr/local/kong", "Kong prefix path (specified by the -p argument commonly used in the kong cli)")
dump = flag.String("dump-plugin-info", "", "Dump info about `plugin` as a MessagePack object")
dumpAllPlugins = flag.Bool("dump-all-plugins", false, "Dump info about all available plugins")
pluginsDir = flag.String("plugins-directory", "", "Set directory `path` where to search plugins")
showVersion = flag.Bool("version", false, "Print binary and runtime version")
)
@@ -60,6 +64,32 @@ func dumpInfo() {
_ = enc.Encode(info)
}
func dumpAll() {
s := newServer()
pluginPaths, err := filepath.Glob(path.Join(s.pluginsDir, "/*.so"))
if err != nil {
log.Printf("can't get plugin names from %s: %s", s.pluginsDir, err)
return
}
infos := make([]PluginInfo, len(pluginPaths))
for i, pluginPath := range pluginPaths {
pluginName := strings.TrimSuffix(path.Base(pluginPath), ".so")
err = s.GetPluginInfo(pluginName, &infos[i])
if err != nil {
log.Printf("can't load Plugin %s: %s", pluginName, err)
continue
}
}
var handle codec.JsonHandle
enc := codec.NewEncoder(os.Stdout, &handle)
_ = enc.Encode(infos)
}
func runServer(listener net.Listener) {
var handle codec.MsgpackHandle
handle.ReaderBufferSize = 4096
@@ -70,7 +100,6 @@ func runServer(listener net.Listener) {
for {
conn, err := listener.Accept()
if err != nil {
log.Printf("accept(): %s", err)
return
}
@@ -96,7 +125,6 @@ func startServer() {
}
rpc.RegisterName("plugin", newServer())
runServer(listener)
}
@@ -115,6 +143,11 @@ func main() {
os.Exit(0)
}
if *dumpAllPlugins {
dumpAll()
os.Exit(0)
}
if socket != "" {
go func() {
for {