or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
[public] kcp API evolution prototyping
Overview
Enable API authors to evolve their APIs and make API versions covertible to each other without needing webhooks.
Motivation
APIs are not static; new features are added, fields are renamed, etc. CustomResourceDefinitions provide a means for converting between different API versions - conversion webhooks. kcp doens't support conversion webhooks because they require Kubernetes
Services
to function, and these are not built in to kcp.We need to provide a way for API providers that are using kcp's APIResourceSchema, APIExport, and APIBinding APIs to support API version conversion.
Proposal
At a high level:
Conversion specification options
Background
Given an APIResourceSchema such as:
it defines two API versions, v1 and v2.
v1 has a
firstName
andlastName
fields directly underspec
.v2 groups them under a parent
spec.name
field.Option 1: spec field on APIResourceSchema
Option 2: part of each spec.versions[]
Alternative conversion structures
The examples above specify a hub version and then a list of conversions, 1 per non-hub version. In other words, given hub version v1 and all versions v1, v2, v3, there will need to be 2 conversion entries, 1 each for v2 (converting between v2 and v1 in both directions) and v3 (converting between v3 and v1 in both directions). No conversion entry is needed for v1, because that is the hub version.
We could specify this using different structures, such as:
Specify from/to for each rule, 1 field per rule
Specify from/to for each rule, n fields per rule
How to reference the source object in CEL
All the examples above refer to the source object as
self
in the CEL rules. Another, possibly less confusing option would be to use the name of the source object's version. For example,would become
We potentially could also improve legibility by adjusting the field names slightly, such as:
Discussion on options
While options 1 and 2 keep the schema definitions and conversion rules together, they also require that the schema definitions for all API versions and all conversion rules (between each non-hub version and the hub version) can fit into a single object in etcd.
Option 3 has the benefit of keeping the conversion rules in a separate resource, so as to avoid restricting the maximum size of an APIResourceSchema any further than the current limitations etcd imposes.
With option 3, we presumably would want to use a naming convention to make it easy to identify which conversion object is linked to which APIResourceSchema. The easiest approach is to require the names to be identical.
One additional considering with option 3 is whether we potentially need to allow conversion rules that exceed the maximum size of a single object in etcd. If that ever become the case, instead of requiring identical names, we could use a label selector to link the conversion resources and an APIResourceSchema. For example, given an APIResourceSchema called
rev0002.widgets.example.io
, we could require that conversion object must have the following label:apis.kcp.dev/apiresourceschema=rev0002.widgets.example.io
.Decision - Option 3
We have decided to proceed with option 3. This is also aligned with the upstream Kubernetes KEP for CEL-based admission control, which uses a standalone resource for admission rules.
Supported conversions
Simple field-to-field
From (v1):
To (v2):
Conversion:
move map (same as simple field-to-field)
From (v1):
To (v2):
Conversion:
convert single value to list
From (v1):
To (v2):
Conversion:
List with nested map, field names change
From (v1):
To (v2):
Conversion:
From (v1):
To (v2):
move from map to list
From (v1):
To (v2):
specify other fields outside of destination
From (v1):
To (v2):
Conversion rule validation
When an APIResourceSchema's conversion rules are created, we must compile and check the conversion rules are valid, and reject if not.
The CEL validation is easily doable for simple "from" rules. For "itemRules" we'll have to do additional work, but this should be possible.
The harder problem to solve is how to validate the "to" rules. It's probably best to ensure that a "to" field exists in the schema for the target version.
Implementation
Kubernetes changes
APIResourceSchema resources are eventually transformed to CustomResourceDefinitions and served via the apiextensions apiserver part of Kubernetes. Because of this, any modifications to conversion logic have to be made in that section of the code.
The apiextensions apiserver defines a
CRConverterFactory
that is used to supply converters.The following logic determines which converter to supply when conversion is needed:
We will have to modify this factory to support a new type of converter, one that is CEL-based. This requires changing the kcp fork of Kubernetes. An option that could reduce long-term maintenace costs (e.g. rebasing) could be the following:
CRConverterFactory
from astruct
to aninterface
NewCustomResourceDefinitionHandler
to take in aCRConverterFactory
instead ofserviceResolver
andauthResolverWrapper
(these are only used to construct the defaultCRConverterFactory
)ExtraConfig
ServiceResolver
AuthResolverWrapper
CRConverterFactory
genericcontrolplane
andcmd/kube-apiserver/app/apiextensions.go
to either take in or set up aCRConverterFactory
as appropriate.CEL evaluation
Before we can perform conversion, we first have to copy the conversion rules from their source workspace (where the APIResourceSchema lives) into the system:bound-crds logical cluster (where the actual CRDs generated from APIResourceSchemas live).
We must modify the APIBinding reconciler so it copies the appropriate conversion object(s) to system:bound-crds as part of the CRD generation process.
TODO