{"action":"created","issue":{"url":"https://api.github.com/repos/kelseyhightower/confd/issues/568","repository_url":"https://api.github.com/repos/kelseyhightower/confd","labels_url":"https://api.github.com/repos/kelseyhightower/confd/issues/568/labels{/name}","comments_url":"https://api.github.com/repos/kelseyhightower/confd/issues/568/comments","events_url":"https://api.github.com/repos/kelseyhightower/confd/issues/568/events","html_url":"https://github.com/kelseyhightower/confd/pull/568","id":234272450,"node_id":"MDExOlB1bGxSZXF1ZXN0MTI0NDY2ODAz","number":568,"title":"Plugin system","user":{"login":"okushchenko","id":8613413,"node_id":"MDQ6VXNlcjg2MTM0MTM=","avatar_url":"https://avatars3.githubusercontent.com/u/8613413?v=4","gravatar_id":"","url":"https://api.github.com/users/okushchenko","html_url":"https://github.com/okushchenko","followers_url":"https://api.github.com/users/okushchenko/followers","following_url":"https://api.github.com/users/okushchenko/following{/other_user}","gists_url":"https://api.github.com/users/okushchenko/gists{/gist_id}","starred_url":"https://api.github.com/users/okushchenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/okushchenko/subscriptions","organizations_url":"https://api.github.com/users/okushchenko/orgs","repos_url":"https://api.github.com/users/okushchenko/repos","events_url":"https://api.github.com/users/okushchenko/events{/privacy}","received_events_url":"https://api.github.com/users/okushchenko/received_events","type":"User","site_admin":false},"labels":[{"id":58843393,"node_id":"MDU6TGFiZWw1ODg0MzM5Mw==","url":"https://api.github.com/repos/kelseyhightower/confd/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2017-06-07T16:42:37Z","updated_at":"2018-09-11T04:48:36Z","closed_at":null,"author_association":"COLLABORATOR","pull_request":{"url":"https://api.github.com/repos/kelseyhightower/confd/pulls/568","html_url":"https://github.com/kelseyhightower/confd/pull/568","diff_url":"https://github.com/kelseyhightower/confd/pull/568.diff","patch_url":"https://github.com/kelseyhightower/confd/pull/568.patch"},"body":"# Plugin system\r\n\r\nThe plugin system is implemented using https://github.com/hashicorp/go-plugin, which is successfully used in Terraform, Packer, Nomad, and Vault. It's based on either gRPC or net/rpc over the local network connection. Plugins are Go interface implementations, which maps quite good to the current backends implementation.\r\n\r\nThe core set of plugins is defined in `builtin/` directory. They are compiled in the main binary.\r\n\r\nBuiltin plugins are called using the special cli command:\r\n```sh\r\nconfd internal-plugin <pluginType> <pluginName>\r\n```\r\n\r\nThe only `pluginType` in use is `database`.\r\n\r\nPlugin discovery mechanism will look for binaries named using `confd-database-*` format in the following locations:\r\n1. A path where Confd is installed\r\n2. A path where Confd is invoked\r\n\r\nTo preserve backward compatibility, the configuration is passed to built-in plugins in the form of a `map[string]string` as a parameter to the `Configure` method.\r\n\r\nA third-party plugin should manage its own config directly. The `map[string]string` passed to a third-party plugin in `Configure` method will be empty.\r\n\r\n## Interface changes\r\n\r\nThe new interface which plugins implement has the new method `Configure`, which is used to decouple plugin configuration from the core of Confd. This method is called to initialize a plugin with a config. A config is passed to a plugin in a form of `map[string]string`. Config deserialization is done using `github.com/mitchellh/mapstructure`, which is a simple and a safe way to convert a map to a Go struct. A plugin may extract values from a map directly, but this behavior is unsafe and discouraged.\r\n\r\n`stopChan` and `waitIndex` parameters were removed from `WatchPrefix` method because they are redundant.\r\n\r\n```go\r\ntype Database interface {\r\n\tGetValues(keys []string) (map[string]string, error)\r\n\tWatchPrefix(prefix string, keys []string, results chan string) error\r\n\tConfigure(map[string]string) error\r\n}\r\n```\r\n\r\n## How to write a plugin\r\n\r\nAny builtin plugin can be used as an example of how to write a plugin for Confd.\r\nAll builtin plugins can be compiled to external plugins by running `go build` from the respectful plugin directory in `builtin/bins`. For example, to compile env plugin to an external plugin:\r\n```sh\r\ncd builtin/bins/env\r\ngo build -o ../../../bin/confd-database-env-test\r\n```\r\n\r\nThe code which is used to run a plugin is very simple:\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"github.com/kelseyhightower/confd/builtin/databases/env\"\r\n\t\"github.com/kelseyhightower/confd/plugin\"\r\n)\r\n\r\nfunc main() {\r\n\tplugin.Serve(&plugin.ServeOpts{\r\n\t\tDatabaseFunc: env.Database,\r\n\t})\r\n}\r\n```\r\n\r\nYou can use generated `confd-database-env-test` plugin binary like that:\r\n```sh\r\n./bin/confd --confdir ./integration/confdir --backend env-test --one-time\r\n```"},"comment":{"url":"https://api.github.com/repos/kelseyhightower/confd/issues/comments/420145646","html_url":"https://github.com/kelseyhightower/confd/pull/568#issuecomment-420145646","issue_url":"https://api.github.com/repos/kelseyhightower/confd/issues/568","id":420145646,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMDE0NTY0Ng==","user":{"login":"abtreece","id":607993,"node_id":"MDQ6VXNlcjYwNzk5Mw==","avatar_url":"https://avatars2.githubusercontent.com/u/607993?v=4","gravatar_id":"","url":"https://api.github.com/users/abtreece","html_url":"https://github.com/abtreece","followers_url":"https://api.github.com/users/abtreece/followers","following_url":"https://api.github.com/users/abtreece/following{/other_user}","gists_url":"https://api.github.com/users/abtreece/gists{/gist_id}","starred_url":"https://api.github.com/users/abtreece/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abtreece/subscriptions","organizations_url":"https://api.github.com/users/abtreece/orgs","repos_url":"https://api.github.com/users/abtreece/repos","events_url":"https://api.github.com/users/abtreece/events{/privacy}","received_events_url":"https://api.github.com/users/abtreece/received_events","type":"User","site_admin":false},"created_at":"2018-09-11T04:48:36Z","updated_at":"2018-09-11T04:48:36Z","author_association":"CONTRIBUTOR","body":"@okushchenko what needs to happen to move this PR and subsequently this project forward? This PR and Confd as a whole is starting to feel a bit neglected at this point. I am using confd extensively for my primary job and would like to see it continue to advance. I'm sure many others feel similarly."}}
{"actor":{"display_login":"abtreece"}}