You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: designs/extensible-cli-and-scaffolding-plugins.md
+11-8Lines changed: 11 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# Extensible CLI and Scaffolding Plugins
2
2
3
-
## Overview
4
-
I would like for Kubebuilder to become more extensible, such that it could be imported and used as a library in other projects. Specifically, I'm looking for a way to use Kubebuilder's existing CLI and scaffolding for Go projects, but to also be able to augment Kubebuilder's project versions with other custom project versions so that I can support the Kubebuilder workflow with non-Go operators (e.g. operator-sdk's Ansible and Helm-based operators).
3
+
## Overview
4
+
I would like for Kubebuilder to become more extensible, such that it could be imported and used as a library in other projects. Specifically, I'm looking for a way to use Kubebuilder's existing CLI and scaffolding for Go projects, but to also be able to augment the Kubebuilder project structure with other custom project types so that I can support the Kubebuilder workflow with non-Go operators (e.g. operator-sdk's Ansible and Helm-based operators).
5
5
6
6
The idea is for Kubebuilder to define one or more plugin interfaces that can be used to drive what the `init`, `create api` and `create webhooks` subcommands do and to add a new `cli` package that other projects can use to integrate out-of-tree plugins with the Kubebuilder CLI in their own projects.
7
7
@@ -21,9 +21,12 @@ Each plugin would minimally be required to implement the `Plugin` interface.
21
21
22
22
```go
23
23
typePlugininterface {
24
-
// Version is the project version that this plugin implements.
25
-
// For example, Kubebuilder's Go v2 plugin implementation would return "2"
26
-
Version() string
24
+
// Version returns the project version that this plugin implements.
25
+
// For example, Kubebuilder's Go v2 plugin implementation would return 2.
26
+
Version() uint
27
+
// Name returns a name defining the plugin type.
28
+
// For example, Kubebuilder's plugins would return "go".
29
+
Name() string
27
30
}
28
31
```
29
32
@@ -33,7 +36,7 @@ Next, a plugin could optionally implement further interfaces to declare its supp
33
36
*`CreateAPIPlugin` - to create APIs (and possibly controllers) for existing projects
34
37
*`CreateWebhookPlugin` - to create webhooks for existing projects
35
38
36
-
Each of these interfaces would follow the same pattern (see the InitPlugin interface example below).
39
+
Each of these interfaces would follow the same pattern (see the `InitPlugin` interface example below).
37
40
38
41
```go
39
42
typeInitPlugininterface {
@@ -66,7 +69,7 @@ To generically support deprecated project versions, we could also add a `Depreca
66
69
// that the plugin is deprecated. The CLI uses this to print deprecation
67
70
// warnings when the plugin is in use.
68
71
typeDeprecatedinterface {
69
-
// DeprecationWarning returns a deprecation message that callers
72
+
// DeprecationWarning returns a deprecation message that callers
70
73
// can use to warn users of deprecations
71
74
DeprecationWarning() string
72
75
}
@@ -122,7 +125,7 @@ func main() {
122
125
## Comments & Questions
123
126
124
127
### Cobra Commands
125
-
As discussed earlier as part of [#1148](https://github.com/kubernetes-sigs/kubebuilder/pull/1148), one goal is to eliminate the use of `cobra.Command` in the exported API of Kubebuilder since that is considered an internal implementation detail.
128
+
As discussed earlier as part of [#1148](https://github.com/kubernetes-sigs/kubebuilder/pull/1148), one goal is to eliminate the use of `cobra.Command` in the exported API of Kubebuilder since that is considered an internal implementation detail.
126
129
127
130
However, at some point, projects that make use of this extensibility will likely want to integrate their own subcommands. In this proposal, `cli.WithExtraCommands()`_DOES_ expose `cobra.Command` to allow callers to pass their own subcommands to the CLI.
0 commit comments