Skip to content

Commit ba68281

Browse files
hasbro17joelanford
authored andcommitted
Add 4.4 proposal for Kubebuilder integration for Go operators (#2350)
* Add 4.4 proposal for Kubebuilder integration for Go operators * fix typos
1 parent 2a55bd0 commit ba68281

File tree

1 file changed

+193
-0
lines changed

1 file changed

+193
-0
lines changed
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
---
2+
title: OpenShift 4.4: Operator-SDK integrates Kubebuilder for Golang Operators
3+
authors:
4+
- "@hasbro17"
5+
reviewers:
6+
- "@estroz"
7+
- "@joelanford"
8+
approvers:
9+
- "@estroz"
10+
- "@joelanford"
11+
creation-date: 2019-12-19
12+
last-updated: 2019-12-19
13+
status: implementable
14+
see-also:
15+
- https://github.com/kubernetes-sigs/kubebuilder/blob/master/designs/integrating-kubebuilder-and-osdk.md
16+
replaces: []
17+
superseded-by: []
18+
---
19+
20+
# OpenShift 4.4: Operator-SDK integrates Kubebuilder for Golang Operators
21+
22+
## Release Signoff Checklist
23+
24+
- \[x\] Enhancement is `implementable`
25+
- \[x\] Design details are appropriately documented from clear requirements
26+
- \[ \] Test plan is defined
27+
- \[ \] Graduation criteria for dev preview, tech preview, GA
28+
- \[ \] User-facing documentation is created in [operator-sdk/doc][operator-sdk-doc]
29+
30+
## Summary
31+
32+
The Operator SDK should become compatible with Kubebuilder so that it has the
33+
same project layout and CLI workflow for developing Go operators.
34+
To achieve this goal without duplicating upstream code, the SDK should integrate
35+
Kubebuilder’s CLI to reuse the scaffolding for project creation and lifecycle management.
36+
At the same time the SDK should still be able to provide SDK specific features that work
37+
with the new project layout.
38+
39+
In order for the SDK to wrap and reuse Kubebuilder while still maintaining the
40+
SDK binary as the entrypoint, Kubebuilder should be extended with a CLI interface
41+
that supports registering plugins. This lets the SDK reuse Kubebuilder’s existing
42+
scaffolding code for Go operators, while still being able to extend the CLI for SDK
43+
specific features/sub-commands and provide custom plugins that will allow the SDK to
44+
scaffold different project types like Helm/Ansible in the future.
45+
46+
47+
## Motivation
48+
49+
The Operator SDK and Kubebuilder largely provide the same experience for developing
50+
Go operators since both projects defer to APIs provided by the same upstream projects.
51+
The two projects differentiate in their CLI and UX of project setup, layout, and
52+
lifecycle management. These differences are largely incidental of how the two
53+
projects developed over time and not due to any use cases that are only addressed by either UX.
54+
55+
By adopting the same workflow and layout as Kubebuilder, the SDK gains better
56+
alignment with the upstream community for writing Go operators. This allows the
57+
SDK to be used interchangeably with Kubebuilder projects, which unifies the
58+
experience of writing Go operators and resolves confusion on why the Operator SDK
59+
and Kubebuilder differ in their UX to achieve the same goals. This lets the SDK
60+
focus more on features that are outside the scope of Kubebuilder, such as
61+
Operator Lifecycle Manager (OLM) integration and Scorecard.
62+
63+
Reusing the project scaffolding from Kubebuilder also reduces duplication in
64+
the SDK. This frees up Operator SDK maintainers to focus more on collaborating
65+
with the Kubebuilder maintainers on the upstream controller-runtime and controller-tools projects
66+
67+
68+
## Goals
69+
70+
- Operator SDK projects should have the same project layout as Kubebuilder projects for Go operators
71+
- The Operator SDK CLI and workflow for extending (adding APIs and webhooks) and managing the lifecycle (generate manifests, build and run) of a project should be the same as Kubebuilder
72+
- This ensures Operator SDK binary compatiblity with existing Kubebuilder projects.
73+
- Operator SDK specific features such as CSV generation, scorecard and test-framework should work the same in the new project layout.
74+
- Operator SDK developers can use cert-manager to generate TLS certificates for their webhook servers
75+
76+
77+
### Non-Goals
78+
79+
- Changing the SDK scaffolding and workflow for Helm and Ansible operators to align with Kubebuilder’s CLI
80+
- While Kubebuilder’s new plugin based CLI architecture should allow the SDK to extend it for scaffolding Helm/Ansible projects, the implementation of those plugins is not currently in scope for this proposal.
81+
- Webhook support for Ansible/Helm based operators
82+
83+
84+
## Proposal
85+
86+
### User Stories
87+
88+
#### Story 1 - Design a Kubebuilder plugin interface that lets the SDK reuse and extend the CLI
89+
90+
After upstream discussions with the Kubebuilder maintainers there is consensus
91+
that Kubebuilder should support an interface to register plugins that would be
92+
used to provide the implementation of CLI commands. This way Kubebuilder would
93+
not have to directly expose its [cobra][cobra] CLI for the SDK’s consumption, and the SDK
94+
could still reuse Kubebuilder’s plugins to scaffold new projects (init and create)
95+
while also being able to register its own plugins to extend the CLI for SDK specific
96+
subcommands (csv-gen, scorecard).
97+
98+
This plugin interface should also allow the SDK to provide custom plugin
99+
implementations for the init and create subcommands so that it can customize the
100+
scaffolding of Helm and Ansible projects in the future.
101+
102+
There is a [proposal][plugin-proposal] on Kubebuilder for the design of such a plugin interface.
103+
The aim of this story is to address all reviewer comments to achieve consensus
104+
on the plugin architecture and merge the proposal.
105+
106+
[plugin-proposal]: https://github.com/kubernetes-sigs/kubebuilder/pull/1250
107+
[cobra]: https://github.com/spf13/cobra
108+
109+
110+
#### Story 2 - Implement the Kubebuilder plugin interface and CLI pkg
111+
112+
After the plugin interface proposal has been accepted, the implementations of
113+
the plugin interface and the CLI pkg should be added to Kubebuilder.
114+
115+
This involves writing plugin implementations for the following scaffolding
116+
subcommands in Kubebuilder so that the SDK can register them for reuse in its own CLI:
117+
118+
- `kubebuilder init`
119+
- `kubebuilder create api`
120+
- `kubebuilder create webhook`
121+
122+
The goal of this story is to ensure a release of Kubebuilder that supports the
123+
new plugin interface that the SDK can integrate downstream into its own CLI.
124+
125+
126+
#### Story 3 - Integrate the Kubebuilder CLI into the SDK CLI to achieve the same workflow and project layout for Go operators
127+
128+
Once Kubebuilder supports plugin registration, the SDK CLI should be modified
129+
to reuse Kubebuilder’s CLI and plugins so that the SDK workflow for developing
130+
Go operators is identical to Kubebuilder’s workflow.
131+
132+
Project initialization and api/webhook scaffolding would be provided by the
133+
upstream Kubebuilder CLI and plugins:
134+
135+
136+
- `operator-sdk new` ==> `operator-sdk init`
137+
- `operator-sdk add api/controller` ==> `operator-sdk create api`
138+
- `operator-sdk create webhook`
139+
140+
Other SDK subcommands can be removed and replaced by their equivalent Makefile targets in the Kubebuilder workflow after ensuring that they fulfill all the same use cases.
141+
142+
- `operator-sdk generate k8s` ==> `make generate`
143+
- `operator-sdk generate crd` ==> `make manifests`
144+
- `operator-sdk build` ==> `make manager`, `make docker-build`
145+
- `operator-sdk up local` ==> `make run`
146+
147+
If any of the old subcommands above are invoked for a Go operator project, the
148+
output should be a deprecation error that highlights the equivalent replacement
149+
for it in the new Kubebuilder workflow.
150+
151+
152+
#### Story 4 - Update the SDK specific features and subcommands to work with the new project layout
153+
154+
Since features like the scorecard, CSV generation and test-framework have no
155+
equivalent in the Kubebuilder workflow, those subcommands would be unchanged on the CLI.
156+
157+
- `operator-sdk gen-csv`
158+
- `operator-sdk scorecard`
159+
- `operator-sdk test`
160+
161+
Where necessary the above commands should be adjusted to reflect the changes to
162+
their expected input and output manifest paths that is consistent with the new project layout.
163+
164+
165+
#### Story 5 - Update the Operator SDK e2e tests to work with the new project layout
166+
167+
The existing e2e tests and CI scripts for testing Go operators would need to be
168+
updated to use the new layout so that CI passes for the new CLI workflow in the master branch.
169+
170+
171+
#### Story 6 - Update the Go operator related documentation per the Kubebuilder workflow and project layout
172+
173+
The user documentation for Go operators such as the user-guide, CLI reference,
174+
project layout, etc will need to be updated according to the new CLI and layout.
175+
176+
177+
### Implementation Details/Notes/Constraints
178+
The integration work for the Go Operator CLI workflow can be done in the master
179+
branch to avoid issues with merge conflicts from rebasing a separate branch at a later time.
180+
The new CLI can be worked on behind a hidden subcommand, `operator-sdk alpha`, until it is ready to
181+
replace the existing workflow. This would help avoid exposing it too early while
182+
still providing the ability to test it on the master branch.
183+
184+
185+
### Risks and Mitigations
186+
187+
- This proposal involves major breaking changes in all aspects of the project that will discourage users from making the upgrade to the release involving these changes.
188+
- Besides having enough documentation to guide users to make the switch over to the new release, there should be some migration tooling to assist users in switching over their existing projects. **TODO:** These efforts will be addressed in a separate enhancement proposal.
189+
- Once the SDK switches to using Kubebuilder for Go operators, the CLI UX for Go vs Ansible/Helm operators will be fragmented. While they don’t target the same users it could be confusing to see the operator-sdk binary support different commands for initializing different project types.
190+
- With the proposed plugin architecture it should be possible to update the workflow for Helm/Ansible operators to be the same as Kubebuilder. However that is not currently in scope for this proposal.
191+
192+
193+
[operator-sdk-doc]: ../../../doc

0 commit comments

Comments
 (0)