Skip to content

Commit 4360bd9

Browse files
authored
Merge pull request #5038 from siyuanfoundation/compat-versions-api
KEP-4330: Change API availability to forward compatibility
2 parents a6b207e + afbb66b commit 4360bd9

File tree

1 file changed

+85
-5
lines changed
  • keps/sig-architecture/4330-compatibility-versions

1 file changed

+85
-5
lines changed

keps/sig-architecture/4330-compatibility-versions/README.md

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,14 @@ tags, and then generate with `hack/update-toc.sh`.
9090
- [Changes to Feature Gates](#changes-to-feature-gates)
9191
- [Feature Gate Lifecycles](#feature-gate-lifecycles)
9292
- [Feature gating changes](#feature-gating-changes)
93+
- [Non-Emulatable Features](#non-emulatable-features)
94+
- [Alternatives](#alternatives)
9395
- [Validation ratcheting](#validation-ratcheting)
9496
- [CEL Environment Compatibility Versioning](#cel-environment-compatibility-versioning)
9597
- [StorageVersion Compatibility Versioning](#storageversion-compatibility-versioning)
9698
- [API availability](#api-availability)
99+
- [API availability in forward-compatible mode](#api-availability-in-forward-compatible-mode)
100+
- [Alternatives to API forward compatibility](#alternatives-to-api-forward-compatibility)
97101
- [API Field availability](#api-field-availability)
98102
- [Discovery](#discovery)
99103
- [Version introspection](#version-introspection)
@@ -126,7 +130,7 @@ tags, and then generate with `hack/update-toc.sh`.
126130
- [Troubleshooting](#troubleshooting)
127131
- [Implementation History](#implementation-history)
128132
- [Drawbacks](#drawbacks)
129-
- [Alternatives](#alternatives)
133+
- [Alternatives](#alternatives-1)
130134
- [Infrastructure Needed (Optional)](#infrastructure-needed-optional)
131135
<!-- /toc -->
132136

@@ -563,6 +567,18 @@ func ClientFunction() {
563567

564568
```
565569

570+
#### Non-Emulatable Features
571+
Generally, if a feature is enabled by default either in Beta or GA, it should be fairly stable already.
572+
In very rare cases for some default-off Beta features, a feature could be non-emulatable if the feature implementation history could not be preserved in the code base with reasonable maintenance cost.
573+
574+
For these cases, we should try to emulate these changing features at best effort, and make sure the clients are aware of the risks of enabling default-off Beta features with emulation version.
575+
576+
##### Alternatives
577+
An alternative would be to keep a exception list of `NonEmulatableFeatures`, and make the server fail to start if any of the `NonEmulatableFeatures` are enabled in compatibility mode. This approach has the benefits of predictable outcomes. The downsides are:
578+
1. whether a feature should be added to the list is subjective. It is hard to define a threshold to decide if the difficulty to preserve the implementation history is above this threshold, we could add the feature to the list.
579+
1. this could break automated upgrade processes using the emulation version, depending what features a cluster opts in.
580+
1. there needs proper cleaning up rules to ensure the list would not just keep growing.
581+
566582
### Validation ratcheting
567583

568584
All validationg ratcheting needs to account for compatibility version.
@@ -611,7 +627,7 @@ The storage version of each group-resource is the newest
611627

612628
### API availability
613629

614-
Similar to feature flags, all APIs group-versions declarations will be modified
630+
By default, similar to feature flags, all APIs group-versions declarations will be modified
615631
to track which Kubernetes version the API group-versions are introduced (or
616632
removed) at.
617633

@@ -626,6 +642,70 @@ emulation version can be set to.
626642

627643
Alpha APIs may not be enabled in conjunction with emulation version.
628644

645+
#### API availability in forward-compatible mode
646+
647+
If we stick to the strict rule of api availability matching the emulation version, we would face some challenging scenarios when emulating the controllers when an API is graduating from Beta to GA and the controller wants to use newer API. For example, to graduate Multiple Service CIDRs to GA, normally the controller code change would look like:
648+
```diff
649+
- c.serviceCIDRInformer = networkingv1beta1informers.NewFilteredServiceCIDRInformer(client, 12*time.Hour,
650+
+ c.serviceCIDRInformer = networkingv1informers.NewFilteredServiceCIDRInformer(client, 12*time.Hour,
651+
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
652+
func(options *metav1.ListOptions) {
653+
options.FieldSelector = fields.OneTermEqualSelector("metadata.name", DefaultServiceCIDRName).String()
654+
})
655+
656+
- c.serviceCIDRLister = networkingv1beta1listers.NewServiceCIDRLister(c.serviceCIDRInformer.GetIndexer())
657+
+ c.serviceCIDRLister = networkingv1listers.NewServiceCIDRLister(c.serviceCIDRInformer.GetIndexer())
658+
c.serviceCIDRsSynced = c.serviceCIDRInformer.HasSynced
659+
660+
return c
661+
//...
662+
663+
type Controller struct {
664+
eventRecorder record.EventRecorder
665+
666+
serviceCIDRInformer cache.SharedIndexInformer
667+
- serviceCIDRLister networkingv1beta1listers.ServiceCIDRLister
668+
+ serviceCIDRLister networkingv1listers.ServiceCIDRLister
669+
serviceCIDRsSynced cache.InformerSynced
670+
671+
```
672+
To fully emulate the controller for an older version, anywhere v1 api/type is referenced, it would need to switch to the v1beta version if the emulation version is older than the binary version. This would mean a lot of extra work, complicated testing rules, and high maintenance cost even for simple API graduations, while the emulation fidelity is unreliable with the extra complexity.
673+
674+
So instead of truly emulating the feature controllers and API availability at the emulation version, we are allowing apis introduced after the emulation version to be enabled explicitly with `--runtime-config=api/<version>`. We are also introducing an umbrella `--emulation-forward-compatible` flag to enable forward compatibility of all APIs in compatibility version mode: if an older version of the API is enabled, newer and more stable versions of the same resource group introduced between the emulation version and binary version would also be enabled. This way the non-emulatable feature controllers would be able to use the newest available API.
675+
676+
For API availability, setting `--emulation-forward-compatible=true` means:
677+
1. if an API is removed (as indicated by the GVK prerelease lifecycle) after the emulation version, it would still be available at the emulation version (regardless of `--emulation-forward-compatible=true/false`).
678+
1. if an API is Beta at the emulation version (meaning the Beta API has been introduced and has not been removed by the emulation version), it can be enabled by `--runtime-config=api/<version>` or it can be on-by-default at the emulation version. If a Beta API is enabled at the emulation version, and it has GAed between the emulation version and the binary version, its GA version(s) would also be enabled at the emulation version. If a newer Beta API is introduced between the emulation version and the binary version, the newer Beta API(s) would also be enabled at the emulation version.
679+
1. if a Beta API is not enabled at the emulation version, its future versions would not be enabled at the emulation version unless explicitly enabled with `--runtime-config=api/<version>`.
680+
1. If an API has GAed at the emulated version, it would be enabled by default at the emulation version. If a newer stable version of the GA API has been introduced between the emulation version and the binary version, the new GA API(s) would also be enabled at the emulation version along with the old GA API.
681+
1. Alpha APIs may not be enabled in conjunction with emulation version.
682+
683+
Here are some examples for `BinaryVersion = 1.33`:
684+
API Prerelease Lifecycle | EmulationVersion | APIs Available @EmulationVersion
685+
-----|-----|-----
686+
`v1alpha1: introduced=1.30, removed=1.31`<br>`v1beta1: introduced=1.31, removed=1.32`<br>`v1: introduced=1.32` | 1.30 | NA because we do not support emulating alpha apis.
687+
`v1alpha1: introduced=1.30, removed=1.31`<br>`v1beta1: introduced=1.31, removed=1.32`<br>`v1: introduced=1.32` | 1.31 | `api/v1beta1` available when `--runtime-config=api/v1beta1=true`<br>`api/v1beta1` and `api/v1` available only when `--runtime-config=api/v1beta1=true,api/v1=true` or `--runtime-config=api/v1beta1=true --emulation-forward-compatible=true`
688+
`v1alpha1: introduced=1.30, removed=1.31`<br>`v1beta1: introduced=1.31, removed=1.32`<br>`v1: introduced=1.32` | 1.33 | `api/v1`
689+
`v1beta1: introduced=1.31, removed=1.32`<br>`v1beta2: introduced=1.32` | 1.31 | `api/v1beta1` available when `--runtime-config=api/v1beta1=true`<br>`api/v1beta1` and `api/v1beta2` available only when `--runtime-config=api/v1beta1=true,api/v1beta2=true` or `--runtime-config=api/v1beta1=true --emulation-forward-compatible=true`
690+
`v1beta1: introduced=1.31, removed=1.32`<br>`v1beta2: introduced=1.32` | 1.33 | `api/v1beta2` available only when `--runtime-config=api/v1beta2=true`
691+
`v1: introduced=1.28`<br>`v2beta1: introduced=1.31, removed=1.32`<br>`v2: introduced=1.32` | 1.30 | `api/v1`<br>`api/v1`, `api/v2` when `--runtime-config=api/v2=true` or `--emulation-forward-compatible=true`
692+
`v1: introduced=1.28`<br>`v2beta1: introduced=1.31, removed=1.32`<br>`v2: introduced=1.32` | 1.31 | `api/v1`, `api/v2beta1` available when `--runtime-config=api/v2beta1=true`<br>`api/v1`, `api/v2beta1`, `api/v2` available only when `--runtime-config=api/v2beta1=true,api/v2=true` or `--runtime-config=api/v2beta1=true, --emulation-forward-compatible=true`
693+
`v1: introduced=1.28`<br>`v2beta1: introduced=1.31, removed=1.32`<br>`v2: introduced=1.32` | 1.33 | `api/v1`, `api/v2`
694+
695+
For the controller, at the emulation version the controller is still enabled by enabling the Beta API **AND** the controller feature as before, but under the hood the controller is calling the newer API.
696+
697+
The forward compatibility of API availability should not affect data compatibility because storage version is still controlled by the `MinCompatibilityVersion` regardless of whether the data are created through future versions of the API endpoints. Webhooks should also work fine if the matching policy is `Equivalent`.
698+
699+
For the use case of upgrading control plane binary version without changing the emulation version, this would mean api servers should be upgraded first before any other components, because an api server of the old binary version would not be able to serve a controller of the new binary version even though the emulation version is the same as the old binary version.
700+
701+
#### Alternatives to API forward compatibility
702+
To make API graduation workable for controller code change under compatibility version, we have considered and rejected the following alternative options:
703+
1. `if .. else ..` statements everywhere is just impractical.
704+
1. have `v1Controller` and `v1beta1Controller` code in separate files would mean duplicate maintenance, test work, and developer churn.
705+
1. have some smart wrapper to pick the right version for each API/type reference: it is very hard to design a generic enough wrapper for all cases.
706+
1. convert the data to older version when the newer API is called: this is the essentially same as the enabling the newer API.
707+
1. have special mechanisms for controllers in `k/k` to call v1 apis, but not expose the v1 apis to clients: clients can spend efforts to duplicate the special mechanisms.
708+
629709
### API Field availability
630710

631711
API fields that were introduced after the emulation version will **not** be
@@ -832,9 +912,9 @@ Alpha feature graduated to Beta|off-by-default|on-by-default|feature enabled onl
832912
Beta feature graduated to GA|on-by-default|on|feature enabled unless `--feature-gates=<feature>=false`|feature always enabled, feature gate may not be set
833913
Beta feature removed|on-by-default|-|feature enabled unless `--feature-gates=<feature>=false`|feature does not exist
834914
Alpha API introduced|-|off-by-default|API does not exist|alpha APIs may not be used in conjunction with emulation version
835-
Beta API graduated to GA|off-by-default|on|API available only when `--runtime-config=api/v1beta1=true`|API `api/v1` available
836-
Beta API removed|off-by-default|-|API available only when `--runtime-config=api/v1beta1=true`|API `api/v1beta1` does not exist
837-
on-by-default Beta API removed|on-by-default|-|API available unless `--runtime-config=api/v1beta1=false`|API `api/v1beta1` does not exist
915+
Beta API graduated to GA|off-by-default|on|API `api/v1beta1` and `api/v1` available only when `--runtime-config=api/v1beta1=true`|API `api/v1` available
916+
Beta API removed|off-by-default|-|API `api/v1beta1` available only when `--runtime-config=api/v1beta1=true`|API `api/v1beta1` does not exist
917+
on-by-default Beta API removed|on-by-default|-|API `api/v1beta1` available unless `--runtime-config=api/v1beta1=false`|API `api/v1beta1` does not exist
838918
API Storage version changed|v1beta1|v1|Resources stored as v1beta1|Resources stored as v1
839919
new CEL function|-|function in StoredExpressions CEL environment|CEL function does not exist|Resources already containing CEL expression can be evaluated
840920
introduced CEL function|function in StoredExpressions CEL environment|function in NewExpressions CEL environment|Resources already containing CEL expression can be evaluated|CEL expression can be written to resources and can be evaluted from storage

0 commit comments

Comments
 (0)