|
| 1 | +# API Extensions - Best Practices |
| 2 | + |
| 3 | +> **Warning**: This document is a work in progress. See the `# TODO` list below |
| 4 | +> for details on some of the content which is unfinished (or even unstarted). |
| 5 | +
|
| 6 | +It is sometimes desireable to build new networking features as [CRDs] rather |
| 7 | +than [in-tree]. Reasons may include (but aren't limited to): |
| 8 | + |
| 9 | +* A need to move at a different pace than the core project |
| 10 | +* Experimentation and highly iterative development |
| 11 | +* The feature is useful to multiple parties, but is niche |
| 12 | +* the API doesn't or can't have a default implementation in core |
| 13 | + |
| 14 | +Whatever the case may be, we have multiple SIG Network sub-projects that have |
| 15 | +taken this approach for various reasons: |
| 16 | + |
| 17 | +* [Gateway API] |
| 18 | +* [Network Policy] |
| 19 | +* [Multi Network] |
| 20 | + |
| 21 | +This document intends to share guidelines and best practices for how to create |
| 22 | +and manage these kinds of "official, but add-on and optional" features, which |
| 23 | +throughout this document we'll refer to as **Official CRDs**. |
| 24 | + |
| 25 | +> **Note**: **This is not a standard**, but **SIG Network projects should try |
| 26 | +> and follow this guidance** unless they have some good reasons not to, as the |
| 27 | +> guidance here comes from the experience of those who have walked this road |
| 28 | +> before. This guidance might be applicable to some other SIGs, but as of the |
| 29 | +> time of writing none except SIG Network have reviewed this. |
| 30 | +
|
| 31 | +> **Note**: This is **not a comprehensive guide**. |
| 32 | +
|
| 33 | +[CRDs]:https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/ |
| 34 | +[in-tree]:https://github.com/kubernetes/api |
| 35 | +[KEP]:https://github.com/kubernetes/enhancements/blob/master/keps/README.md |
| 36 | +[Gateway API]:https://github.com/kubernetes-sigs/gateway-api |
| 37 | +[Network Policy]:https://github.com/kubernetes-sigs/network-policy-api |
| 38 | +[Multi Network]:https://github.com/kubernetes-sigs/multi-network |
| 39 | + |
| 40 | +## Objectives |
| 41 | + |
| 42 | +At a high level, SIG Network sub-projects that deploy as [CRDs] will need to |
| 43 | +deal with (at least) the following dimensions: |
| 44 | + |
| 45 | +* Enhancement Proposals |
| 46 | +* Developing CRDs |
| 47 | +* Delivering CRDs |
| 48 | +* CRD Lifecycle Management |
| 49 | +* Conformance Tests & Reports |
| 50 | +* Documentation |
| 51 | +* Community & Evangelism |
| 52 | + |
| 53 | +In the following section we'll talk about each of these in-depth, including |
| 54 | +some lessons learned by existing or historical sub-projects. |
| 55 | + |
| 56 | +[CRDs]:https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/ |
| 57 | + |
| 58 | +### Enhancement Proposals |
| 59 | + |
| 60 | +Projects which produce optional [Custom Resource Defintion (CRD)][CRD]-based |
| 61 | +APIs should provide a project-specific enhancement proposal system. You can see |
| 62 | +examples of using project-specific enhancement proposals with some of the |
| 63 | +current sub-projects: |
| 64 | + |
| 65 | +* [Gateway Enhancement Proposals (GEPs)][geps] |
| 66 | +* [Network Policy Enhancement Proposals (NPEPs)][npeps] |
| 67 | + |
| 68 | +Key characteristics of this pattern are: |
| 69 | + |
| 70 | +* an easy to find directory at the root of repositories, such as `geps/`, with |
| 71 | + references provided from the `README.md`. |
| 72 | +* a readme for the enhancement process (we recommend using GEP as a template, |
| 73 | + and we recommend a motivation focused proposal process (see more below)). |
| 74 | +* a project board which organizes these GEPs and helps provide visibility into |
| 75 | + the project's priorities and roadmap |
| 76 | +* trackable issues and PRs for every proposal that go through phases (e.g. |
| 77 | + (`provisional`, `implementable`, `experimental`, e.t.c.) |
| 78 | + |
| 79 | +We strongly recommend this pattern (unless there's some very compelling reason |
| 80 | +reason not to use it for any particular project). |
| 81 | + |
| 82 | +> **Note**: When starting new projects, we advise having enhancement proposals |
| 83 | +> preceed any code whatsoever, for posterity and to ensure time for all |
| 84 | +> stakeholders in the community are represented. |
| 85 | +
|
| 86 | +> **Note**: Taking this approach doesn't mean complete autonomy. Any GA APIs |
| 87 | +> (version is v1 or greater) with a `*.k8s.io` group **MUST** go through the API |
| 88 | +> review process with the SIG Network leads for any content considered |
| 89 | +> stable/standard/GA. The use of any non-`*.k8s.io` group for APIs published by |
| 90 | +> official SIG Network sub-projects or working groups needs to be ratified with |
| 91 | +> SIG Network leads first. Experimental features, alpha, beta, e.t.c. can be |
| 92 | +> developed without that additional oversight until they are promoted to GA. |
| 93 | +
|
| 94 | +[KEP]:https://github.com/kubernetes/enhancements/blob/master/keps/README.md |
| 95 | +[geps]:https://github.com/kubernetes-sigs/gateway-api/blob/main/geps/overview.md |
| 96 | +[npeps]:https://github.com/kubernetes-sigs/network-policy-api/tree/main/npeps |
| 97 | + |
| 98 | +#### Motivation Focused Enhancement Proposals |
| 99 | + |
| 100 | +It can be very easy to bring a new proposal to the table, and start with a huge |
| 101 | +GEP and maybe a ton of upfront code. In our experience however having too much |
| 102 | +up front, and in particular coming right to the table with an implementation |
| 103 | +can cause a proposal to get gridlocked very quickly. |
| 104 | + |
| 105 | +**We strongly recommend a "What, why and who before how" approach**. The first |
| 106 | +PR which adds an enhancement proposal should establish: |
| 107 | + |
| 108 | +* **What?** - What do we want to do, at a high level? A summary and/or specific |
| 109 | + high-level goals to achieve. |
| 110 | +* **Why?** - The motivation, the user stories, the reason we want to do this. |
| 111 | +* **Who?** - Every proposal stands a better chance of succeeding if there are |
| 112 | + multiple aligned parties interested in it, and collaborating on it upfront. |
| 113 | + |
| 114 | +Without any indication of _how_ we accomplish it. This, plus a process of steps |
| 115 | +for graduation (e.g. `provisional` -> `implementable` -> `experimental` -> |
| 116 | +`standard`) allows the community to work more iteratively, and work on alignment |
| 117 | +with the principles before spending any time in the implementation details. |
| 118 | + |
| 119 | +### Developing CRDs |
| 120 | + |
| 121 | +TODO |
| 122 | + |
| 123 | +#### Known Challenges |
| 124 | + |
| 125 | +Developing with CRDs can be challenging and we've gained a lot of experience |
| 126 | +with some of the trickier bits over the years. In this section we'll describe in |
| 127 | +detail some subtle or particularly nebulous challenges we've faced, and provide |
| 128 | +guidance on how to navigate them. |
| 129 | + |
| 130 | +##### When a feature can be supported by many but not ALL implementations |
| 131 | + |
| 132 | +When developing an API in a community (especially if there are many |
| 133 | +implementations) you may find there are features that are not common across all |
| 134 | +implementations, but a subset of them can implement them. |
| 135 | + |
| 136 | +**In an ideal situation no user is provided fields in an API that they can't |
| 137 | +actually use**. It can be tempting to take some tradeoffs on this to try to find |
| 138 | +a middle-ground so that you can provide more overall features. The [Gateway API] |
| 139 | +project (in particular) ran into this problem early on and decided to try an |
| 140 | +approach called [Conformance Support Levels]. |
| 141 | + |
| 142 | +With the "support levels approach", all the ubiquitous features are covered by |
| 143 | +a "core" level of support. Features which are supported by at least 3 |
| 144 | +implementations are covered by an "extended" level of support. Each of these has |
| 145 | +conformance tests and are included in reports, but ultimately when the user is |
| 146 | +defining their [HTTPRoute] (or other resource) **it can be very unclear whether |
| 147 | +the fields marked as "extended" will actually be functional given any particular |
| 148 | +implementation, and between different implementations**. Morever (at the time |
| 149 | +of writing) Gateway API doesn't have a complete solution for how feedback to a |
| 150 | +user should work in this regard (but there are some [ongoing proposals]). |
| 151 | + |
| 152 | +It is due to the problems stated above and the lack of implementation |
| 153 | +complete-ness so far that **we do not advise employing an approach like |
| 154 | +conformance levels at this time**. In general, we advise that all fields |
| 155 | +available in your APIs be functional regardless of implementation. |
| 156 | + |
| 157 | +> **Note**: This guidance may be updated in the future if we come to more |
| 158 | +> definitive conclusions on the value and efficacy of support levels for |
| 159 | +> end-users. |
| 160 | +
|
| 161 | +[Gateway API]:https://github.com/kubernetes-sigs/gateway-api/ |
| 162 | +[Conformance Support Levels]:https://gateway-api.sigs.k8s.io/concepts/conformance/#2-support-levels |
| 163 | +[HTTPRoute]:https://gateway-api.sigs.k8s.io/api-types/httproute/ |
| 164 | +[ongoing proposals]:https://gateway-api.sigs.k8s.io/geps/gep-2162/ |
| 165 | + |
| 166 | +### Delivering CRDs |
| 167 | + |
| 168 | +TODO |
| 169 | + |
| 170 | +### CRD Lifecycle Management |
| 171 | + |
| 172 | +TODO - installing, and managing CRDs. How this should work on platforms, who's |
| 173 | + responsible (and trying to reduce responsibility on the cluster operator) |
| 174 | + Also need to talk about interop between multiple dependent projects. |
| 175 | + |
| 176 | +### Conformance Tests & Reports |
| 177 | + |
| 178 | +TODO - framework for testing and reporting |
| 179 | + |
| 180 | +## Important Notes |
| 181 | + |
| 182 | +> **Note**: At the time of writing, we have no extension APIs that have |
| 183 | +> transferred themselves in-tree after doing development iterations |
| 184 | +> out-of-tree. This is uncharted territory at present, though we are not |
| 185 | +> opposed to it happening if it seems appropriate. |
| 186 | +
|
| 187 | +## TODO |
| 188 | + |
| 189 | +This document is a work in progress. Some sections are outlined above but |
| 190 | +still need to be started or completed: |
| 191 | + |
| 192 | +- [ ] Developing CRDs |
| 193 | +- [ ] Delivering CRDs |
| 194 | +- [ ] CRD Lifecycle Management |
| 195 | +- [ ] Conformance Tests and Conformance Reports |
0 commit comments