-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Allow inlining of golang plugins #928
Comments
Here's an example how a plugin can leverage this. The sample in https://github.com/rhuss/kn-service-log shows the registration process:
package plugin
import (
"os"
"knative.dev/client/pkg/kn/plugin"
"github.com/rhuss/kn-service-log/pkg"
)
func init() {
plugin.InternalPlugins = append(plugin.InternalPlugins, &logPlugin{})
}
type logPlugin struct {}
func (l *logPlugin) Name() string {
return "kn-service-log"
}
func (l *logPlugin) Execute(args []string) error {
cmd := pkg.NewLogCommand()
oldArgs := os.Args
defer (func() {
os.Args = oldArgs
})()
os.Args = append([]string { "kn-service-log" }, args...)
return cmd.Execute()
}
func (l *logPlugin) Description() (string, error) {
return "Print logs of pods belonging to a service", nil
}
func (l *logPlugin) CommandParts() []string {
return []string{ "service", "log" }
}
// Path is empty because its an internal plugins
func (l *logPlugin) Path() string {
return ""
}
func init() {
plugin.InternalPlugins = append(plugin.InternalPlugins, &logPlugin{})
}
package root
import (
_ "github.com/rhuss/kn-service-log/plugin"
)
// RegisterInlinePlugins is an empty function which however forces the
// compiler to run all init() methods of the registered imports
func RegisterInlinePlugins() {} Note the If you now compile such a modified |
A question to this item, if I want to register an inline plugin, do I have to change the source code of kn client ? or in another word, do I have to submit a PR to kn client repo ? |
You would have to create an own variation of the kn build. The idea is that no plugin is added to
With this, it's very easy to create an own distribution. The tricky part will be to align the dependencies of plugins and the kn used, but that would be the value-add that somebody creating such a distribution could add. |
I like this. Overall my main concern would be to make sure (in time) that the That would have two side effects:
Not urgent but would be nice to have. |
Adressed all comment, ptal |
This issue is stale because it has been open for 90 days with no |
/close fixed by #902 |
@navidshaikh: Closing this issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/remove-lifecycle stale |
kn
provides a plugin architecture that allows calling to external commands via a naming convention (much likekubectl
). This proposal suggests a small modification inkn
s plugin handling algorithm to allow also to include golang-based plugins internally plugins so that are compiled together with kn and that implements aPlugin
golang interface. The required changes are implemented in PR #902.Use Cases
Allowing to package plugins together with
kn
during build-time allows for an easy distribution mechanism with a single binary, so a plugin package management (likekrew
for kubectl) is not needed. It also allows third-parties to provide value-add by maintaining a curated set of plugins and align them dependency-wise so that they can be compiled together.kn
itself is agnostic of the underlying platform and only uses the endpoints that the Knative API defines. However, a vast majority of Knative installations run on Kubernetes, so having Kubernetes specific functionality implemented askn
internal plugins that integrate seamlessly into the given command structure is valuable for Knative Kubernetes users.Examples of such Kubernetes specific plugins:
kn admin
for managing the Knative configurationkn service log
for showing the Knative logsAdditionally, inlining plugins for managing Event Sources also helps in creating a better user and installation experience:
kn source kafka
for managing a Kafka sourcekn source github
likewise, for a GitHub sourceScope
This proposal suggests only to offer the infrastructure for allowing such tight integration. Creating custom distributions of
kn
is out of scope for this proposal and left to third-parties. The integration must be minimally intrusive and not conflict with externally managed plugins.From UX perspective, inlined plugins (as well as externally managed plugins) should integrate seamlessly into the command structure of the builtin commands so that from a user's POV there is no notable difference between built-in commands and plugins (i.e. the should appear on the same help pages as the commands and also follow the same CLI conventions for subcommand and option names).
Code & Examples
init()
method.kn service log
plugin that uses this implementationkn service log
plugin used as an external and internal plugin.The text was updated successfully, but these errors were encountered: